From 1beb0fa86a65897b75cfe510d54b83bf71bf5622 Mon Sep 17 00:00:00 2001 From: MatteZ02 <47610069+MatteZ02@users.noreply.github.com> Date: Wed, 8 Apr 2020 20:48:57 +0300 Subject: [PATCH] nigthCore added --- src/commands/nigthcore.ts | 26 +++ src/struct/config/messages.ts | 310 ++++++++++++++++++------------- src/struct/config/queueConfig.ts | 33 ++-- src/struct/funcs/play.ts | 105 ++++++----- 4 files changed, 290 insertions(+), 184 deletions(-) create mode 100644 src/commands/nigthcore.ts diff --git a/src/commands/nigthcore.ts b/src/commands/nigthcore.ts new file mode 100644 index 00000000..ede9a9de --- /dev/null +++ b/src/commands/nigthcore.ts @@ -0,0 +1,26 @@ +module.exports = { + name: "nigthcore", + alias: "nc", + usage: "", + description: "Change nigthcore on/off", + onlyDev: false, + permission: "MANAGE_MESSAGES", + category: "music", + async execute(msg, args, client, Discord, prefix, command) { + const queue = client.queue.get(msg.guild.id); + if (!args[1] && queue) + return msg.channel.send( + `${client.messages.currentNigthCore}**${queue.nigthCore}**` + ); + if (client.funcs.check(client, msg, command)) { + if (args[1] === "true") { + queue.nigthCore = true; + } else if (args[1] === "false") { + queue.nigthCore = false; + } + let message; + message = client.messages.nigthCoreApplied.replace("%BOOLEAN%", args[1]); + return msg.channel.send(message); + } + }, +}; diff --git a/src/struct/config/messages.ts b/src/struct/config/messages.ts index 181649c8..8ff746b1 100644 --- a/src/struct/config/messages.ts +++ b/src/struct/config/messages.ts @@ -1,128 +1,188 @@ -const emojis = require('./emojis.ts'); +const emojis = require("./emojis.ts"); module.exports = { - alreadyPaused: emojis.redx + "The music is already paused!", - alreadyVoted: emojis.redx + "You have already voted to skip!", - announceSongs: emojis.megaPhone + "Current setting:", - announceSongsFalse: emojis.green_check_mark + "announcesongs now set to `false`!", - announceSongsTrue: emojis.green_check_mark + "announcesongs now set to `true`!", - bassApplied: emojis.volumeHigh + "The bass level **%BASS%** will be applied when the next song starts playing!", - bassFalse: emojis.green_check_mark + "Bass is now false!", - bassLevel: emojis.green_check_mark + "Bass level is now", - boolean: emojis.redx + "Please define a boolean! (true/false)", - cancellingVideoSelection: emojis.redx + "Cancelling video selection", - cantSkipToCurrent: emojis.redx + "You can't skip to the song currently playing!", - channelFull: emojis.redx + "Your voice channel is full!", - cmdUsesFooter: "These statistics are from the current uptime.", - cmdUsesTitle: "Musix Command Usage During Current Uptime", - correctUsage: emojis.redx + "correct usage: ", - currentBass: emojis.loudSound + "The current bass is: ", - currentDefaultBass: emojis.speaker + "Currect default bass level: ", - currentDefaultVolume: emojis.speaker + "Current default volume is:", - currentPrefix: "Current prefix:", - currentVolume: emojis.loudSound + "The current volume is: ", - dbSaved: emojis.green_check_mark + "DB Saved!", - defaultVolumeMax: emojis.redx + "The default volume must be below `100` for quality and safety resons.", - defaultVolumeNumber: emojis.redx + "I'm sorry, But the default volume needs to be a valid __number__.", - defaultVolumeSet: emojis.green_check_mark + "Default volume set to:", - devMode: emojis.redx + "Dev mode has been turned on! Commands are only available to developer(s)!", - dispatcherError: "Error with the dispatcher: ", - djFalse: emojis.green_check_mark + "`DJ` now set to `false`", - djRoleCreated: emojis.green_check_mark + "I did not find a role `DJ` so i have created one for you!", - djRoleFound: emojis.green_check_mark + "I found a `DJ` role from this guild! This role is now the DJ role.", - error: emojis.redx + "An error occured!", - errorConnecting: "Error with connecting to voice channel: ", - errorDetected: "Error detected: ", - errorDispatcher: emojis.redx + "An error has occured while playing music! The queue has been deleted.", - errorExe: emojis.redx + "there was an error trying to execute that command!", - errorExeOpt: emojis.redx + "there was an error trying to execute that option!", - evalTitle: "Evaluation Command", - helpCmdFooter: "Command Alias:", - helpFooter: "\"%PREFIX%help \" to see more information about a command.", - helpTitle: "help", - inviteTitle: "Invite Musix to your Discord server!", - joined: emojis.green_check_mark + "Joined", - joinSupport: "Join the musix support server: ", - loadingSongs: emojis.loading + "Loading song(s)", - looping: emojis.repeat + "Looping the queue now!", - loopingSong: emojis.repeatSong + "Looping **%TITLE%** now!", - maxBass: emojis.redx + "The max bass is `100`!", - maxVolume: emojis.redx + "The max volume is `100`!", - noDj: emojis.redx + "You need the `DJ` role to use this command!", - noLooping: emojis.repeat + "No longer looping the queue!", - noLoopingSong: emojis.repeatSong + "No longer looping the song!", - noPerms: emojis.redx + `You need the %PERMS% permission to use this command!`, - noPermsConnect: emojis.redx + "I cannot connect to your voice channel, make sure I have the proper permissions!", - noPermsEmbed: emojis.redx + "I cannot send embeds (Embed links), make sure I have the proper permissions!", - noPermsManageRoles: emojis.redx + "I cannot create roles (Manage roles), make sure I have the proper permissions! I will need this permission to create a `DJ` role since i did not find one!", - noPermsManageSettings: emojis.redx + "You need the `MANAGE_SERVER` permission to change the settings!", - noPermsSpeak: emojis.redx + "I cannot speak in your voice channel, make sure I have the proper permissions!", - noPermsUseExternalEmojis: emojis.redx + "I cannot use external emojis, make sure I have the proper permissions!", - noQuery: emojis.redx + "you need to use a link or search for a song!", - noResults: emojis.redx + "I could not obtain any search results!", - noServerQueue: emojis.redx + "There is nothing playing!", - noSongs: emojis.redx + "That song does not exist!", - nowPlayingDesc: emojis.notes + "**Now playing:**", - notAllowed: emojis.redx + "You are not allowed to do that!", - notEnoughVotes: emojis.redx + "Not enough votes!", - notPaused: emojis.redx + "The music in not paused!", - noVoiceChannel: emojis.redx + "I'm sorry but you need to be in a voice channel to play music!", - nowPlaying: "__Now playing__", - paused: emojis.pause + "Paused the music!", - permission: "🔒 Permission requirement:", - permissionsFalse: emojis.redx + "That value is already `false`!", - permissionsSetFalse: emojis.green_check_mark + "Permissions requirement now set to: `false`", - permissionsSetTrue: emojis.green_check_mark + "Permissions requirement now set to: `true`", - permissionsTrue: emojis.redx + "That value is already `true`!", - pinging: emojis.loading + "Pinging...", - playlistAdded: emojis.green_check_mark + "Playlist: **%TITLE%** has been added to the queue!", - positiveBass: emojis.redx + "The bass needs to be a positive number!", - positiveVolume: emojis.redx + "The volume needs to be a positive number!", - prefixHere: "My prefix here is: ", - prefixMaxLength: "The prefix must be shorter or equal to 5 letters!", - prefixSet: emojis.green_check_mark + "New prefix set to:", - provideANumber: "Please provide a number ranging from 1-10 to select one of the search results.", - provideASong: emojis.redx + "Please provide a song position in queue for me to remove!", - queueDeleted: "Queue deleted!", - queueDesc: "**Now playing:** %SONG%\n:arrow_down: Next in queue :arrow_down:", - queueFooter: "songs in the queue!", - queueLength: emojis.redx + "There are only %SONGS% amount of songs in the queue!", - queueTitle: "__Song queue__", - quotaReached: emojis.redx + "Quota reached please try again after midnight Pacific Time (PT)!", - reloaded: "All files reloaded!", - removed: emojis.garbage + "removed `%SONG%` from the queue!", - reset: emojis.green_check_mark + "Reset __all__ guild settings!", - restart: "restarting all shards...", - resumed: emojis.resume + "Resumed the music!", - seekingPointPositive: emojis.redx + "The seeking point needs to be a positive number!", - seekMax: emojis.redx + "The lenght of this song is %LENGTH% seconds! You can't seek further than that!", - settingsAnnounceSongs: "announcesongs", - settingsAnnounceSongsDesc: "Whether to announce songs that start playing or not.", - settingsBass: "bass", - settingsBassDesc: "Change the default bass level.", - settingsFooter: "how to use: %PREFIX%settings  ", - settingsPermissions: "permissions", - settingsPermissionsDesc: "Change whether to require permissions to use eg `skip, stop, pause, loop, etc...`", - settingsPrefix: "prefix", - settingsPrefixDesc: "Change the guild specific prefix. (string)", - settingsSetDj: "setdj", - settingsSetDjDesc: "Set a DJ role. This will allow chosen users to freely use all Musix commands. This will automatically set the `permissions` settings to true in order for the `DJ` role to have effect!", - settingsTitle: "Guild settings for Musix", - settingsVolume: "volume", - settingsVolumeDesc: "Change the default volume that the bot will start playing at. (number)", - setVolume: emojis.volumeHigh + "I set the volume to: ", - shuffled: emojis.shuffle + "Queue suffled!", - skipped: emojis.skip + "Skipped the song!", - songAdded: emojis.green_check_mark + "**%TITLE%** has been added to the queue!", - songBlockedWMG: emojis.redx + "This song had been blocked by WMG (Warner Music Groud).\n<:skip:674685614221688832> Skipped to next song.", - songSelection: "__Song Selection__", - startPlaying: emojis.notes + "Start playing: ", - statusField1: emojis.signal + "Ping", - statusField2: "Latency", - statusField3: emojis.stopWatch + "Uptime", - statusField4: "Shard: ", - statusTitle: "Status for Musix", - stop: emojis.stop + "Stopped the music!", - validNumber: emojis.redx + "I'm sorry, But you need to enter a valid __number__.", - wrongVoiceChannel: emojis.redx + "I'm sorry but you need to be in the same voice channel as Musix to use this command!", + alreadyPaused: emojis.redx + "The music is already paused!", + alreadyVoted: emojis.redx + "You have already voted to skip!", + announceSongs: emojis.megaPhone + "Current setting:", + announceSongsFalse: + emojis.green_check_mark + "announcesongs now set to `false`!", + announceSongsTrue: + emojis.green_check_mark + "announcesongs now set to `true`!", + bassApplied: + emojis.volumeHigh + + "The bass level **%BASS%** will be applied when the next song starts playing!", + bassFalse: emojis.green_check_mark + "Bass is now false!", + bassLevel: emojis.green_check_mark + "Bass level is now", + boolean: emojis.redx + "Please define a boolean! (true/false)", + cancellingVideoSelection: emojis.redx + "Cancelling video selection", + cantSkipToCurrent: + emojis.redx + "You can't skip to the song currently playing!", + channelFull: emojis.redx + "Your voice channel is full!", + cmdUsesFooter: "These statistics are from the current uptime.", + cmdUsesTitle: "Musix Command Usage During Current Uptime", + correctUsage: emojis.redx + "correct usage: ", + currentBass: emojis.loudSound + "The current bass is: ", + currentDefaultBass: emojis.speaker + "Currect default bass level: ", + currentDefaultVolume: emojis.speaker + "Current default volume is:", + currentNigthCore: emojis.speaker + "Currect Nigthcore setting: ", + currentPrefix: "Current prefix:", + currentVolume: emojis.loudSound + "The current volume is: ", + dbSaved: emojis.green_check_mark + "DB Saved!", + defaultVolumeMax: + emojis.redx + + "The default volume must be below `100` for quality and safety resons.", + defaultVolumeNumber: + emojis.redx + + "I'm sorry, But the default volume needs to be a valid __number__.", + defaultVolumeSet: emojis.green_check_mark + "Default volume set to:", + devMode: + emojis.redx + + "Dev mode has been turned on! Commands are only available to developer(s)!", + dispatcherError: "Error with the dispatcher: ", + djFalse: emojis.green_check_mark + "`DJ` now set to `false`", + djRoleCreated: + emojis.green_check_mark + + "I did not find a role `DJ` so i have created one for you!", + djRoleFound: + emojis.green_check_mark + + "I found a `DJ` role from this guild! This role is now the DJ role.", + error: emojis.redx + "An error occured!", + errorConnecting: "Error with connecting to voice channel: ", + errorDetected: "Error detected: ", + errorDispatcher: + emojis.redx + + "An error has occured while playing music! The queue has been deleted.", + errorExe: emojis.redx + "there was an error trying to execute that command!", + errorExeOpt: + emojis.redx + "there was an error trying to execute that option!", + evalTitle: "Evaluation Command", + helpCmdFooter: "Command Alias:", + helpFooter: + '"%PREFIX%help " to see more information about a command.', + helpTitle: "help", + inviteTitle: "Invite Musix to your Discord server!", + joined: emojis.green_check_mark + "Joined", + joinSupport: "Join the musix support server: ", + loadingSongs: emojis.loading + "Loading song(s)", + looping: emojis.repeat + "Looping the queue now!", + loopingSong: emojis.repeatSong + "Looping **%TITLE%** now!", + maxBass: emojis.redx + "The max bass is `100`!", + maxVolume: emojis.redx + "The max volume is `100`!", + nigthCoreApplied: + emojis.green_check_mark + + "NigthCore is now **%BOOLEAN%** this will be applied when the next song starts playing!", + noDj: emojis.redx + "You need the `DJ` role to use this command!", + noLooping: emojis.repeat + "No longer looping the queue!", + noLoopingSong: emojis.repeatSong + "No longer looping the song!", + noPerms: emojis.redx + `You need the %PERMS% permission to use this command!`, + noPermsConnect: + emojis.redx + + "I cannot connect to your voice channel, make sure I have the proper permissions!", + noPermsEmbed: + emojis.redx + + "I cannot send embeds (Embed links), make sure I have the proper permissions!", + noPermsManageRoles: + emojis.redx + + "I cannot create roles (Manage roles), make sure I have the proper permissions! I will need this permission to create a `DJ` role since i did not find one!", + noPermsManageSettings: + emojis.redx + + "You need the `MANAGE_SERVER` permission to change the settings!", + noPermsSpeak: + emojis.redx + + "I cannot speak in your voice channel, make sure I have the proper permissions!", + noPermsUseExternalEmojis: + emojis.redx + + "I cannot use external emojis, make sure I have the proper permissions!", + noQuery: emojis.redx + "you need to use a link or search for a song!", + noResults: emojis.redx + "I could not obtain any search results!", + noServerQueue: emojis.redx + "There is nothing playing!", + noSongs: emojis.redx + "That song does not exist!", + nowPlayingDesc: emojis.notes + "**Now playing:**", + notAllowed: emojis.redx + "You are not allowed to do that!", + notEnoughVotes: emojis.redx + "Not enough votes!", + notPaused: emojis.redx + "The music in not paused!", + noVoiceChannel: + emojis.redx + + "I'm sorry but you need to be in a voice channel to play music!", + nowPlaying: "__Now playing__", + paused: emojis.pause + "Paused the music!", + permission: "🔒 Permission requirement:", + permissionsFalse: emojis.redx + "That value is already `false`!", + permissionsSetFalse: + emojis.green_check_mark + "Permissions requirement now set to: `false`", + permissionsSetTrue: + emojis.green_check_mark + "Permissions requirement now set to: `true`", + permissionsTrue: emojis.redx + "That value is already `true`!", + pinging: emojis.loading + "Pinging...", + playlistAdded: + emojis.green_check_mark + + "Playlist: **%TITLE%** has been added to the queue!", + positiveBass: emojis.redx + "The bass needs to be a positive number!", + positiveVolume: emojis.redx + "The volume needs to be a positive number!", + prefixHere: "My prefix here is: ", + prefixMaxLength: "The prefix must be shorter or equal to 5 letters!", + prefixSet: emojis.green_check_mark + "New prefix set to:", + provideANumber: + "Please provide a number ranging from 1-10 to select one of the search results.", + provideASong: + emojis.redx + "Please provide a song position in queue for me to remove!", + queueDeleted: "Queue deleted!", + queueDesc: + "**Now playing:** %SONG%\n:arrow_down: Next in queue :arrow_down:", + queueFooter: "songs in the queue!", + queueLength: + emojis.redx + "There are only %SONGS% amount of songs in the queue!", + queueTitle: "__Song queue__", + quotaReached: + emojis.redx + + "Quota reached please try again after midnight Pacific Time (PT)!", + reloaded: "All files reloaded!", + removed: emojis.garbage + "removed `%SONG%` from the queue!", + reset: emojis.green_check_mark + "Reset __all__ guild settings!", + restart: "restarting all shards...", + resumed: emojis.resume + "Resumed the music!", + seekingPointPositive: + emojis.redx + "The seeking point needs to be a positive number!", + seekMax: + emojis.redx + + "The lenght of this song is %LENGTH% seconds! You can't seek further than that!", + settingsAnnounceSongs: "announcesongs", + settingsAnnounceSongsDesc: + "Whether to announce songs that start playing or not.", + settingsBass: "bass", + settingsBassDesc: "Change the default bass level.", + settingsFooter: "how to use: %PREFIX%settings  ", + settingsPermissions: "permissions", + settingsPermissionsDesc: + "Change whether to require permissions to use eg `skip, stop, pause, loop, etc...`", + settingsPrefix: "prefix", + settingsPrefixDesc: "Change the guild specific prefix. (string)", + settingsSetDj: "setdj", + settingsSetDjDesc: + "Set a DJ role. This will allow chosen users to freely use all Musix commands. This will automatically set the `permissions` settings to true in order for the `DJ` role to have effect!", + settingsTitle: "Guild settings for Musix", + settingsVolume: "volume", + settingsVolumeDesc: + "Change the default volume that the bot will start playing at. (number)", + setVolume: emojis.volumeHigh + "I set the volume to: ", + shuffled: emojis.shuffle + "Queue suffled!", + skipped: emojis.skip + "Skipped the song!", + songAdded: + emojis.green_check_mark + "**%TITLE%** has been added to the queue!", + songBlockedWMG: + emojis.redx + + "This song had been blocked by WMG (Warner Music Groud).\n<:skip:674685614221688832> Skipped to next song.", + songSelection: "__Song Selection__", + startPlaying: emojis.notes + "Start playing: ", + statusField1: emojis.signal + "Ping", + statusField2: "Latency", + statusField3: emojis.stopWatch + "Uptime", + statusField4: "Shard: ", + statusTitle: "Status for Musix", + stop: emojis.stop + "Stopped the music!", + validNumber: + emojis.redx + "I'm sorry, But you need to enter a valid __number__.", + wrongVoiceChannel: + emojis.redx + + "I'm sorry but you need to be in the same voice channel as Musix to use this command!", }; diff --git a/src/struct/config/queueConfig.ts b/src/struct/config/queueConfig.ts index 21a54e43..976bdd5f 100644 --- a/src/struct/config/queueConfig.ts +++ b/src/struct/config/queueConfig.ts @@ -1,17 +1,18 @@ module.exports = { - textChannel: null, - voiceChannel: null, - connection: null, - songs: [], - volume: null, - bass: null, - playing: false, - paused: false, - looping: false, - songLooping: false, - votes: 0, - voters: [], - votesNeeded: null, - time: 0, - endReason: null, -} \ No newline at end of file + textChannel: null, + voiceChannel: null, + connection: null, + songs: [], + volume: null, + bass: null, + nigthCore: false, + playing: false, + paused: false, + looping: false, + songLooping: false, + votes: 0, + voters: [], + votesNeeded: null, + time: 0, + endReason: null, +}; diff --git a/src/struct/funcs/play.ts b/src/struct/funcs/play.ts index 5b62bcf5..b3aa5030 100644 --- a/src/struct/funcs/play.ts +++ b/src/struct/funcs/play.ts @@ -1,48 +1,67 @@ module.exports = async function (guild, song, client, seek, play) { - const Discord = require('discord.js'); - const ytdl = require('ytdl-core'); - const streamConfig = require("../config/streamConfig.ts"); - const getThumb = require('video-thumbnail-url'); - const prism = require('prism-media'); + const Discord = require("discord.js"); + const ytdl = require("ytdl-core"); + const streamConfig = require("../config/streamConfig.ts"); + const getThumb = require("video-thumbnail-url"); + const prism = require("prism-media"); - const queue = client.queue.get(guild.id); - if (!song) { - queue.voiceChannel.leave(); - client.queue.delete(guild.id); - return; - } + const queue = client.queue.get(guild.id); + if (!song) { + queue.voiceChannel.leave(); + client.queue.delete(guild.id); + return; + } - streamConfig.ytdlOptions.begin = seek; + streamConfig.ytdlOptions.begin = seek; - const ffmpegArgs = [ - "-analyzeduration", "0", - "-loglevel", "0", - "-f", "s16le", - "-ar", "48000", - "-ac", "2", - "-af", `bass=g=${queue.bass}`, - ]; - const transcoder = new prism.FFmpeg({ args: ffmpegArgs }); + const ffmpegArgs = [ + "-analyzeduration", + "0", + "-loglevel", + "0", + "-f", + "s16le", + "-ar", + "48000", + "-ac", + "2", + "-af", + `bass=g=${queue.bass}`, + ]; + if (queue.nigthCore) { + ffmpegArgs.push("-af"); + ffmpegArgs.push("asetrate=52920"); + } - const dispatcher = queue.connection - .play(await ytdl(song.url, streamConfig.ytdlOptions).pipe(transcoder), streamConfig.options).on("finish", () => { - client.dispatcher.finish(client, queue.endReason, guild); - }).on('start', () => { - dispatcher.player.streamingData.pausedTime = 0; - }).on('error', error => { - client.dispatcher.error(client, error, guild); - }); - dispatcher.setVolume(queue.volume / 10); - if (client.global.db.guilds[guild.id].startPlaying || play) { - const data = await Promise.resolve(ytdl.getInfo(queue.songs[0].url)); - const songtime = (data.length_seconds * 1000).toFixed(0); - const thumbnail = getThumb(queue.songs[0].url); - const embed = new Discord.MessageEmbed() - .setTitle(`${client.messages.startPlaying}**${song.title}**`) - .setDescription(`Song duration: \`${client.funcs.msToTime(songtime, "hh:mm:ss")}\``) - .setThumbnail(thumbnail._rejectionHandler0) - .setColor(client.config.embedColor) - queue.textChannel.send(embed); - } - queue.playing = true; -} + const transcoder = new prism.FFmpeg({ args: ffmpegArgs }); + + const dispatcher = queue.connection + .play( + await ytdl(song.url, streamConfig.ytdlOptions).pipe(transcoder), + streamConfig.options + ) + .on("finish", () => { + client.dispatcher.finish(client, queue.endReason, guild); + }) + .on("start", () => { + dispatcher.player.streamingData.pausedTime = 0; + }) + .on("error", (error) => { + client.dispatcher.error(client, error, guild); + }); + dispatcher.setVolume(queue.volume / 10); + if (client.global.db.guilds[guild.id].startPlaying || play) { + const data = await Promise.resolve(ytdl.getInfo(queue.songs[0].url)); + const songtime = (data.length_seconds * 1000).toFixed(0); + const thumbnail = getThumb(queue.songs[0].url); + const embed = new Discord.MessageEmbed() + .setTitle(`${client.messages.startPlaying}**${song.title}**`) + .setDescription( + `Song duration: \`${client.funcs.msToTime(songtime, "hh:mm:ss")}\`` + ) + .setThumbnail(thumbnail._rejectionHandler0) + .setColor(client.config.embedColor); + queue.textChannel.send(embed); + } + queue.playing = true; +};