From 011e221748386eb9089892d576804a32d1fc2cb3 Mon Sep 17 00:00:00 2001 From: MatteZ02 <47610069+MatteZ02@users.noreply.github.com> Date: Sun, 22 Mar 2020 17:10:46 +0200 Subject: [PATCH] removed some unnecessary variables and general clean up --- commands/bug.js | 8 ++++---- commands/help.js | 12 ++++++------ commands/invite.js | 2 +- commands/list.js | 4 ++-- commands/nowplaying.js | 9 ++++----- commands/play.js | 18 +++++------------- commands/stop.js | 2 +- commands/volume.js | 14 +++++++------- config.js | 3 +-- events/msg.js | 4 ++-- events/ready.js | 4 ++-- events/voiceStateUpdate.js | 6 ------ struct/check.js | 4 ++-- struct/client.js | 1 - struct/emojis.js | 10 +++++----- 15 files changed, 42 insertions(+), 59 deletions(-) diff --git a/commands/bug.js b/commands/bug.js index 7ee7a9e..15ea43f 100644 --- a/commands/bug.js +++ b/commands/bug.js @@ -5,13 +5,13 @@ module.exports = { description: 'Report a bug', permission: 'none', category: 'info', - async execute(msg, args, client, Discord, prefix) { + async execute(msg, args, client, Discord, command) { let message = {}; - + message.bugTitle = client.messages.bugTitle.replace("%client.user.username%", client.user.username); message.bugDescription = client.messages.bugDescription.replace("%client.developers%", client.developers); message.bugDescription = message.bugDescription.replace("%client.config.supportGuild%", client.config.supportGuild); - + const embed = new Discord.MessageEmbed() .setTitle(message.bugTitle) .setThumbnail("https://cdn.discordapp.com/emojis/686296221433725076.png") @@ -19,6 +19,6 @@ module.exports = { .setDescription(message.bugDescription) .setFooter('EximiaBots by Warén Media', 'https://cdn.discordapp.com/emojis/687022937978568760.png'); msg.channel.send(embed); - + }, }; \ No newline at end of file diff --git a/commands/help.js b/commands/help.js index d56e7ef..da68045 100644 --- a/commands/help.js +++ b/commands/help.js @@ -5,19 +5,19 @@ module.exports = { description: 'See the help for RadioX.', permission: 'none', category: 'info', - execute(msg, args, client, Discord, prefix, command) { + execute(msg, args, client, Discord, command) { let message = {}; - + if (args[1]) { if (!client.commands.has(args[1]) || (client.commands.has(args[1]) && client.commands.get(args[1]).omitFromHelp === true)) return msg.channel.send('That command does not exist'); const command = client.commands.get(args[1]); - + message.helpCommandTitle = client.messages.helpCommandTitle.replace("%client.config.prefix%", client.config.prefix); message.helpCommandTitle = message.helpCommandTitle.replace("%command.name%", command.name); message.helpCommandTitle = message.helpCommandTitle.replace("%command.usage%", command.usage); message.helpCommandDescription = client.messages.helpCommandDescription.replace("%command.description%", command.description); message.helpCommandDescription = message.helpCommandDescription.replace("%command.alias%", command.alias); - + const embed = new Discord.MessageEmbed() .setTitle(message.helpCommandTitle) .setThumbnail("https://cdn.discordapp.com/emojis/686296221433725076.png") @@ -34,11 +34,11 @@ module.exports = { for (let i = 0; i < categories.length; i++) { commands += `**» ${categories[i].toUpperCase()}**\n${client.commands.filter(x => x.category === categories[i] && !x.omitFromHelp).map(x => `\`${x.name}\``).join(', ')}\n`; } - + message.helpTitle = client.messages.helpTitle.replace("%client.user.username%", client.user.username); message.helpDescription = client.messages.helpDescription.replace("%commands%", commands); message.helpDescription = message.helpDescription.replace("%client.config.prefix%", client.config.prefix); - + const embed = new Discord.MessageEmbed() .setTitle(message.helpTitle) .setThumbnail("https://cdn.discordapp.com/emojis/686296221433725076.png") diff --git a/commands/invite.js b/commands/invite.js index 180e928..df8fb02 100644 --- a/commands/invite.js +++ b/commands/invite.js @@ -5,7 +5,7 @@ module.exports = { description: 'Invite RadioX.', permission: 'none', category: 'info', - execute(msg, args, client, Discord, prefix) { + execute(msg, args, client, Discord, command) { let message = {}; message.inviteTitle = client.messages.inviteTitle.replace("%client.user.username%", client.user.username); const embed = new Discord.MessageEmbed() diff --git a/commands/list.js b/commands/list.js index aefb27d..0b22191 100644 --- a/commands/list.js +++ b/commands/list.js @@ -5,13 +5,13 @@ module.exports = { description: 'List radio stations.', permission: 'none', category: 'info', - execute(msg, args, client, Discord, prefix) { + execute(msg, args, client, Discord, command) { let stations = `${client.stations.map(s => `**#** ${s.name}`).join('\n')}` const hashs = stations.split('**#**').length; for (let i = 0; i < hashs; i++) { stations = stations.replace('**#**', `**${i + 1}**`); } - + const embed = new Discord.MessageEmbed() .setTitle(client.messages.listTitle) .setThumbnail("https://cdn.discordapp.com/emojis/" + client.messageEmojis["list"].replace(/[^0-9]+/g, '')) diff --git a/commands/nowplaying.js b/commands/nowplaying.js index b6c5c2a..edf7657 100644 --- a/commands/nowplaying.js +++ b/commands/nowplaying.js @@ -5,17 +5,16 @@ module.exports = { description: 'See the currently playing song position and length.', permission: 'none', category: 'music', - async execute(msg, args, client, Discord, prefix) { + async execute(msg, args, client, Discord, command) { let message = {}; const radio = client.radio.get(msg.guild.id); - if (!radio || !radio.playing) return msg.channel.send('There is nothing playing.'); - radio.time = radio.connection.dispatcher.streamTime; - const completed = (radio.time.toFixed(0)); + if (!radio) return msg.channel.send('There is nothing playing.'); + const completed = (radio.connection.dispatcher.streamTime.toFixed(0)); message.nowplayingDescription = client.messages.nowplayingDescription.replace("%radio.station.name%", radio.station.name); message.nowplayingDescription = message.nowplayingDescription.replace("%radio.station.owner%", radio.station.owner); message.nowplayingDescription = message.nowplayingDescription.replace("%msToTime(completed, \"hh:mm:ss\")%", msToTime(completed, "hh:mm:ss")); - + const embed = new Discord.MessageEmbed() .setTitle(client.messages.nowplayingTitle) .setThumbnail("https://cdn.discordapp.com/emojis/" + client.messageEmojis["play"].replace(/[^0-9]+/g, '')) diff --git a/commands/play.js b/commands/play.js index ef88f70..313edba 100644 --- a/commands/play.js +++ b/commands/play.js @@ -5,7 +5,7 @@ module.exports = { description: 'Play some music.', permission: 'none', category: 'music', - async execute(msg, args, client, Discord, prefix) { + async execute(msg, args, client, Discord, command) { let url = args[1] ? args[1].replace(/<(.+)>/g, "$1") : ""; const radio = client.radio.get(msg.guild.id); const voiceChannel = msg.member.voice.channel; @@ -44,7 +44,7 @@ module.exports = { if (radio) { radio.connection.dispatcher.destroy(); radio.station = station; - radio.textChannel = msg.channel; + radio.textChannel = msg.channel; play(msg.guild, client, url); return; } @@ -53,10 +53,8 @@ module.exports = { textChannel: msg.channel, voiceChannel: voiceChannel, connection: null, - playing: false, station: station, - volume: client.config.volume, - time: null + volume: 5, }; client.radio.set(msg.guild.id, construct); @@ -71,7 +69,7 @@ module.exports = { } }; function play(guild, client, url) { - let message = {}; + let message = {}; const radio = client.radio.get(guild.id); const dispatcher = radio.connection @@ -82,10 +80,6 @@ function play(guild, client, url) { return; }); - dispatcher.on('start', () => { - dispatcher.player.streamingData.pausedTime = 0; - }); - dispatcher.on('error', error => { console.error(error); radio.voiceChannel.leave(); @@ -95,10 +89,8 @@ function play(guild, client, url) { dispatcher.setVolume(radio.volume / 10); - message.play = client.messages.play.replace("%radio.station.name%", radio.station.name); + message.play = client.messages.play.replace("%radio.station.name%", radio.station.name); radio.textChannel.send(client.messageEmojis["play"] + message.play); - radio.playing = true; - }; function searchStation(key, client) { diff --git a/commands/stop.js b/commands/stop.js index 5abe8a9..f7979f6 100644 --- a/commands/stop.js +++ b/commands/stop.js @@ -5,7 +5,7 @@ module.exports = { usage: '', permission: 'none', category: 'music', - execute(msg, args, client, Discord, prefix, command) { + execute(msg, args, client, Discord, command) { const radio = client.radio.get(msg.guild.id); if (client.funcs.check(client, msg, command)) { radio.connection.dispatcher.destroy(); diff --git a/commands/volume.js b/commands/volume.js index c40cc1a..3ae2962 100644 --- a/commands/volume.js +++ b/commands/volume.js @@ -5,14 +5,14 @@ module.exports = { usage: '', permission: 'MANAGE_MESSAGES', category: 'music', - execute(msg, args, client, Discord, prefix, command) { - let message = {}; + execute(msg, args, client, Discord, command) { + let message = {}; const radio = client.radio.get(msg.guild.id); - + if (!args[1] && radio) { - message.currentVolume = client.messages.currentVolume.replace("%radio.volume%", radio.volume) - return msg.channel.send(message.currentVolume); - } + message.currentVolume = client.messages.currentVolume.replace("%radio.volume%", radio.volume) + return msg.channel.send(message.currentVolume); + } const volume = parseFloat(args[1]); if (client.funcs.check(client, msg, command)) { if (isNaN(volume)) return msg.channel.send(client.messages.invalidVolume); @@ -20,7 +20,7 @@ module.exports = { if (volume < 0) return msg.channel.send(client.messages.negativeVolume); radio.volume = volume; radio.connection.dispatcher.setVolume(volume / 5); - message.newVolume = client.messages.newVolume.replace("%volume%", volume); + message.newVolume = client.messages.newVolume.replace("%volume%", volume); return msg.channel.send(message.newVolume); } } diff --git a/config.js b/config.js index 2491b71..6f73d6d 100644 --- a/config.js +++ b/config.js @@ -4,7 +4,7 @@ module.exports = { //credentials token: process.env.DISCORD_TOKEN, - + //support supportGuild: "https://discord.gg/rRA65Mn", devId: [ @@ -18,6 +18,5 @@ module.exports = { //Settings prefix: process.env.PREFIX || "rx>", - volume: 5 } diff --git a/events/msg.js b/events/msg.js index afd4ec9..5aa24af 100644 --- a/events/msg.js +++ b/events/msg.js @@ -7,13 +7,13 @@ module.exports = { if (!msg.content.startsWith(prefix)) return; if (!args[0]) return; const commandName = args[0].toLowerCase(); + if (commandName === 'none') return; const command = client.commands.get(commandName) || client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName)) || client.commandAliases.get(commandName); if (!command && msg.content !== `${prefix}`) return; const permissions = msg.channel.permissionsFor(msg.client.user); if (!permissions.has('EMBED_LINKS')) return msg.channel.send(client.messages.noPermsEmbed); try { - command.uses++; - command.execute(msg, args, client, Discord, prefix, command); + command.execute(msg, args, client, Discord, command); } catch (error) { msg.reply(client.messages.runningCommandFailed); console.error(error); diff --git a/events/ready.js b/events/ready.js index 8031f5d..1a0809c 100644 --- a/events/ready.js +++ b/events/ready.js @@ -31,7 +31,7 @@ module.exports = { client.stations = await fetch('https://gitea.cwinfo.org/cwchristerw/radio/raw/branch/master/playlist.json') .then(res => res.json()); }, 3600000); - - require(`../struct/emojis.js`).execute(client, Discord); + + require(`../struct/emojis.js`).execute(client); } } \ No newline at end of file diff --git a/events/voiceStateUpdate.js b/events/voiceStateUpdate.js index d49292f..a1973c6 100644 --- a/events/voiceStateUpdate.js +++ b/events/voiceStateUpdate.js @@ -7,8 +7,6 @@ module.exports = { if (!radio) return; if (newState.member.id === client.user.id && oldState.member.id === client.user.id) { if (newState.channel === null) { - radio.songs = []; - radio.looping = false; return client.radio.delete(newState.guild.id); } @@ -18,8 +16,6 @@ module.exports = { const connection = await oldState.channel.join(); return radio.connection = connection; } catch (error) { - radio.songs = []; - radio.looping = false; radio.connection.dispatcher.destroy(); radio.voiceChannel.leave(); client.radio.delete(msg.guild.id); @@ -36,8 +32,6 @@ module.exports = { setTimeout(() => { if (!radio) return; if (radio.voiceChannel.members.size === 1) { - radio.songs = []; - radio.looping = false; radio.connection.dispatcher.destroy(); radio.voiceChannel.leave(); client.radio.delete(newState.guild.id); diff --git a/struct/check.js b/struct/check.js index fb4d404..f16e9d4 100644 --- a/struct/check.js +++ b/struct/check.js @@ -2,11 +2,11 @@ module.exports = function (client, msg, command) { let message = {}; const radio = client.radio.get(msg.guild.id); const permissions = msg.channel.permissionsFor(msg.author); - if (!radio || !radio.playing){ + if (!radio) { msg.channel.send(client.messageEmojis["x"] + client.messages.notPlaying); return false; } - if (msg.member.voice.channel !== radio.voiceChannel){ + if (msg.member.voice.channel !== radio.voiceChannel) { msg.channel.send(client.messageEmojis["x"] + client.messages.wrongVoiceChannel); return false; } diff --git a/struct/client.js b/struct/client.js index 10d084c..cbf4288 100644 --- a/struct/client.js +++ b/struct/client.js @@ -14,7 +14,6 @@ module.exports = class extends Client { this.commandAliases = new Collection(); this.radio = new Map(); this.funcs = {}; - this.dispatcher = {}; this.config = require('../config.js'); this.messages = require('./messages.js'); this.funcs.check = require('./check.js'); diff --git a/struct/emojis.js b/struct/emojis.js index d93d54f..3018e73 100644 --- a/struct/emojis.js +++ b/struct/emojis.js @@ -1,26 +1,26 @@ module.exports = { name: 'emojis', - async execute(client, Discord) { + async execute(client) { let customEmojis = { list: "<:RadioXList:688541155519889482>", play: "<:RadioXPlay:688541155712827458>", stop: "<:RadioXStop:688541155377414168>", x: "<:RadioXX:688541155792781320>" }; - + let fallbackEmojis = { list: "📜", play: "▶️", stop: "⏹️", x: "❌" }; - + client.messageEmojis = {}; - for(customEmojiName in customEmojis){ + for (customEmojiName in customEmojis) { customEmojiID = customEmojis[customEmojiName].replace(/[^0-9]+/g, ''); customEmoji = client.emojis.cache.get(customEmojiID); - if(customEmoji){ + if (customEmoji) { client.messageEmojis[customEmojiName] = customEmojis[customEmojiName]; } else { client.messageEmojis[customEmojiName] = fallbackEmojis[customEmojiName];