From 163b6ce83622e9c4092c075df5e94ad3f12538e5 Mon Sep 17 00:00:00 2001 From: MatteZ02 <47610069+MatteZ02@users.noreply.github.com> Date: Sun, 12 Jul 2020 19:08:53 +0300 Subject: [PATCH] Chore update 3.9 --- package.json | 16 ++++++++-------- src/commands/bass.js | 2 +- src/commands/cmduses.js | 2 +- src/commands/end.js | 13 ------------- src/commands/loop.js | 2 +- src/commands/loopsong.js | 2 +- src/commands/nigthcore.js | 2 +- src/commands/nowplaying.js | 4 ++-- src/commands/pause.js | 2 +- src/commands/play.js | 25 ++++++++----------------- src/commands/previous.js | 2 +- src/commands/queue.js | 2 +- src/commands/remove.js | 2 +- src/commands/replay.js | 2 +- src/commands/resume.js | 2 +- src/commands/search.js | 11 ++--------- src/commands/seek.js | 2 +- src/commands/shuffle.js | 2 +- src/commands/skip.js | 2 +- src/commands/skipto.js | 2 +- src/commands/soundcloud.js | 2 +- src/commands/stop.js | 2 +- src/commands/volume.js | 2 +- src/events/dispatcherEvents/finish.js | 2 +- src/struct/client.js | 10 +++++++++- src/struct/config/config.js | 3 ++- src/struct/funcs/getSpotifyKey.js | 5 ++++- 27 files changed, 54 insertions(+), 71 deletions(-) delete mode 100644 src/commands/end.js diff --git a/package.json b/package.json index 643e1b82..417dcb2b 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,10 @@ { "name": "musix", - "version": "3.8.4", + "version": "3.9.0", "description": "V3 for Musix the discord music bot", "main": "./index.js", "scripts": { - "start": "node --max-old-space-size=4096 index.js" + "start": "node --max-old-space-size=3072 index.js" }, "repository": { "type": "git", @@ -24,13 +24,13 @@ "cookie-parser": "^1.4.5", "cors": "^2.8.5", "dblapi.js": "^2.4.0", - "discord-webhook-node": "^1.0.7", + "discord-webhook-node": "^1.1.0", "discord.js": "^12.2.0", "dotenv": "^8.2.0", "erlpack": "github:discordapp/erlpack", "express": "^4.17.1", - "firebase": "^7.14.6", - "firebase-admin": "^8.12.1", + "firebase": "^7.16.0", + "firebase-admin": "^8.13.0", "fs": "0.0.1-security", "genius-lyrics-api": "^2.0.3", "he": "^1.2.0", @@ -44,8 +44,8 @@ "soundcloud-api-client": "0.0.9", "spotify-web-api-node": "^4.0.0", "utf-8-validate": "^5.0.2", - "ytdl-core": "^3.1.0", + "ytdl-core": "^3.1.2", "ytsr": "^0.1.15", - "zlib-sync": "^0.1.6" + "zlib-sync": "^0.1.7" } -} \ No newline at end of file +} diff --git a/src/commands/bass.js b/src/commands/bass.js index 7d35b633..ec5638d2 100644 --- a/src/commands/bass.js +++ b/src/commands/bass.js @@ -6,7 +6,7 @@ module.exports = { cooldown: 5, onlyDev: false, permission: "MANAGE_MESSAGES", - category: "music", + category: "audio modifiers", execute(msg, args, client, Discord, command) { const queue = client.queue.get(msg.guild.id); if (!args[1] && queue) diff --git a/src/commands/cmduses.js b/src/commands/cmduses.js index 14d51f55..5c2c3db2 100644 --- a/src/commands/cmduses.js +++ b/src/commands/cmduses.js @@ -5,7 +5,7 @@ module.exports = { description: 'list all commands and how many times they\'ve been used', onlyDev: true, permission: 'dev', - category: 'info', + category: 'util', async execute(msg, args, client, Discord, command) { const cmduses = []; client.commands.forEach((value, key) => { diff --git a/src/commands/end.js b/src/commands/end.js deleted file mode 100644 index b8fdf7dc..00000000 --- a/src/commands/end.js +++ /dev/null @@ -1,13 +0,0 @@ -module.exports = { - name: 'end', - alias: ["none"], - usage: '', - description: 'just end it', - onlyDev: true, - permission: 'dev', - category: 'util', - async execute(msg, args, client, Discord, command) { - client.queue.delete(msg.guild.id); - msg.channel.send(client.messages.queueDeleted); - } -}; \ No newline at end of file diff --git a/src/commands/loop.js b/src/commands/loop.js index 5e2de3a3..061d3320 100644 --- a/src/commands/loop.js +++ b/src/commands/loop.js @@ -5,7 +5,7 @@ module.exports = { description: 'loop the queue.', onlyDev: false, permission: 'MANAGE_MESSAGES', - category: 'music', + category: 'music control', async execute(msg, args, client, Discord, command) { const queue = client.queue.get(msg.guild.id); if (client.funcs.check(client, msg, command)) { diff --git a/src/commands/loopsong.js b/src/commands/loopsong.js index ba6c679a..3c793d24 100644 --- a/src/commands/loopsong.js +++ b/src/commands/loopsong.js @@ -5,7 +5,7 @@ module.exports = { description: 'loop the currently playing song.', onlyDev: false, permission: 'MANAGE_MESSAGES', - category: 'music', + category: 'music control', async execute(msg, args, client, Discord, command) { const queue = client.queue.get(msg.guild.id); if (client.funcs.check(client, msg, command)) { diff --git a/src/commands/nigthcore.js b/src/commands/nigthcore.js index 3c279f55..8381a537 100644 --- a/src/commands/nigthcore.js +++ b/src/commands/nigthcore.js @@ -5,7 +5,7 @@ module.exports = { description: "Change nigthcore audio modifier on/off", onlyDev: false, permission: "MANAGE_MESSAGES", - category: "music", + category: "audio modifiers", async execute(msg, args, client, Discord, command) { const queue = client.queue.get(msg.guild.id); if (!args[1] && queue) diff --git a/src/commands/nowplaying.js b/src/commands/nowplaying.js index 0fe5bcf7..6b105562 100644 --- a/src/commands/nowplaying.js +++ b/src/commands/nowplaying.js @@ -5,10 +5,10 @@ module.exports = { description: "See the currently playing song position and length.", onlyDev: false, permission: "none", - category: "music", + category: "info", async execute(msg, args, client, Discord, command) { const queue = client.queue.get(msg.guild.id); - if (!queue) return msg.channel.send(client.messages.noServerQueue); + if (!queue || !queue.songs[0] || !queue.connection || !queue.connection.dispatcher) return msg.channel.send(client.messages.noServerQueue); let songTime = (queue.songs[0].info.lengthSeconds * 1000).toFixed(0); let completed = ( queue.connection.dispatcher.streamTime + queue.time diff --git a/src/commands/pause.js b/src/commands/pause.js index f6939d9a..b657f32e 100644 --- a/src/commands/pause.js +++ b/src/commands/pause.js @@ -5,7 +5,7 @@ module.exports = { description: 'Pause the currently playing music.', onlyDev: false, permission: 'MANAGE_MESSAGES', - category: 'music', + category: 'music control', execute(msg, args, client, Discord, command) { const queue = client.queue.get(msg.guild.id); if (client.funcs.check(client, msg, command)) { diff --git a/src/commands/play.js b/src/commands/play.js index 44d3845f..12958827 100644 --- a/src/commands/play.js +++ b/src/commands/play.js @@ -1,5 +1,3 @@ -const YouTube = require("simple-youtube-api"); -const SpotifyApi = require("spotify-web-api-node"); const ytdl = require("ytdl-core"); const ytsr = require("ytsr"); @@ -10,15 +8,8 @@ module.exports = { description: "Play some music.", onlyDev: false, permission: "none", - category: "music", + category: "play", async execute(msg, args, client, Discord, command) { - const spotify = new SpotifyApi({ - id: client.config.spotify_client_id, - secret: client.config.spotify_client_secret, - }); - spotify.setAccessToken(client.config.spotify_access_key); - - const youtube = new YouTube(client.config.api_key); const searchString = args.slice(1).join(" "); const url = args[1] ? args[1].replace(/<(.+)>/g, "$1") : ""; const queue = client.queue.get(msg.guild.id); @@ -47,7 +38,7 @@ module.exports = { } else if (url.match(/^https?:\/\/(open.spotify.com|spotify.com)(.*)$/)) { if (url.includes("playlist")) { const playlistId = url.split("/playlist/")[1].split("?")[0]; - spotify.getPlaylist(playlistId).then( + client.spotify.getPlaylist(playlistId).then( async function (data) { console.log(data.body) searchPlaylist(data, client, msg, voiceChannel); @@ -59,7 +50,7 @@ module.exports = { ); } else if (url.includes("album")) { const albumId = url.split("/album/")[1].split("?")[0]; - spotify.getAlbumTracks(albumId).then( + client.spotify.getAlbumTracks(albumId).then( async function (data) { searchAlbum(data, client, msg, voiceChannel); }, @@ -82,17 +73,17 @@ module.exports = { url.match(/^https?:\/\/(www.youtube.com|youtube.com)\/playlist(.*)$/) ) { const lmsg = await msg.channel.send(client.messages.loadingSongs); - const playlist = await youtube.getPlaylist(url).catch((err) => { + const playlist = await client.youtube.getPlaylist(url).catch((err) => { console.log("err1"); }); const videos = await playlist.getVideos().catch((err) => { console.log("err2"); }); for (const video of Object.values(videos)) { - const video2 = await youtube.getVideoByID(video.id).catch((err) => { + const video2 = await client.youtube.getVideoByID(video.id).catch((err) => { console.log("err3"); }); - spotify.searchTracks(`track:${video2.name}`).then( + client.spotify.searchTracks(`track:${video2.name}`).then( function (data) { client.funcs.handleVideo( video2.url, @@ -125,7 +116,7 @@ module.exports = { const videoResults = res.items.filter( (item) => item.type === "video" ); - spotify.searchTracks(`track:${searchString}`).then( + client.spotify.searchTracks(`track:${searchString}`).then( function (data) { client.funcs.handleVideo( videoResults[0].link, @@ -138,7 +129,7 @@ module.exports = { ); }, function (err) { - console.log("Something went wrong!", err); + console.log(err); } ); } diff --git a/src/commands/previous.js b/src/commands/previous.js index e8680087..d2d5a893 100644 --- a/src/commands/previous.js +++ b/src/commands/previous.js @@ -5,7 +5,7 @@ module.exports = { description: 'Play the previous song.', onlyDev: false, permission: 'MANAGE_MESSAGES', - category: 'music', + category: 'music control', async execute(msg, args, client, Discord, command) { const queue = client.queue.get(msg.guild.id) if (client.funcs.check(client, msg, command)) { diff --git a/src/commands/queue.js b/src/commands/queue.js index 74a571b7..d69a2209 100644 --- a/src/commands/queue.js +++ b/src/commands/queue.js @@ -5,7 +5,7 @@ module.exports = { description: 'See the queue.', onlyDev: false, permission: 'none', - category: 'music', + category: 'info', async execute(msg, args, client, Discord, command) { const queue = client.queue.get(msg.guild.id); if (!queue) return msg.channel.send(client.messages.noServerQueue); diff --git a/src/commands/remove.js b/src/commands/remove.js index 2c4f574f..aab05386 100644 --- a/src/commands/remove.js +++ b/src/commands/remove.js @@ -5,7 +5,7 @@ module.exports = { description: "Remove a song from the queue", onlyDev: false, permission: "MANAGE_MESSAGES", - category: "music", + category: "music control", execute(msg, args, client, Discord, command) { const queue = client.queue.get(msg.guild.id); if (client.funcs.check(client, msg, command)) { diff --git a/src/commands/replay.js b/src/commands/replay.js index e3274ca8..33b85b0e 100644 --- a/src/commands/replay.js +++ b/src/commands/replay.js @@ -5,7 +5,7 @@ module.exports = { description: 'Replay the currently playing song.', onlyDev: false, permission: 'MANAGE_MESSAGES', - category: 'music', + category: 'play', async execute(msg, args, client, Discord, command) { const queue = client.queue.get(msg.guild.id); if (client.funcs.check(client, msg, command)) { diff --git a/src/commands/resume.js b/src/commands/resume.js index 58f39836..5b5d0da1 100644 --- a/src/commands/resume.js +++ b/src/commands/resume.js @@ -5,7 +5,7 @@ module.exports = { description: 'Resume the paused music.', onlyDev: false, permission: 'MANAGE_MESSAGES', - category: 'music', + category: 'music control', execute(msg, args, client, Discord, command) { const queue = client.queue.get(msg.guild.id); if (client.funcs.check(client, msg, command)) { diff --git a/src/commands/search.js b/src/commands/search.js index a8a2c6fa..10239806 100644 --- a/src/commands/search.js +++ b/src/commands/search.js @@ -1,5 +1,4 @@ const ytsr = require('ytsr'); -const SpotifyApi = require("spotify-web-api-node"); const he = require('he'); module.exports = { @@ -9,14 +8,8 @@ module.exports = { description: 'Search the top 10 queryes and choose one.', onlyDev: false, permission: 'none', - category: 'music', + category: 'play', async execute(msg, args, client, Discord, command) { - const spotify = new SpotifyApi({ - id: client.config.spotify_client_id, - secret: client.config.spotify_client_secret, - }); - spotify.setAccessToken(client.config.spotify_access_key); - const searchString = args.slice(1).join(" "); const queue = client.queue.get(msg.guild.id); const voiceChannel = msg.member.voice.channel; @@ -54,7 +47,7 @@ module.exports = { return msg.channel.send(client.messages.cancellingVideoSelection); } const videoIndex = parseInt(response.first().content) - 1; - spotify.searchTracks(`track:${videos[videoIndex].title}`) + client.spotify.searchTracks(`track:${videos[videoIndex].title}`) .then(function (data) { client.funcs.handleVideo( videoResults[0].link, diff --git a/src/commands/seek.js b/src/commands/seek.js index ee125784..323d8605 100644 --- a/src/commands/seek.js +++ b/src/commands/seek.js @@ -5,7 +5,7 @@ module.exports = { description: "Seek to a specific point in the currently playing song.", onlyDev: false, permission: "MANAGE_MESSAGES", - category: "music", + category: "music control", async execute(msg, args, client, Discord, command) { const queue = client.queue.get(msg.guild.id); if (client.funcs.check(client, msg, command)) { diff --git a/src/commands/shuffle.js b/src/commands/shuffle.js index c9502d82..8f943663 100644 --- a/src/commands/shuffle.js +++ b/src/commands/shuffle.js @@ -5,7 +5,7 @@ module.exports = { description: 'Shuffle the queue.', onlyDev: false, permission: 'MANAGE_MESSAGES', - category: 'music', + category: 'music control', execute(msg, args, client, Discord, command) { const queue = client.queue.get(msg.guild.id); if (client.funcs.check(client, msg, command)) { diff --git a/src/commands/skip.js b/src/commands/skip.js index 90d82b2c..bfe678c1 100644 --- a/src/commands/skip.js +++ b/src/commands/skip.js @@ -5,7 +5,7 @@ module.exports = { description: "Skip the currently playing song.", onlyDev: false, permission: "MANAGE_MESSAGES", - category: "music", + category: "music control", execute(msg, args, client, Discord, command) { const queue = client.queue.get(msg.guild.id); const permissions = msg.channel.permissionsFor(msg.author); diff --git a/src/commands/skipto.js b/src/commands/skipto.js index 26634870..88d95034 100644 --- a/src/commands/skipto.js +++ b/src/commands/skipto.js @@ -5,7 +5,7 @@ module.exports = { description: "Skip to a point in the queue", onlyDev: false, permission: "MANAGE_MESSAGES", - category: "music", + category: "music control", async execute(msg, args, client, Discord, command) { const queue = client.queue.get(msg.guild.id); if (client.funcs.check(client, msg, command)) { diff --git a/src/commands/soundcloud.js b/src/commands/soundcloud.js index 6e96f8c3..175f7ec0 100644 --- a/src/commands/soundcloud.js +++ b/src/commands/soundcloud.js @@ -5,7 +5,7 @@ module.exports = { description: "", onlyDev: true, permission: "dev", - category: "music", + category: "play", async execute(msg, args, client, Discord, prefix, command) { if (!args[1]) return msg.channel.send(client.messages.noQuery); const SoundCloud = require("soundcloud-api-client"); diff --git a/src/commands/stop.js b/src/commands/stop.js index 83861dea..4bebfd70 100644 --- a/src/commands/stop.js +++ b/src/commands/stop.js @@ -5,7 +5,7 @@ module.exports = { usage: '', onlyDev: false, permission: 'MANAGE_CHANNELS', - category: 'music', + category: 'music control', execute(msg, args, client, Discord, command) { const queue = client.queue.get(msg.guild.id); if (client.funcs.check(client, msg, command)) { diff --git a/src/commands/volume.js b/src/commands/volume.js index 8ac9dd6f..e4b5cdf2 100644 --- a/src/commands/volume.js +++ b/src/commands/volume.js @@ -6,7 +6,7 @@ module.exports = { cooldown: 5, onlyDev: false, permission: 'MANAGE_MESSAGES', - category: 'music', + category: 'music control', execute(msg, args, client, Discord, command) { const queue = client.queue.get(msg.guild.id); if (!args[1] && queue) return msg.channel.send(`${client.messages.currentVolume}**${queue.volume}**`); diff --git a/src/events/dispatcherEvents/finish.js b/src/events/dispatcherEvents/finish.js index cf42ac62..b97d5cb1 100644 --- a/src/events/dispatcherEvents/finish.js +++ b/src/events/dispatcherEvents/finish.js @@ -48,7 +48,7 @@ function findSimilar(client, queue, prevSongs, guild) { limit: 10, lastfmAPIKey: client.config.lastfm_api_key, lastfmAPISecret: client.config.lastfm_secret, - youtubeAPIKey: client.config.api_key, + youtubeAPIKey: client.config.api_keys[(client.shard.ids / 2).toFixed()], }, async function (err, songs) { if (err) { diff --git a/src/struct/client.js b/src/struct/client.js index d3c9372e..d4b6f1cd 100644 --- a/src/struct/client.js +++ b/src/struct/client.js @@ -7,6 +7,9 @@ const admin = require("firebase-admin"); const serviceAccount = require("./config/serviceAccount.json"); const fs = require("fs"); const path = require("path"); +const SpotifyApi = require("spotify-web-api-node"); +const YouTube = require("simple-youtube-api"); +const config = require("./config/config"); const myIntents = new Intents(); myIntents.add( @@ -31,9 +34,14 @@ module.exports = class extends Client { this.commands = new Collection(); this.settingCmd = new Collection(); this.queue = new Map(); + this.spotify = new SpotifyApi({ + id: config.spotify_client_id, + secret: config.spotify_client_secret, + }); + this.youtube = new YouTube(config.api_keys[(this.shard.ids / 2).toFixed()]); + this.config = config; this.funcs = {}; this.dispatcher = {}; - this.config = require("./config/config.js"); this.messages = require("./config/messages.js"); this.db = admin.firestore(); this.db.FieldValue = require("firebase-admin").firestore.FieldValue; diff --git a/src/struct/config/config.js b/src/struct/config/config.js index 63708c01..3545b93f 100644 --- a/src/struct/config/config.js +++ b/src/struct/config/config.js @@ -6,6 +6,7 @@ module.exports = { dblKey: process.env.DBLKEY, bodKey: process.env.BODKEY, api_key: process.env.GOOGLE_API_KEY, + api_keys: [process.env.GOOGLE_API_KEY1, process.env.GOOGLE_API_KEY2, process.env.GOOGLE_API_KEY3, process.env.GOOGLE_API_KEY4, process.env.GOOGLE_API_KEY5, process.env.GENIUS_API_KEY6], genius_api_key: process.env.GENIUS_API_KEY, soundCloud_api_key: process.env.SOUNDCLOUD_API_KEY, spotify_access_key: process.env.SPOTIFY_ACCESS_KEY, @@ -99,4 +100,4 @@ module.exports.emojis = { stop: "<:stop:674685626108477519> ", stopWatch: ":stopwatch: ", volumeHigh: "<:volumehigh:674685637626167307> ", -}; +}; \ No newline at end of file diff --git a/src/struct/funcs/getSpotifyKey.js b/src/struct/funcs/getSpotifyKey.js index 4c7e6493..9e17f4bf 100644 --- a/src/struct/funcs/getSpotifyKey.js +++ b/src/struct/funcs/getSpotifyKey.js @@ -1,4 +1,5 @@ module.exports = async function (client) { + const request = require("request"); const refresh_token = client.config.spotify_refresh_token; @@ -17,9 +18,11 @@ module.exports = async function (client) { request.post(authOptions, function (error, response, body) { if (!error && response.statusCode === 200) { + client.spotify.setAccessToken(body.access_token); client.config.spotify_access_key = body.access_token + console.log("- Spotify access token set -"); } else { - console.log("An error occured!") + console.log("An error occured!"); } }); }; \ No newline at end of file