From 8aba76a9246ad32be1fc8005859df279dbf99b79 Mon Sep 17 00:00:00 2001 From: JonnyBro Date: Sat, 26 Mar 2022 17:23:03 +0500 Subject: [PATCH] v3.4.4 --- base/User.js | 9 ++- commands/Economy/transactions.js | 8 +- commands/Music/createplaylist.js | 45 +++++++++++ commands/Music/playlists.js | 98 +++++++++++++++++++++++ commands/Music/playplaylist.js | 56 +++++++++++++ commands/Music/queue.js | 7 +- commands/Music/removeplaylist.js | 44 ++++++++++ dashboard/public/docs/updates.md | 12 +++ languages/ru-RU/music/createplaylist.json | 8 ++ languages/ru-RU/music/playlists.json | 12 +++ languages/ru-RU/music/playplaylist.json | 8 ++ languages/ru-RU/music/queue.json | 3 +- languages/ru-RU/music/removeplaylist.json | 8 ++ package-lock.json | 22 ++--- package.json | 4 +- 15 files changed, 317 insertions(+), 27 deletions(-) create mode 100644 commands/Music/createplaylist.js create mode 100644 commands/Music/playlists.js create mode 100644 commands/Music/playplaylist.js create mode 100644 commands/Music/removeplaylist.js create mode 100644 languages/ru-RU/music/createplaylist.json create mode 100644 languages/ru-RU/music/playlists.json create mode 100644 languages/ru-RU/music/playplaylist.json create mode 100644 languages/ru-RU/music/removeplaylist.json diff --git a/base/User.js b/base/User.js index 35120348..dd309ee8 100644 --- a/base/User.js +++ b/base/User.js @@ -82,10 +82,11 @@ const userSchema = new mongoose.Schema({ }}, /* OTHER INFORMATIONS */ - afk: { type: String, default: null }, // Whether the member is AFK - reminds: { type: Array, default: [] }, // the reminds of the user - logged: { type: Boolean, default: false }, // if the user is logged to the dashboard - apiToken: { type: String, default: genToken() } // the api token of the user + afk: { type: String, default: null }, // The AFK reason (if any) + reminds: { type: Array, default: [] }, // The reminds of the user + playlists: { type: Array, default: [] }, // The playlists of the user + logged: { type: Boolean, default: false }, // If the user is logged to the dashboard + apiToken: { type: String, default: genToken() } // The API token of the user }); userSchema.method("genApiToken", async function() { diff --git a/commands/Economy/transactions.js b/commands/Economy/transactions.js index a36d78ca..f39c9e13 100644 --- a/commands/Economy/transactions.js +++ b/commands/Economy/transactions.js @@ -20,8 +20,8 @@ class Transactions extends Command { async run(message, args, data) { const timestamp = Date.now() + (30 * 24 * 60 * 60 * 1000); // day hour min sec msec / 1 month const transactions = data.memberData.transactions; - for (const t of transactions) { - if (t.date > timestamp) { + for await (const t of transactions) { + if (t.date < timestamp) { const index = transactions.indexOf(t); transactions.splice(index, 1); } @@ -50,13 +50,11 @@ class Transactions extends Command { if (transactions.length < 1) { embed.setDescription(message.translate("economy/transactions:NO_TRANSACTIONS")); - return message.reply({ - embeds: [embed] - }); } else { if (sortedTransactions[0].length > 0) embed.addField(message.translate("economy/transactions:T_GOT"), sortedTransactions[0].join("\n"), true); if (sortedTransactions[1].length > 0) embed.addField(message.translate("economy/transactions:T_SEND"), sortedTransactions[1].join("\n"), true); } + message.reply({ embeds: [embed] }); diff --git a/commands/Music/createplaylist.js b/commands/Music/createplaylist.js new file mode 100644 index 00000000..86fdc036 --- /dev/null +++ b/commands/Music/createplaylist.js @@ -0,0 +1,45 @@ +const Command = require("../../base/Command"); + +class CreatePlaylist extends Command { + constructor(client) { + super(client, { + name: "createplaylist", + dirname: __dirname, + enabled: true, + guildOnly: true, + aliases: ["cpl", "createpl"], + memberPermissions: [], + botPermissions: ["SEND_MESSAGES", "EMBED_LINKS"], + nsfw: false, + ownerOnly: false, + cooldown: 3000 + }); + } + + async run(message, args, data) { + args = args.join(" ").split(" | "); + + const name = args[0]; + const songs = args[1].split(" "); + if (!name) return message.error("music/createplaylist:NO_NAME"); + if (!songs) return message.error("music/createplaylist:NO_SONGS"); + + const playlist = await this.client.player.createCustomPlaylist(songs, { + member: message.member, + properties: { + name + }, + parallel: true + }); + + data.userData.playlists.push(playlist); + data.userData.markModified("playlists"); + data.userData.save(); + + message.success("music/createplaylist:CREATED", { + name + }); + } +} + +module.exports = CreatePlaylist; \ No newline at end of file diff --git a/commands/Music/playlists.js b/commands/Music/playlists.js new file mode 100644 index 00000000..01fec0dc --- /dev/null +++ b/commands/Music/playlists.js @@ -0,0 +1,98 @@ +const Command = require("../../base/Command"), + Discord = require("discord.js"); + +class Playlists extends Command { + constructor(client) { + super(client, { + name: "playlists", + dirname: __dirname, + enabled: true, + guildOnly: true, + aliases: ["pls"], + memberPermissions: [], + botPermissions: ["SEND_MESSAGES", "EMBED_LINKS"], + nsfw: false, + ownerOnly: false, + cooldown: 3000 + }); + } + + async run(message, args, data) { + const playlists = data.userData.playlists; + + if (args[0]) { + const name = args.join(" "); + let playlist; + + for (const pl of playlists) { + if (pl.name === name) { + playlist = pl; + } else { + message.error("music/removeplaylist:NOT_FOUND", { + name + }); + } + } + + const embed = new Discord.MessageEmbed() + .setAuthor({ + name: message.translate("music/playlists:EMBED_TITLE2", { + name + }), + iconURL: message.author.displayAvatarURL({ + size: 512, + dynamic: true, + format: "png" + }) + }) + .setColor(data.config.embed.color) + .setFooter({ + text: data.config.embed.footer + }) + .addField(message.translate("music/playlists:NAME"), playlist.name, true) + .addField(message.translate("music/playlists:COUNT"), playlist.songs.length.toString(), true); + + const songs = []; + for (const song of playlist.songs) { + songs.push(`[${song.name}](${song.url})`); + } + + embed.addField(message.translate("music/playlists:SONGS"), songs.join("\n")); + + return message.reply({ + embeds: [embed] + }); + } + + const embed = new Discord.MessageEmbed() + .setAuthor({ + name: message.translate("music/playlists:EMBED_TITLE"), + iconURL: message.author.displayAvatarURL({ + size: 512, + dynamic: true, + format: "png" + }) + }) + .setColor(data.config.embed.color) + .setFooter({ + text: data.config.embed.footer + }); + + const pls = []; + playlists.forEach((pl) => { + pls.push(`${message.translate("music/playlists:NAME")}: ${pl.name}\n${message.translate("music/playlists:COUNT")}: ${pl.songs.length}\n`); + }); + + if (playlists.length < 1) { + embed.setDescription(message.translate("music/playlists:NO_PLAYLISTS")); + } else { + embed.addField(message.translate("music/playlists:PLAYLISTS"), pls.join("\n"), true); + } + + message.reply({ + embeds: [embed] + }); + } +} + +module.exports = Playlists; \ No newline at end of file diff --git a/commands/Music/playplaylist.js b/commands/Music/playplaylist.js new file mode 100644 index 00000000..d7d475c4 --- /dev/null +++ b/commands/Music/playplaylist.js @@ -0,0 +1,56 @@ +const Command = require("../../base/Command"), + DisTube = require("distube"), + { Permissions } = require("discord.js"); + +class PlayPlaylists extends Command { + constructor(client) { + super(client, { + name: "playplaylist", + dirname: __dirname, + enabled: true, + guildOnly: true, + aliases: ["ppl"], + memberPermissions: [], + botPermissions: ["SEND_MESSAGES", "EMBED_LINKS"], + nsfw: false, + ownerOnly: false, + cooldown: 3000 + }); + } + + async run(message, args, data) { + const voice = message.member.voice.channel; + const name = args.join(" "); + let playlist; + for (const pl of data.userData.playlists) { + if (pl.name === name) { + playlist = new DisTube.Playlist(pl); + } else { + return message.error("music/removeplaylist:NOT_FOUND", { + name + }); + } + } + + if (!voice) return message.error("music/play:NO_VOICE_CHANNEL"); + + // Check my permissions + const perms = voice.permissionsFor(this.client.user); + if (!perms.has(Permissions.FLAGS.CONNECT) || !perms.has(Permissions.FLAGS.SPEAK)) return message.error("music/play:VOICE_CHANNEL_CONNECT"); + + try { + this.client.player.play(message.member.voice.channel, playlist, { + member: message.member, + textChannel: message.channel, + message + }); + } catch (e) { + message.error("music/play:ERR_OCCURRED", { + error: e + }); + console.error(e); + } + } +} + +module.exports = PlayPlaylists; \ No newline at end of file diff --git a/commands/Music/queue.js b/commands/Music/queue.js index 79944065..735b2ec7 100644 --- a/commands/Music/queue.js +++ b/commands/Music/queue.js @@ -33,7 +33,7 @@ class Queue extends Command { dynamic: true }) }) - .addField(message.translate("music/np:CURRENTLY_PLAYING"), `[${queue.songs[0].name}](${queue.songs[0].url})\n*Добавил ${queue.songs[0].member}*\n`) + .addField(message.translate("music/np:CURRENTLY_PLAYING"), `[${queue.songs[0].name}](${queue.songs[0].url})\n*${message.translate("music/queue:ADDED")} ${queue.songs[0].member || message.translate("music/queue:PLAYLIST")}*\n`) .setColor(data.config.embed.color); return message.reply({ embeds: [embed] @@ -50,8 +50,7 @@ class Queue extends Command { dynamic: true }) }) - .addField(message.translate("music/np:CURRENTLY_PLAYING"), `[${queue.songs[0].name}](${queue.songs[0].url})\n*${message.translate("music/queue:TITLE")} ${queue.songs[0].member}*\n`); - + .addField(message.translate("music/np:CURRENTLY_PLAYING"), `[${queue.songs[0].name}](${queue.songs[0].url})\n*${message.translate("music/queue:ADDED")} ${queue.songs[0].member || message.translate("music/queue:PLAYLIST")}*\n`); FieldsEmbed .setArray(queue.songs[1] ? queue.songs.slice(1, queue.songs.length) : []) .setAuthorizedUsers([message.author.id]) @@ -60,7 +59,7 @@ class Queue extends Command { .setDeleteOnTimeout(true) .setDisabledNavigationEmojis(["jump"]) .setPageIndicator(true) - .formatField(message.translate("music/queue:TITLE"), (track) => `**${queue.songs.indexOf(track)}**. [${track.name}](${track.url})\n*${message.translate("music/queue:TITLE")} ${track.member}*\n`) + .formatField(message.translate("music/queue:TITLE"), (track) => `**${queue.songs.indexOf(track)}**. [${track.name}](${track.url})\n*${message.translate("music/queue:ADDED")} ${track.member || message.translate("music/queue:PLAYLIST")}*\n`) .build(); } } diff --git a/commands/Music/removeplaylist.js b/commands/Music/removeplaylist.js new file mode 100644 index 00000000..318835a4 --- /dev/null +++ b/commands/Music/removeplaylist.js @@ -0,0 +1,44 @@ +const Command = require("../../base/Command"); + +class RemovePlaylist extends Command { + constructor(client) { + super(client, { + name: "removeplaylist", + dirname: __dirname, + enabled: true, + guildOnly: true, + aliases: ["rpl", "removepl"], + memberPermissions: [], + botPermissions: ["SEND_MESSAGES", "EMBED_LINKS"], + nsfw: false, + ownerOnly: false, + cooldown: 3000 + }); + } + + async run(message, args, data) { + const name = args[0]; + if (!name) return message.error("music/createplaylist:NO_NAME"); + + const playlists = data.userData.playlists; + for (const playlist of playlists) { + if (playlist.name === name) { + const index = playlists.indexOf(playlist); + playlists.splice(index, 1); + + data.userData.markModified("playlists"); + data.userData.save(); + + message.success("music/removeplaylist:REMOVED", { + name + }); + } else { + message.error("music/removeplaylist:NOT_FOUND", { + name + }); + } + } + } +} + +module.exports = RemovePlaylist; \ No newline at end of file diff --git a/dashboard/public/docs/updates.md b/dashboard/public/docs/updates.md index 18779221..892b0640 100644 --- a/dashboard/public/docs/updates.md +++ b/dashboard/public/docs/updates.md @@ -1,3 +1,15 @@ +### JaBa v3.4.4 +* Добавлено + * Создание, удаление и воспроизведение плейлистов! + * *createplaylist (cpl)* - Создать плейлист. + * *playlists (pls)* - Список ваших плейлистов (Так же информация об отдельном плейлисте, смотрите *help*). + * *playplaylist (ppl)* - Воспроизвести ваш плейлист. + * *removeplaylist (rpl)* - Удалить плейлист. + +* Исправления + * Транзакции в *transactions* удаляются через месяц. + * Мелкие правки в локализации, исправление орфографических ошибок. + ### JaBa v3.4.3 * Изменения * Украинская локализация закончена. diff --git a/languages/ru-RU/music/createplaylist.json b/languages/ru-RU/music/createplaylist.json new file mode 100644 index 00000000..2b8d3595 --- /dev/null +++ b/languages/ru-RU/music/createplaylist.json @@ -0,0 +1,8 @@ +{ + "DESCRIPTION": "Создать плейлист", + "USAGE": "{{prefix}}createplaylist [название] | [ссылки на треки/трансляции]", + "EXAMPLES": "{{prefix}}createplaylist Мой крутой плейлист | https://www.youtube.com/watch?v=dQw4w9WgXcQ https://www.youtube.com/watch?v=MEg-oqI9qmw", + "NO_NAME": "Укажите название плейлиста!", + "NO_SONGS": "Укажите ссылки(у) на треки/трансляции!", + "CREATED": "Плейлист `{{name}}` сохранён!" +} \ No newline at end of file diff --git a/languages/ru-RU/music/playlists.json b/languages/ru-RU/music/playlists.json new file mode 100644 index 00000000..8f12b606 --- /dev/null +++ b/languages/ru-RU/music/playlists.json @@ -0,0 +1,12 @@ +{ + "DESCRIPTION": "Посмотреть список ваших плейлистов", + "USAGE": "{{prefix}}playlists (название)", + "EXAMPLES": "{{prefix}}playlists\n{{prefix}}playlists Мой крутой плейлист", + "EMBED_TITLE": "Список плейлистов", + "EMBED_TITLE2": "Плейлист \"{{name}}\"", + "NO_PLAYLISTS": "У вас нет плейлистов!", + "PLAYLISTS": "Плейлисты", + "NAME": "Название", + "COUNT": "Количество треков", + "SONGS": "Треки в плейлисте" +} \ No newline at end of file diff --git a/languages/ru-RU/music/playplaylist.json b/languages/ru-RU/music/playplaylist.json new file mode 100644 index 00000000..2b8d3595 --- /dev/null +++ b/languages/ru-RU/music/playplaylist.json @@ -0,0 +1,8 @@ +{ + "DESCRIPTION": "Создать плейлист", + "USAGE": "{{prefix}}createplaylist [название] | [ссылки на треки/трансляции]", + "EXAMPLES": "{{prefix}}createplaylist Мой крутой плейлист | https://www.youtube.com/watch?v=dQw4w9WgXcQ https://www.youtube.com/watch?v=MEg-oqI9qmw", + "NO_NAME": "Укажите название плейлиста!", + "NO_SONGS": "Укажите ссылки(у) на треки/трансляции!", + "CREATED": "Плейлист `{{name}}` сохранён!" +} \ No newline at end of file diff --git a/languages/ru-RU/music/queue.json b/languages/ru-RU/music/queue.json index 7b4ef50b..9e08a054 100644 --- a/languages/ru-RU/music/queue.json +++ b/languages/ru-RU/music/queue.json @@ -3,5 +3,6 @@ "USAGE": "{{prefix}}queue", "EXAMPLES": "{{prefix}}queue", "TITLE": "Очередь", - "ADDED": "Добавил" + "ADDED": "Добавил", + "PLAYLIST": "Плейлист" } \ No newline at end of file diff --git a/languages/ru-RU/music/removeplaylist.json b/languages/ru-RU/music/removeplaylist.json new file mode 100644 index 00000000..244a39c1 --- /dev/null +++ b/languages/ru-RU/music/removeplaylist.json @@ -0,0 +1,8 @@ +{ + "DESCRIPTION": "Удалить плейлист", + "USAGE": "{{prefix}}removeplaylist [название]", + "EXAMPLES": "{{prefix}}removeplaylist Мой крутой плейлист", + "NO_NAME": "Укажите название плейлиста!", + "REMOVED": "Плейлист `{{name}}` удалён!", + "NOT_FOUND": "Плейлист `{{name}}` не найден!" +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 845187e4..3483e818 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "jaba", - "version": "3.4.3", + "version": "3.4.4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "jaba", - "version": "3.4.2", + "version": "3.4.3", "license": "ISC", "dependencies": { "@discordjs/opus": "^0.7.0", @@ -30,7 +30,7 @@ "discord-paginationembed": "github:gazmull/discord-paginationembed#v3", "discord-together": "^1.3.3", "discord.js": "^13.6.0", - "distube": "^3.3.2", + "distube": "^3.3.3", "ejs": "^3.1.3", "express": "^4.17.1", "express-session": "^1.17.0", @@ -1472,12 +1472,12 @@ } }, "node_modules/distube": { - "version": "3.3.2", - "resolved": "https://registry.npmjs.org/distube/-/distube-3.3.2.tgz", - "integrity": "sha512-cSri8ulAw7cP7hSC7Dfgw++O0U7pv6EhtMtB7I5oIzDC+YNv9qg0P1DKZ/TnuBWcmdBaxltmeG4o6BHiOLshiw==", + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/distube/-/distube-3.3.3.tgz", + "integrity": "sha512-4iGrKmyVT46/V/J6KZ+1XOq1gosbr07KZtMKodYtuG2vAX/cNP9TA2giqX7wJZoXJO2NYic7XWe06Z/NgBlgIw==", "dependencies": { "@distube/youtube-dl": "^2.2.4", - "@distube/ytdl-core": "^4.9.4", + "@distube/ytdl-core": "^4.11.1", "@distube/ytpl": "^1.1.1", "@distube/ytsr": "^1.1.5", "prism-media": "https://codeload.github.com/distubejs/prism-media/tar.gz/main#workaround.tar.gz", @@ -5837,12 +5837,12 @@ } }, "distube": { - "version": "3.3.2", - "resolved": "https://registry.npmjs.org/distube/-/distube-3.3.2.tgz", - "integrity": "sha512-cSri8ulAw7cP7hSC7Dfgw++O0U7pv6EhtMtB7I5oIzDC+YNv9qg0P1DKZ/TnuBWcmdBaxltmeG4o6BHiOLshiw==", + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/distube/-/distube-3.3.3.tgz", + "integrity": "sha512-4iGrKmyVT46/V/J6KZ+1XOq1gosbr07KZtMKodYtuG2vAX/cNP9TA2giqX7wJZoXJO2NYic7XWe06Z/NgBlgIw==", "requires": { "@distube/youtube-dl": "^2.2.4", - "@distube/ytdl-core": "^4.9.4", + "@distube/ytdl-core": "^4.11.1", "@distube/ytpl": "^1.1.1", "@distube/ytsr": "^1.1.5", "prism-media": "https://codeload.github.com/distubejs/prism-media/tar.gz/main#workaround.tar.gz", diff --git a/package.json b/package.json index 9cbb7fa1..798fd08d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jaba", - "version": "3.4.3", + "version": "3.4.4", "description": "A very complete Discord bot (more than 100 commands) that uses the Discord.js", "main": "index.js", "private": true, @@ -34,7 +34,7 @@ "discord-paginationembed": "github:gazmull/discord-paginationembed#v3", "discord-together": "^1.3.3", "discord.js": "^13.6.0", - "distube": "^3.3.2", + "distube": "^3.3.3", "ejs": "^3.1.3", "express": "^4.17.1", "express-session": "^1.17.0",