Skip to content

Commit

Permalink
Fix loop queue (Ecliptia#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
1Lucas1apk authored Feb 18, 2024
2 parents 271cf9e + cbc0677 commit 889e0bd
Show file tree
Hide file tree
Showing 18 changed files with 103 additions and 52 deletions.
72 changes: 72 additions & 0 deletions dist/src/@Datastore/database-960185850346471505.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"players": {
"990369410344701964": {
"voiceChannel": "1089198118022680626",
"textChannel": "1151684866971275325"
}
},
"queue": {
"990369410344701964": [
{
"encoded": "QAAA8AMATUxlbWJyZSBkZSBNaW0gKENhbsOnw6NvIGRlIE5pbmFyKSAoRGUgIlZpdmEgLSBBIFZpZGEgw6kgdW1hIEZlc3RhIi9Db20gbGV0cmEpABFEaXNuZXlNdXNpY0JSVkVWTwAAAAAAARlAAAtkcDZobUo0Vkt5TQABACtodHRwczovL3d3dy55b3V0dWJlLmNvbS93YXRjaD92PWRwNmhtSjRWS3lNAQA0aHR0cHM6Ly9pLnl0aW1nLmNvbS92aS9kcDZobUo0Vkt5TS9tYXhyZXNkZWZhdWx0LmpwZwAAB3lvdXR1YmUAAAAAAAAAAA==",
"identifier": "dp6hmJ4VKyM",
"title": "Lembre de Mim (Canção de Ninar) (De \"Viva - A Vida é uma Festa\"/Com letra)",
"author": "DisneyMusicBRVEVO",
"url": "https://www.youtube.com/watch?v=dp6hmJ4VKyM",
"duration": 72000,
"position": 69380,
"isSeekable": true,
"isStream": false,
"sourceName": "youtube",
"artworkUrl": "https://i.ytimg.com/vi/dp6hmJ4VKyM/maxresdefault.jpg",
"isrc": null,
"time": 0
},
{
"encoded": "QAAA8AMATUxlbWJyZSBkZSBNaW0gKENhbsOnw6NvIGRlIE5pbmFyKSAoRGUgIlZpdmEgLSBBIFZpZGEgw6kgdW1hIEZlc3RhIi9Db20gbGV0cmEpABFEaXNuZXlNdXNpY0JSVkVWTwAAAAAAARlAAAtkcDZobUo0Vkt5TQABACtodHRwczovL3d3dy55b3V0dWJlLmNvbS93YXRjaD92PWRwNmhtSjRWS3lNAQA0aHR0cHM6Ly9pLnl0aW1nLmNvbS92aS9kcDZobUo0Vkt5TS9tYXhyZXNkZWZhdWx0LmpwZwAAB3lvdXR1YmUAAAAAAAAAAA==",
"identifier": "dp6hmJ4VKyM",
"title": "Lembre de Mim (Canção de Ninar) (De \"Viva - A Vida é uma Festa\"/Com letra)",
"author": "DisneyMusicBRVEVO",
"url": "https://www.youtube.com/watch?v=dp6hmJ4VKyM",
"duration": 72000,
"position": 69380,
"isSeekable": true,
"isStream": false,
"sourceName": "youtube",
"artworkUrl": "https://i.ytimg.com/vi/dp6hmJ4VKyM/maxresdefault.jpg",
"isrc": null,
"time": 0
},
{
"encoded": "QAAAqAMAEUh1bWJlIC0gZmFudGFzbWFzAAVIdW1iZQAAAAAABGEYAAtlMmM4TmtOWTQxVQABACtodHRwczovL3d3dy55b3V0dWJlLmNvbS93YXRjaD92PWUyYzhOa05ZNDFVAQA0aHR0cHM6Ly9pLnl0aW1nLmNvbS92aS9lMmM4TmtOWTQxVS9tYXhyZXNkZWZhdWx0LmpwZwAAB3lvdXR1YmUAAAAAAAAAAA==",
"identifier": "e2c8NkNY41U",
"title": "Humbe - fantasmas",
"author": "Humbe",
"url": "https://www.youtube.com/watch?v=e2c8NkNY41U",
"duration": 287000,
"position": 284780,
"isSeekable": true,
"isStream": false,
"sourceName": "youtube",
"artworkUrl": "https://i.ytimg.com/vi/e2c8NkNY41U/maxresdefault.jpg",
"isrc": null,
"time": 0
},
{
"encoded": "QAAAqAMAEUh1bWJlIC0gZmFudGFzbWFzAAVIdW1iZQAAAAAABGEYAAtlMmM4TmtOWTQxVQABACtodHRwczovL3d3dy55b3V0dWJlLmNvbS93YXRjaD92PWUyYzhOa05ZNDFVAQA0aHR0cHM6Ly9pLnl0aW1nLmNvbS92aS9lMmM4TmtOWTQxVS9tYXhyZXNkZWZhdWx0LmpwZwAAB3lvdXR1YmUAAAAAAAAAAA==",
"identifier": "e2c8NkNY41U",
"title": "Humbe - fantasmas",
"author": "Humbe",
"url": "https://www.youtube.com/watch?v=e2c8NkNY41U",
"duration": 287000,
"position": 284780,
"isSeekable": true,
"isStream": false,
"sourceName": "youtube",
"artworkUrl": "https://i.ytimg.com/vi/e2c8NkNY41U/maxresdefault.jpg",
"isrc": null,
"time": 0
}
]
}
}
1 change: 0 additions & 1 deletion dist/src/@Entities/MoonlinkNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,6 @@ class MoonlinkNode {
player.queue.add(player.current);
if (!queue || queue.length === 0)
return this._manager.emit("trackEnd", player, track, payload);
player.current = queue.shift();
player.play();
return;
}
Expand Down
4 changes: 2 additions & 2 deletions dist/src/@Entities/MoonlinkPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ class MoonlinkPlayer {
await this.node.rest.destroy(this.guildId);
this.queue.clear();
this.manager.players.delete(this.guildId);
this.manager.emit("debug", "@Moonlink(Player): destroyed player " + this.guildId);
this.manager.emit("debug", "@Moonlink(Player) - Destroyed player " + this.guildId);
return true;
}
validateNumberParam(param, paramName) {
Expand All @@ -316,7 +316,7 @@ class MoonlinkPlayer {
if (!this.queue.size) {
throw new Error(`@Moonlink(Player) - The "shuffle" method doesn't work if there are no tracks in the queue`);
}
mode ? mode : (mode = !this.shuffled);
mode ?? (mode = !this.shuffled);
this.shuffled = mode;
return mode;
}
Expand Down
2 changes: 1 addition & 1 deletion dist/src/@Managers/MoonlinkManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class MoonlinkManager extends node_events_1.EventEmitter {
});
}
if (!this.options.clientName)
this.options.clientName = `@Moonlink/${this.version} (https://github.com/Ecliptia/moonlink.js)`;
this.options.clientName = `Moonlink/${this.version} (https://github.com/Ecliptia/moonlink.js)`;
}
init(clientId) {
if (this.initiated)
Expand Down
4 changes: 2 additions & 2 deletions dist/src/@Managers/PlayerManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class PlayerManager {
}
get(guildId) {
if (!guildId && typeof guildId !== "string")
throw new Error('[ @Moonlink/Manager ]: "guildId" option in parameter to get player is empty or type is different from string');
throw new Error('@Moonlink(PlayerManager) - "guildId" option in parameter to get player is empty or type is different from string');
if (!this.has(guildId))
return null;
return this.cache[guildId];
Expand Down Expand Up @@ -106,7 +106,7 @@ class PlayerManager {
missingParams.push("autoPlay");
if (data.node && typeof data.node !== "string")
missingParams.push("node");
throw new Error(`[ @Moonlink/Manager ]: Invalid or missing parameters for player creation: ${missingParams.join(", ")}`);
throw new Error(`@Moonlink(PlayerManager) - Missing parameters for player creation: ${missingParams.join(", ")}`);
}
if (this.has(data.guildId))
return this.get(data.guildId);
Expand Down
2 changes: 1 addition & 1 deletion dist/src/@Utils/MoonlinkTrack.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class MoonlinkTrack {
requester;
artworkUrl;
isrc;
time;
time = 0;
constructor(data, requester) {
this.encoded = data.encoded;
this.title = data.info.title;
Expand Down
1 change: 1 addition & 0 deletions dist/src/@Utils/Structure.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export declare abstract class Structure {
}
export declare class Plugin {
load(manager: MoonlinkManager): void;
unload(manager: MoonlinkManager): void;
}
1 change: 1 addition & 0 deletions dist/src/@Utils/Structure.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ class Structure {
exports.Structure = Structure;
class Plugin {
load(manager) { }
unload(manager) { }
}
exports.Plugin = Plugin;
3 changes: 1 addition & 2 deletions src/@Entities/MoonlinkNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,7 @@ export class MoonlinkNode {
track,
payload
);

player.current = queue.shift() as MoonlinkTrack | any;

player.play();
return;
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/@Entities/MoonlinkPlayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ export class MoonlinkPlayer {
this.manager.players.delete(this.guildId);
this.manager.emit(
"debug",
"@Moonlink(Player): destroyed player " + this.guildId
"@Moonlink(Player) - Destroyed player " + this.guildId
);

return true;
Expand Down Expand Up @@ -524,7 +524,7 @@ export class MoonlinkPlayer {
`@Moonlink(Player) - The "shuffle" method doesn't work if there are no tracks in the queue`
);
}
mode ? mode : (mode = !this.shuffled);
mode ?? (mode = !this.shuffled);
this.shuffled = mode;
return mode;
}
Expand Down
2 changes: 1 addition & 1 deletion src/@Managers/MoonlinkManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class MoonlinkManager extends EventEmitter {
});
}
if (!this.options.clientName)
this.options.clientName = `@Moonlink/${this.version} (https://github.com/Ecliptia/moonlink.js)`;
this.options.clientName = `Moonlink/${this.version} (https://github.com/Ecliptia/moonlink.js)`;
}
public init(clientId?: string): this {
if (this.initiated) return this;
Expand Down
7 changes: 5 additions & 2 deletions src/@Managers/PlayerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,13 @@ export class PlayerManager {
public get(guildId: string): MoonlinkPlayer | null {
if (!guildId && typeof guildId !== "string")
throw new Error(
'[ @Moonlink/Manager ]: "guildId" option in parameter to get player is empty or type is different from string'
'@Moonlink(PlayerManager) - "guildId" option in parameter to get player is empty or type is different from string'
);
if (!this.has(guildId)) return null;

return this.cache[guildId];
}

public create(data: createOptions): MoonlinkPlayer {
if (
typeof data !== "object" ||
Expand Down Expand Up @@ -155,7 +156,7 @@ export class PlayerManager {
missingParams.push("node");

throw new Error(
`[ @Moonlink/Manager ]: Invalid or missing parameters for player creation: ${missingParams.join(
`@Moonlink(PlayerManager) - Missing parameters for player creation: ${missingParams.join(
", "
)}`
);
Expand Down Expand Up @@ -184,9 +185,11 @@ export class PlayerManager {

return instance;
}

public get all(): Record<string, any> | null {
return this.cache ?? null;
}

public delete(guildId): void {
delete this.cache[guildId];
}
Expand Down
3 changes: 0 additions & 3 deletions src/@Services/MoonlinkWebSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ import https from "https";
import crypto from "crypto";
import { EventEmitter } from "events";

// @Author: 1Lucas1apk
// Code made entirely by me, the code can be used as inspiration for your own RFC 6455 Protocol

export class MoonlinkWebSocket extends EventEmitter {
private url: URL;
private options: any;
Expand Down
2 changes: 1 addition & 1 deletion src/@Utils/MoonlinkTrack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class MoonlinkTrack {
public requester: any;
public artworkUrl: string;
public isrc: string;
public time?: number;
public time?: number = 0;
constructor(data: MoonlinkTrackOptions, requester?: string | any) {
this.encoded = data.encoded;
this.title = data.info.title;
Expand Down
1 change: 1 addition & 0 deletions src/@Utils/Structure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,5 @@ export abstract class Structure {

export class Plugin {
public load(manager: MoonlinkManager): void {}
public unload(manager: MoonlinkManager): void {}
}
4 changes: 3 additions & 1 deletion testBot/commands/music/shuffle.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ module.exports = {
let player = client.moon.players.get(message.guild.id);

if (!player.playing) return message.reply("<:hi:1176345748405768252> | ")


if(!player.queue.size) return message.reply("<:hi:1176345748405768252> | ")

player.shuffle(!player.shuffled);
return message.reply(`<:hi:1176345748405768252> | shuffled(${player.shuffled})`);
},
Expand Down
4 changes: 3 additions & 1 deletion testBot/commands/music/skip.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ module.exports = {
let player = client.moon.players.get(message.guild.id);

if (!player.queue.size) return message.reply("<:hi:1176345748405768252> | ")

if (args[0] && typeof args[0] !== "number") return message.reply("<:hi:1176345748405768252> | ")

player.skip();
player.skip(args[0] ?? null);
message.reply("<:hi:1176345748405768252> | Skiped");
},
};
38 changes: 6 additions & 32 deletions testBot/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,26 @@ const {
Client,
Collection
} = require("discord.js");
const mongoose = require("mongoose");

const {
MoonlinkManager,
Plugin,
makeRequest
} = require("../dist/index.js");
} = require("../dist/index.js")

const {
Lyrics
} = require("../../moonlink.js-lyrics/index.js")
const {
mongodb
} = require("../../moonlink.js-mongodb/index.js")

const fs = require("fs");
const path = require("path");
const http = require("http");

const log = (message) => {
const coloredMessage = message.replace(/\((.*?)\)/g, "\x1b[34m[$1]\x1b[0m");
const coloredMessage = message.replace(/\((.*?)\)/g, "\x1b[34m($1)\x1b[0m");
console.log(coloredMessage);
};

console.log(Lyrics, !(Lyrics instanceof Plugin))

const client = new Client({
intents: 131071,
Expand Down Expand Up @@ -88,7 +85,7 @@ client.moon = new MoonlinkManager(
autoResume: true,
clientName: "Moonlink/Blio",
WebSocketDebug: true,
plugins: [new Lyrics(), /*new mongodb(mongoose)*/],
plugins: [new Lyrics()],
},
(id, data) => {
let guild = client.guilds.cache.get(id);
Expand Down Expand Up @@ -125,32 +122,9 @@ client.on("messageCreate", (message) => {
});

client.moon.on("debug", log);
client.moon.on("nodeCreate", (node) =>
log(`[ Moonlink/Event ]: Node created: ${node.identifier || node.host}`),
);

client.on("error", (error) => {
log(`[ Client ]: Client error: ${error}`);
});

const server = http.createServer((req, res) => {
res.writeHead(200, {
"Content-Type": "text/plain"
});
res.end("Hello, World!\n");
});

/*
server.listen(80, () => {
log(`[ Server ]: Server running;`);
});
*/
const token = require ("../config.json").token;
if (!token) {
console.error(
"[ System ]: Please provide a valid TOKEN in the environment variables.",
);

} else {
client.login(token);
}
client.login(require ("../config.json").token);

0 comments on commit 889e0bd

Please sign in to comment.