From 8860952c072ee319a353b4aa2b6a777781051f94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Sat, 4 Sep 2021 14:18:58 +0300 Subject: [PATCH 01/30] Bumb version --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 079efd4..a9935a2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "eximiabots-radiox", - "version": "0.3.3", + "version": "0.3.4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "eximiabots-radiox", - "version": "0.3.3", + "version": "0.3.4", "license": "MIT", "dependencies": { "@discordjs/builders": "^0.6.0", diff --git a/package.json b/package.json index f37e0b7..27aee2a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "eximiabots-radiox", - "version": "0.3.3", + "version": "0.3.4", "description": "Internet Radio to your Discord guild", "main": "index.js", "scripts": { From d5fefcdbbc1ae5ca733cdc9357a23f8dc66b16fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Sun, 5 Sep 2021 02:12:10 +0300 Subject: [PATCH 02/30] Removed commandAliases collection in messageCreate.js --- src/client/events/messageCreate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/events/messageCreate.js b/src/client/events/messageCreate.js index ecc09aa..ccd314f 100644 --- a/src/client/events/messageCreate.js +++ b/src/client/events/messageCreate.js @@ -22,7 +22,7 @@ module.exports = { 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); + const command = client.commands.get(commandName) || client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName)); if (!command && message.content !== `${prefix}`) return; const permissions = message.channel.permissionsFor(message.client.user); if (!permissions.has('EMBED_LINKS')) return message.channel.send(client.messages.noPermsEmbed); From 3609e6af10ba8fc92adecb58339b34545e57737a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Sun, 5 Sep 2021 02:12:43 +0300 Subject: [PATCH 03/30] Added empty next and previous command --- src/client/commands/next.js | 24 ++++++++++++++++++++++++ src/client/commands/previous.js | 24 ++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 src/client/commands/next.js create mode 100644 src/client/commands/previous.js diff --git a/src/client/commands/next.js b/src/client/commands/next.js new file mode 100644 index 0000000..8498004 --- /dev/null +++ b/src/client/commands/next.js @@ -0,0 +1,24 @@ +module.exports = { + name: 'next', + usage: '', + description: 'Next Station', + permission: 'none', + category: 'info', + async execute(interaction, client, Discord, command) { + let message = {}; + const radio = client.radio.get(interaction.guild.id); + if (!radio) return interaction.reply({ + content: 'There is nothing playing.', + ephemeral: true + }); + if(!client.stations) { + message.errorToGetPlaylist = client.messages.errorToGetPlaylist.replace("%client.config.supportGuild%", client.config.supportGuild); + return interaction.reply({ + content: client.messageEmojis["error"] + message.errorToGetPlaylist, + ephemeral: true + }); + } + + + } +} \ No newline at end of file diff --git a/src/client/commands/previous.js b/src/client/commands/previous.js new file mode 100644 index 0000000..7faa125 --- /dev/null +++ b/src/client/commands/previous.js @@ -0,0 +1,24 @@ +module.exports = { + name: 'previous', + usage: '', + description: 'Previous Station', + permission: 'none', + category: 'info', + async execute(interaction, client, Discord, command) { + let message = {}; + const radio = client.radio.get(interaction.guild.id); + if (!radio) return interaction.reply({ + content: 'There is nothing playing.', + ephemeral: true + }); + if(!client.stations) { + message.errorToGetPlaylist = client.messages.errorToGetPlaylist.replace("%client.config.supportGuild%", client.config.supportGuild); + return interaction.reply({ + content: client.messageEmojis["error"] + message.errorToGetPlaylist, + ephemeral: true + }); + } + + + } +} \ No newline at end of file From 1e24e895682dade6688efcf4276f1c821b7da49f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Sun, 5 Sep 2021 02:12:57 +0300 Subject: [PATCH 04/30] Updated maintenance command --- src/client/commands/maintenance.js | 78 +++++++++++++++++------------- 1 file changed, 44 insertions(+), 34 deletions(-) diff --git a/src/client/commands/maintenance.js b/src/client/commands/maintenance.js index 08a52fc..21cb4fa 100644 --- a/src/client/commands/maintenance.js +++ b/src/client/commands/maintenance.js @@ -10,43 +10,53 @@ module.exports = { if(!client.funcs.isDev(client.config.devId, interaction.user.id)) return interaction.reply(client.messageEmojis["error"] + client.messages.notAllowed); - if(!client.stations) { - message.errorToGetPlaylist = client.messages.errorToGetPlaylist.replace("%client.config.supportGuild%", client.config.supportGuild); - return interaction.reply(client.messageEmojis["error"] + message.errorToGetPlaylist); - } - - let currentRadios = client.radio.keys(); - let radio = currentRadios.next(); - let stoppedRadios = ""; + if(client.config.version.includes("-dev")){ + interaction.reply({ + content: "Maintenance Initiated", + ephemeral: true + }); - client.user.setStatus('dnd'); - - while (!radio.done) { - let currentRadio = client.radio.get(radio.value); - currentRadio.guild = client.datastore.getEntry(radio.value).guild; - - if(currentRadio){ - client.funcs.statisticsUpdate(client, currentRadio.guild, currentRadio); - currentRadio.connection?.destroy(); - currentRadio.audioPlayer?.stop(); - currentRadio.message?.delete(); - client.radio.delete(radio.value); - stoppedRadios += "-" + radio.value + ": " + currentRadio.guild.name + "\n"; + process.emit('SIGINT'); + } else { + if(!client.stations) { + message.errorToGetPlaylist = client.messages.errorToGetPlaylist.replace("%client.config.supportGuild%", client.config.supportGuild); + return interaction.reply(client.messageEmojis["error"] + message.errorToGetPlaylist); } - radio = currentRadios.next(); + + let currentRadios = client.radio.keys(); + let radio = currentRadios.next(); + let stoppedRadios = ""; + + client.user.setStatus('dnd'); + + while (!radio.done) { + let currentRadio = client.radio.get(radio.value); + currentRadio.guild = client.datastore.getEntry(radio.value).guild; + + if(currentRadio){ + client.funcs.statisticsUpdate(client, currentRadio.guild, currentRadio); + currentRadio.connection?.destroy(); + currentRadio.audioPlayer?.stop(); + currentRadio.message?.delete(); + client.radio.delete(radio.value); + stoppedRadios += "-" + radio.value + ": " + currentRadio.guild.name + "\n"; + } + radio = currentRadios.next(); + } + + const embed = new Discord.MessageEmbed() + .setTitle(client.messages.maintenanceTitle) + .setThumbnail("https://cdn.discordapp.com/emojis/" + client.messageEmojis["maintenance"].replace(/[^0-9]+/g, '')) + .setColor(client.config.embedColor) + .setDescription("Stopped all radios" + "\n" + stoppedRadios) + .setImage('https://waren.io/berriabot-temp-sa7a36a9xm6837br/images/empty-3.png') + .setFooter(client.messages.footerText, "https://cdn.discordapp.com/emojis/" + client.messageEmojis["eximiabots"].replace(/[^0-9]+/g, '')); + + interaction.reply({ + embeds: [embed], + ephemeral: true + }); } - const embed = new Discord.MessageEmbed() - .setTitle(client.messages.maintenanceTitle) - .setThumbnail("https://cdn.discordapp.com/emojis/" + client.messageEmojis["maintenance"].replace(/[^0-9]+/g, '')) - .setColor(client.config.embedColor) - .setDescription("Stopped all radios" + "\n" + stoppedRadios) - .setImage('https://waren.io/berriabot-temp-sa7a36a9xm6837br/images/empty-3.png') - .setFooter(client.messages.footerText, "https://cdn.discordapp.com/emojis/" + client.messageEmojis["eximiabots"].replace(/[^0-9]+/g, '')); - - interaction.reply({ - embeds: [embed], - ephemeral: true - }); } }; \ No newline at end of file From 2857b6886fb00480750ef02ebea9f9f429a147a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Sun, 5 Sep 2021 02:13:18 +0300 Subject: [PATCH 05/30] Enabled prev & next buttons in play command --- src/client/commands/play.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/client/commands/play.js b/src/client/commands/play.js index b022bbf..8ef96a4 100644 --- a/src/client/commands/play.js +++ b/src/client/commands/play.js @@ -240,7 +240,6 @@ async function play(interaction, guild, client, url, Discord) { .setCustomId('prev') .setEmoji(client.messageEmojis["prev"]) .setStyle('SECONDARY') - .setDisabled(true) ) .addComponents( new Discord.MessageButton() @@ -253,7 +252,6 @@ async function play(interaction, guild, client, url, Discord) { .setCustomId('next') .setEmoji(client.messageEmojis["next"]) .setStyle('SECONDARY') - .setDisabled(true) ) .addComponents( new Discord.MessageButton() From a3efdbf3cb27d661952758e90db400d64b5bcb8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Sun, 5 Sep 2021 02:13:39 +0300 Subject: [PATCH 06/30] Enabled next and previous buttons in restoreradio.js --- src/client/restoreradio.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/client/restoreradio.js b/src/client/restoreradio.js index 45ff10f..c33bca5 100644 --- a/src/client/restoreradio.js +++ b/src/client/restoreradio.js @@ -114,7 +114,6 @@ async function play(interaction, guild, client, url, Discord) { .setCustomId('prev') .setEmoji(client.messageEmojis["prev"]) .setStyle('SECONDARY') - .setDisabled(true) ) .addComponents( new Discord.MessageButton() @@ -127,7 +126,6 @@ async function play(interaction, guild, client, url, Discord) { .setCustomId('next') .setEmoji(client.messageEmojis["next"]) .setStyle('SECONDARY') - .setDisabled(true) ) .addComponents( new Discord.MessageButton() From c724ae502f878912df63d7bb68174b1e03332c59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Sun, 5 Sep 2021 02:16:58 +0300 Subject: [PATCH 07/30] Moved searchStations function into funcs folder --- src/Client.ts | 1 + src/client/commands/play.js | 67 +----------------------------- src/client/funcs/searchStations.js | 62 +++++++++++++++++++++++++++ src/client/restoreradio.js | 65 +---------------------------- 4 files changed, 66 insertions(+), 129 deletions(-) create mode 100644 src/client/funcs/searchStations.js diff --git a/src/Client.ts b/src/Client.ts index a991ab7..3df2bef 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -39,6 +39,7 @@ class RadioClient extends Client { this.funcs.statisticsUpdate = require("./client/funcs/statisticsUpdate.js"); this.funcs.saveState = require("./client/funcs/saveState.js"); this.funcs.loadState = require("./client/funcs/loadState.js"); + this.funcs.searchStations = require("./client/funcs/searchStations.js"); console.log('RadioX ' + this.config.version); console.log('Internet Radio to your Discord guild'); diff --git a/src/client/commands/play.js b/src/client/commands/play.js index 8ef96a4..f15ab44 100644 --- a/src/client/commands/play.js +++ b/src/client/commands/play.js @@ -123,7 +123,7 @@ module.exports = { content: client.messageEmojis["error"] + client.messages.tooShortSearch, ephemeral: true }); - const sstation = await searchStation(query, client); + const sstation = await client.funcs.searchStation(query, client); if (!sstation) return interaction.reply({ content: client.messageEmojis["error"] + client.messages.noSearchResults, @@ -273,67 +273,4 @@ async function play(interaction, guild, client, url, Discord) { ephemeral: true }); -} - -function searchStation(key, client) { - if (client.stations === null) return false; - let foundStations = []; - if (!key) return false; - if (key == "radio") return false; - - client.stations - .filter( - x => x.name.toUpperCase().includes(key.toUpperCase()) || x === key - ) - .forEach(x => - foundStations.push({ station: x, name: x.name, probability: 100 }) - ); - - if (key.startsWith("radio ")) key = key.slice(6); - const probabilityIncrement = 100 / key.split(" ").length / 2; - for (let i = 0; i < key.split(" ").length; i++) { - client.stations - .filter( - x => x.name.toUpperCase().includes(key.split(" ")[i].toUpperCase()) || x === key - ) - .forEach(x => - foundStations.push({ station: x, name: x.name, probability: probabilityIncrement }) - ); - } - if (foundStations.length === 0) return false; - for (let i = 0; i < foundStations.length; i++) { - for (let j = 0; j < foundStations.length; j++) { - if (foundStations[i] === foundStations[j] && i !== j) foundStations.splice(i, 1); - } - } - for (let i = 0; i < foundStations.length; i++) { - if (foundStations[i].name.length > key.length) { - foundStations[i].probability -= - (foundStations[i].name.split(" ").length - key.split(" ").length) * - (probabilityIncrement * 0.5); - } else if (foundStations[i].name.length === key.length) { - foundStations[i].probability += probabilityIncrement * 0.9; - } - - for (let j = 0; j < key.split(" ").length; j++) { - if (!foundStations[i].name.toUpperCase().includes(key.toUpperCase().split(" ")[j])) { - foundStations[i].probability -= probabilityIncrement * 0.5; - } - } - } - let highestProbabilityStation; - for (let i = 0; i < foundStations.length; i++) { - if ( - !highestProbabilityStation || - highestProbabilityStation.probability < foundStations[i].probability - ) - highestProbabilityStation = foundStations[i]; - if ( - highestProbabilityStation && - highestProbabilityStation.probability === foundStations[i].probability - ) { - highestProbabilityStation = foundStations[i].station; - } - } - return highestProbabilityStation; -} +} \ No newline at end of file diff --git a/src/client/funcs/searchStations.js b/src/client/funcs/searchStations.js new file mode 100644 index 0000000..f443fd0 --- /dev/null +++ b/src/client/funcs/searchStations.js @@ -0,0 +1,62 @@ +module.exports = function searchStation(key, client) { + if (client.stations === null) return false; + let foundStations = []; + if (!key) return false; + if (key == "radio") return false; + + client.stations + .filter( + x => x.name.toUpperCase().includes(key.toUpperCase()) || x === key + ) + .forEach(x => + foundStations.push({ station: x, name: x.name, probability: 100 }) + ); + + if (key.startsWith("radio ")) key = key.slice(6); + const probabilityIncrement = 100 / key.split(" ").length / 2; + for (let i = 0; i < key.split(" ").length; i++) { + client.stations + .filter( + x => x.name.toUpperCase().includes(key.split(" ")[i].toUpperCase()) || x === key + ) + .forEach(x => + foundStations.push({ station: x, name: x.name, probability: probabilityIncrement }) + ); + } + if (foundStations.length === 0) return false; + for (let i = 0; i < foundStations.length; i++) { + for (let j = 0; j < foundStations.length; j++) { + if (foundStations[i] === foundStations[j] && i !== j) foundStations.splice(i, 1); + } + } + for (let i = 0; i < foundStations.length; i++) { + if (foundStations[i].name.length > key.length) { + foundStations[i].probability -= + (foundStations[i].name.split(" ").length - key.split(" ").length) * + (probabilityIncrement * 0.5); + } else if (foundStations[i].name.length === key.length) { + foundStations[i].probability += probabilityIncrement * 0.9; + } + + for (let j = 0; j < key.split(" ").length; j++) { + if (!foundStations[i].name.toUpperCase().includes(key.toUpperCase().split(" ")[j])) { + foundStations[i].probability -= probabilityIncrement * 0.5; + } + } + } + let highestProbabilityStation; + for (let i = 0; i < foundStations.length; i++) { + if ( + !highestProbabilityStation || + highestProbabilityStation.probability < foundStations[i].probability + ) + highestProbabilityStation = foundStations[i]; + if ( + highestProbabilityStation && + highestProbabilityStation.probability === foundStations[i].probability + ) { + highestProbabilityStation = foundStations[i].station; + } + } + return highestProbabilityStation; +} \ No newline at end of file diff --git a/src/client/restoreradio.js b/src/client/restoreradio.js index c33bca5..1e31709 100644 --- a/src/client/restoreradio.js +++ b/src/client/restoreradio.js @@ -15,7 +15,7 @@ module.exports = { if(!state) return; if(!state.station || !state.channels.voice || !state.channels.text) return; - const sstation = await searchStation(state.station.name, client); + const sstation = await client.funcs.searchStation(state.station.name, client); let url = sstation.stream[sstation.stream.default]; let station = sstation; @@ -143,66 +143,3 @@ async function play(interaction, guild, client, url, Discord) { message.play = client.messages.play.replace("%radio.station.name%", radio.station.name); } - -function searchStation(key, client) { - if (client.stations === null) return false; - let foundStations = []; - if (!key) return false; - if (key == "radio") return false; - - client.stations - .filter( - x => x.name.toUpperCase().includes(key.toUpperCase()) || x === key - ) - .forEach(x => - foundStations.push({ station: x, name: x.name, probability: 100 }) - ); - - if (key.startsWith("radio ")) key = key.slice(6); - const probabilityIncrement = 100 / key.split(" ").length / 2; - for (let i = 0; i < key.split(" ").length; i++) { - client.stations - .filter( - x => x.name.toUpperCase().includes(key.split(" ")[i].toUpperCase()) || x === key - ) - .forEach(x => - foundStations.push({ station: x, name: x.name, probability: probabilityIncrement }) - ); - } - if (foundStations.length === 0) return false; - for (let i = 0; i < foundStations.length; i++) { - for (let j = 0; j < foundStations.length; j++) { - if (foundStations[i] === foundStations[j] && i !== j) foundStations.splice(i, 1); - } - } - for (let i = 0; i < foundStations.length; i++) { - if (foundStations[i].name.length > key.length) { - foundStations[i].probability -= - (foundStations[i].name.split(" ").length - key.split(" ").length) * - (probabilityIncrement * 0.5); - } else if (foundStations[i].name.length === key.length) { - foundStations[i].probability += probabilityIncrement * 0.9; - } - - for (let j = 0; j < key.split(" ").length; j++) { - if (!foundStations[i].name.toUpperCase().includes(key.toUpperCase().split(" ")[j])) { - foundStations[i].probability -= probabilityIncrement * 0.5; - } - } - } - let highestProbabilityStation; - for (let i = 0; i < foundStations.length; i++) { - if ( - !highestProbabilityStation || - highestProbabilityStation.probability < foundStations[i].probability - ) - highestProbabilityStation = foundStations[i]; - if ( - highestProbabilityStation && - highestProbabilityStation.probability === foundStations[i].probability - ) { - highestProbabilityStation = foundStations[i].station; - } - } - return highestProbabilityStation; -} \ No newline at end of file From e8d90f8a3cf99d53398f24d54ea006bee4eb03a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Sun, 5 Sep 2021 02:23:26 +0300 Subject: [PATCH 08/30] Fixed file name searchStations to searchStation --- src/Client.ts | 2 +- src/client/funcs/{searchStations.js => searchStation.js} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename src/client/funcs/{searchStations.js => searchStation.js} (100%) diff --git a/src/Client.ts b/src/Client.ts index 3df2bef..2d364e5 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -39,7 +39,7 @@ class RadioClient extends Client { this.funcs.statisticsUpdate = require("./client/funcs/statisticsUpdate.js"); this.funcs.saveState = require("./client/funcs/saveState.js"); this.funcs.loadState = require("./client/funcs/loadState.js"); - this.funcs.searchStations = require("./client/funcs/searchStations.js"); + this.funcs.searchStation = require("./client/funcs/searchStation.js"); console.log('RadioX ' + this.config.version); console.log('Internet Radio to your Discord guild'); diff --git a/src/client/funcs/searchStations.js b/src/client/funcs/searchStation.js similarity index 100% rename from src/client/funcs/searchStations.js rename to src/client/funcs/searchStation.js From 25356be323f9e566bf5087db0fec560dc5bc09a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Sun, 5 Sep 2021 02:35:36 +0300 Subject: [PATCH 09/30] Moved play function to funcs folder --- src/Client.ts | 1 + src/client/commands/play.js | 93 +------------------------------------ src/client/funcs/play.js | 88 +++++++++++++++++++++++++++++++++++ src/client/restoreradio.js | 87 +--------------------------------- 4 files changed, 93 insertions(+), 176 deletions(-) create mode 100644 src/client/funcs/play.js diff --git a/src/Client.ts b/src/Client.ts index 2d364e5..7c0e3ef 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -40,6 +40,7 @@ class RadioClient extends Client { this.funcs.saveState = require("./client/funcs/saveState.js"); this.funcs.loadState = require("./client/funcs/loadState.js"); this.funcs.searchStation = require("./client/funcs/searchStation.js"); + this.funcs.play = require("./client/funcs/play.js"); console.log('RadioX ' + this.config.version); console.log('Internet Radio to your Discord guild'); diff --git a/src/client/commands/play.js b/src/client/commands/play.js index f15ab44..b4fece3 100644 --- a/src/client/commands/play.js +++ b/src/client/commands/play.js @@ -167,7 +167,7 @@ module.exports = { construct.connection = connection; let date = new Date(); construct.startTime = date.getTime(); - play(interaction, interaction.guild, client, url, Discord); + client.funcs.play(interaction, interaction.guild, client, url, Discord); client.datastore.checkEntry(interaction.guild.id); construct.currentGuild = client.datastore.getEntry(interaction.guild.id); @@ -184,93 +184,4 @@ module.exports = { return interaction.reply(client.messageEmojis["error"] + `An error occured: ${error}`); } } -}; - -async function play(interaction, guild, client, url, Discord) { - let message = {}; - const radio = client.radio.get(guild.id); - const resource = createAudioResource(url); - radio.connection.subscribe(radio.audioPlayer); - radio.audioPlayer.play(resource); - resource.playStream - .on("readable", () => { - client.funcs.logger('Radio', 'Stream started' + " / " + guild.id + " / " + radio.station.name); - }) - .on("finish", () => { - client.funcs.logger('Radio', 'Stream finished' + " / " + guild.id); - client.funcs.statisticsUpdate(client, guild, radio); - radio.connection?.destroy(); - radio.audioPlayer?.stop(); - client.radio.delete(guild.id); - return; - }) - .on("error", error => { - client.funcs.logger('Radio', 'Stream errored'); - console.error(error); - radio.connection?.destroy(); - radio.audioPlayer?.stop(); - client.radio.delete(guild.id); - return interaction.reply(client.messages.errorPlaying); - }); - - 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("%client.funcs.msToTime(completed)%", ""); - message.nowplayingDescription = message.nowplayingDescription.replace("Owner: ", ""); - message.nowplayingDescription = message.nowplayingDescription.replace("**", ""); - message.nowplayingDescription = message.nowplayingDescription.replace("**", ""); - - const embed = new Discord.MessageEmbed() - .setTitle(client.user.username) - .setThumbnail((radio.station.logo || "https://cdn.discordapp.com/emojis/" + client.messageEmojis["play"].replace(/[^0-9]+/g, ''))) - .setColor(client.config.embedColor) - .addField(client.messages.nowplayingTitle, message.nowplayingDescription, true) - .setImage('https://waren.io/berriabot-temp-sa7a36a9xm6837br/images/empty-3.png') - .setFooter(client.messages.footerText, "https://cdn.discordapp.com/emojis/" + client.messageEmojis["eximiabots"].replace(/[^0-9]+/g, '')); - - const buttons = new Discord.MessageActionRow() - .addComponents( - new Discord.MessageButton() - .setCustomId('list') - .setEmoji(client.messageEmojis["list"]) - .setStyle('SECONDARY') - ) - .addComponents( - new Discord.MessageButton() - .setCustomId('prev') - .setEmoji(client.messageEmojis["prev"]) - .setStyle('SECONDARY') - ) - .addComponents( - new Discord.MessageButton() - .setCustomId('stop') - .setEmoji(client.messageEmojis["stop"]) - .setStyle('SECONDARY') - ) - .addComponents( - new Discord.MessageButton() - .setCustomId('next') - .setEmoji(client.messageEmojis["next"]) - .setStyle('SECONDARY') - ) - .addComponents( - new Discord.MessageButton() - .setCustomId('statistics') - .setEmoji(client.messageEmojis["statistics"]) - .setStyle('SECONDARY') - ); - - if(!radio.message){ - radio.message = await radio.textChannel.send({ embeds: [embed], components: [buttons] }); - } else { - radio.message.edit({ embeds: [embed], components: [buttons] }); - } - - message.play = client.messages.play.replace("%radio.station.name%", radio.station.name); - - interaction.reply({ - content: client.messageEmojis["play"] + message.play, - ephemeral: true - }); - -} \ No newline at end of file +}; \ No newline at end of file diff --git a/src/client/funcs/play.js b/src/client/funcs/play.js new file mode 100644 index 0000000..0d9551a --- /dev/null +++ b/src/client/funcs/play.js @@ -0,0 +1,88 @@ +module.exports = async function play(interaction, guild, client, url, Discord) { + let message = {}; + const radio = client.radio.get(guild.id); + const resource = createAudioResource(url); + radio.connection.subscribe(radio.audioPlayer); + radio.audioPlayer.play(resource); + resource.playStream + .on("readable", () => { + client.funcs.logger('Radio', 'Stream started' + " / " + guild.id + " / " + radio.station.name); + }) + .on("finish", () => { + client.funcs.logger('Radio', 'Stream finished' + " / " + guild.id); + client.funcs.statisticsUpdate(client, guild, radio); + radio.connection?.destroy(); + radio.audioPlayer?.stop(); + client.radio.delete(guild.id); + return; + }) + .on("error", error => { + client.funcs.logger('Radio', 'Stream errored'); + console.error(error); + radio.connection?.destroy(); + radio.audioPlayer?.stop(); + client.radio.delete(guild.id); + return interaction.reply(client.messages.errorPlaying); + }); + + 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("%client.funcs.msToTime(completed)%", ""); + message.nowplayingDescription = message.nowplayingDescription.replace("Owner: ", ""); + message.nowplayingDescription = message.nowplayingDescription.replace("**", ""); + message.nowplayingDescription = message.nowplayingDescription.replace("**", ""); + + const embed = new Discord.MessageEmbed() + .setTitle(client.user.username) + .setThumbnail((radio.station.logo || "https://cdn.discordapp.com/emojis/" + client.messageEmojis["play"].replace(/[^0-9]+/g, ''))) + .setColor(client.config.embedColor) + .addField(client.messages.nowplayingTitle, message.nowplayingDescription, true) + .setImage('https://waren.io/berriabot-temp-sa7a36a9xm6837br/images/empty-3.png') + .setFooter(client.messages.footerText, "https://cdn.discordapp.com/emojis/" + client.messageEmojis["eximiabots"].replace(/[^0-9]+/g, '')); + + const buttons = new Discord.MessageActionRow() + .addComponents( + new Discord.MessageButton() + .setCustomId('list') + .setEmoji(client.messageEmojis["list"]) + .setStyle('SECONDARY') + ) + .addComponents( + new Discord.MessageButton() + .setCustomId('prev') + .setEmoji(client.messageEmojis["prev"]) + .setStyle('SECONDARY') + ) + .addComponents( + new Discord.MessageButton() + .setCustomId('stop') + .setEmoji(client.messageEmojis["stop"]) + .setStyle('SECONDARY') + ) + .addComponents( + new Discord.MessageButton() + .setCustomId('next') + .setEmoji(client.messageEmojis["next"]) + .setStyle('SECONDARY') + ) + .addComponents( + new Discord.MessageButton() + .setCustomId('statistics') + .setEmoji(client.messageEmojis["statistics"]) + .setStyle('SECONDARY') + ); + + if(!radio.message){ + radio.message = await radio.textChannel.send({ embeds: [embed], components: [buttons] }); + } else { + radio.message.edit({ embeds: [embed], components: [buttons] }); + } + + message.play = client.messages.play.replace("%radio.station.name%", radio.station.name); + + interaction.reply({ + content: client.messageEmojis["play"] + message.play, + ephemeral: true + }); + +} \ No newline at end of file diff --git a/src/client/restoreradio.js b/src/client/restoreradio.js index 1e31709..982bc87 100644 --- a/src/client/restoreradio.js +++ b/src/client/restoreradio.js @@ -43,7 +43,7 @@ module.exports = { let date = new Date(); construct.startTime = date.getTime(); - play(null, guild, client, url, Discord); + client.funcs.play(null, guild, client, url, Discord); client.datastore.checkEntry(guild.id); construct.datastore = client.datastore.getEntry(guild.id); @@ -59,87 +59,4 @@ module.exports = { } }); } -} - -async function play(interaction, guild, client, url, Discord) { - let message = {}; - const radio = client.radio.get(guild.id); - const resource = createAudioResource(url); - radio.connection.subscribe(radio.audioPlayer); - radio.audioPlayer.play(resource); - resource.playStream - .on("readable", () => { - client.funcs.logger('Radio', 'Stream started' + " / " + guild.id + " / " + radio.station.name); - }) - .on("finish", () => { - client.funcs.logger('Radio', 'Stream finished' + " / " + guild.id); - client.funcs.statisticsUpdate(client, guild, radio); - radio.connection?.destroy(); - radio.audioPlayer?.stop(); - client.radio.delete(guild.id); - return; - }) - .on("error", error => { - client.funcs.logger('Radio', 'Stream errored'); - console.error(error); - radio.connection?.destroy(); - radio.audioPlayer?.stop(); - client.radio.delete(guild.id); - }); - - 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("%client.funcs.msToTime(completed)%", ""); - message.nowplayingDescription = message.nowplayingDescription.replace("Owner: ", ""); - message.nowplayingDescription = message.nowplayingDescription.replace("**", ""); - message.nowplayingDescription = message.nowplayingDescription.replace("**", ""); - - const embed = new Discord.MessageEmbed() - .setTitle(client.user.username) - .setThumbnail((radio.station.logo || "https://cdn.discordapp.com/emojis/" + client.messageEmojis["play"].replace(/[^0-9]+/g, ''))) - .setColor(client.config.embedColor) - .addField(client.messages.nowplayingTitle, message.nowplayingDescription, true) - .setImage('https://waren.io/berriabot-temp-sa7a36a9xm6837br/images/empty-3.png') - .setFooter(client.messages.footerText, "https://cdn.discordapp.com/emojis/" + client.messageEmojis["eximiabots"].replace(/[^0-9]+/g, '')); - - const buttons = new Discord.MessageActionRow() - .addComponents( - new Discord.MessageButton() - .setCustomId('list') - .setEmoji(client.messageEmojis["list"]) - .setStyle('SECONDARY') - ) - .addComponents( - new Discord.MessageButton() - .setCustomId('prev') - .setEmoji(client.messageEmojis["prev"]) - .setStyle('SECONDARY') - ) - .addComponents( - new Discord.MessageButton() - .setCustomId('stop') - .setEmoji(client.messageEmojis["stop"]) - .setStyle('SECONDARY') - ) - .addComponents( - new Discord.MessageButton() - .setCustomId('next') - .setEmoji(client.messageEmojis["next"]) - .setStyle('SECONDARY') - ) - .addComponents( - new Discord.MessageButton() - .setCustomId('statistics') - .setEmoji(client.messageEmojis["statistics"]) - .setStyle('SECONDARY') - ); - - if(!radio.message){ - radio.message = await radio.textChannel.send({ embeds: [embed], components: [buttons] }); - } else { - radio.message.edit({ embeds: [embed], components: [buttons] }); - } - - message.play = client.messages.play.replace("%radio.station.name%", radio.station.name); - -} +} \ No newline at end of file From 72d0054d258e94b3b245216c50904d65fd03c92e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Sun, 5 Sep 2021 02:36:52 +0300 Subject: [PATCH 10/30] Made interaction nullable when replying in play function --- src/client/funcs/play.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/funcs/play.js b/src/client/funcs/play.js index 0d9551a..8b4c764 100644 --- a/src/client/funcs/play.js +++ b/src/client/funcs/play.js @@ -80,7 +80,7 @@ module.exports = async function play(interaction, guild, client, url, Discord) { message.play = client.messages.play.replace("%radio.station.name%", radio.station.name); - interaction.reply({ + interaction?.reply({ content: client.messageEmojis["play"] + message.play, ephemeral: true }); From 3fc28a79cb65ae15d056f6460f84e92f1a3693cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Sun, 5 Sep 2021 02:39:59 +0300 Subject: [PATCH 11/30] Moved createAudioResource from discord.js/voice to play function --- src/client/commands/play.js | 3 +-- src/client/funcs/play.js | 4 ++++ src/client/restoreradio.js | 1 - 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/client/commands/play.js b/src/client/commands/play.js index b4fece3..041e9ad 100644 --- a/src/client/commands/play.js +++ b/src/client/commands/play.js @@ -1,6 +1,5 @@ const { createAudioPlayer, - createAudioResource, getVoiceConnection, joinVoiceChannel } = require("@discordjs/voice"); @@ -141,7 +140,7 @@ module.exports = { radio.station = station; radio.textChannel = interaction.channel; radio.startTime = date.getTime(); - play(interaction, interaction.guild, client, url, Discord); + client.funcs.play(interaction, interaction.guild, client, url, Discord); return; } diff --git a/src/client/funcs/play.js b/src/client/funcs/play.js index 8b4c764..83f9729 100644 --- a/src/client/funcs/play.js +++ b/src/client/funcs/play.js @@ -1,3 +1,7 @@ +const { + createAudioResource +} = require("@discordjs/voice"); + module.exports = async function play(interaction, guild, client, url, Discord) { let message = {}; const radio = client.radio.get(guild.id); diff --git a/src/client/restoreradio.js b/src/client/restoreradio.js index 982bc87..4916bbc 100644 --- a/src/client/restoreradio.js +++ b/src/client/restoreradio.js @@ -1,7 +1,6 @@ import Discord from "discord.js"; const { createAudioPlayer, - createAudioResource, getVoiceConnection, joinVoiceChannel } = require("@discordjs/voice"); From 3f12bafee0286731596547d2637a398edaa04e01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Sun, 5 Sep 2021 02:46:13 +0300 Subject: [PATCH 12/30] Updated Dependencies --- package-lock.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index a9935a2..0eafcbb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1228,9 +1228,9 @@ } }, "node_modules/deep-is": { - "version": "0.1.3", - "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.3.tgz", - "integrity": "sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=", + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz", + "integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==", "dev": true }, "node_modules/defer-to-connect": { @@ -4788,9 +4788,9 @@ "dev": true }, "deep-is": { - "version": "0.1.3", - "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.3.tgz", - "integrity": "sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=", + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz", + "integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==", "dev": true }, "defer-to-connect": { From e0226c5cfe9f0aa51fee1e52b5a68dd46613596a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Sun, 5 Sep 2021 02:49:03 +0300 Subject: [PATCH 13/30] Updated multiple command's metadata --- src/client/commands/bug.js | 2 -- src/client/commands/help.js | 2 -- src/client/commands/invite.js | 2 -- src/client/commands/list.js | 2 -- src/client/commands/maintenance.js | 2 -- src/client/commands/next.js | 1 - src/client/commands/nowplaying.js | 2 -- src/client/commands/play.js | 1 - src/client/commands/previous.js | 1 - src/client/commands/statistics.js | 2 -- src/client/commands/status.js | 2 -- src/client/commands/stop.js | 2 -- 12 files changed, 21 deletions(-) diff --git a/src/client/commands/bug.js b/src/client/commands/bug.js index 11a19c0..667a623 100644 --- a/src/client/commands/bug.js +++ b/src/client/commands/bug.js @@ -1,7 +1,5 @@ module.exports = { name: 'bug', - alias: 'none', - usage: '', description: 'Report a bug', permission: 'none', category: 'info', diff --git a/src/client/commands/help.js b/src/client/commands/help.js index 016b267..9ed5e44 100644 --- a/src/client/commands/help.js +++ b/src/client/commands/help.js @@ -1,7 +1,5 @@ module.exports = { name: 'help', - alias: 'h', - usage: '', description: 'Get help using bot', permission: 'none', category: 'info', diff --git a/src/client/commands/invite.js b/src/client/commands/invite.js index aa65a41..a833c43 100644 --- a/src/client/commands/invite.js +++ b/src/client/commands/invite.js @@ -1,7 +1,5 @@ module.exports = { name: 'invite', - alias: 'i', - usage: '', description: 'Invite Bot', permission: 'none', category: 'info', diff --git a/src/client/commands/list.js b/src/client/commands/list.js index 0caa10b..9de8b3b 100644 --- a/src/client/commands/list.js +++ b/src/client/commands/list.js @@ -1,7 +1,5 @@ module.exports = { name: 'list', - alias: 'l', - usage: '', description: 'List radio stations', permission: 'none', category: 'radio', diff --git a/src/client/commands/maintenance.js b/src/client/commands/maintenance.js index 21cb4fa..53085fe 100644 --- a/src/client/commands/maintenance.js +++ b/src/client/commands/maintenance.js @@ -1,7 +1,5 @@ module.exports = { name: 'maintenance', - alias: 'm', - usage: '', description: 'Bot Maintenance', permission: 'none', category: 'info', diff --git a/src/client/commands/next.js b/src/client/commands/next.js index 8498004..1604385 100644 --- a/src/client/commands/next.js +++ b/src/client/commands/next.js @@ -1,6 +1,5 @@ module.exports = { name: 'next', - usage: '', description: 'Next Station', permission: 'none', category: 'info', diff --git a/src/client/commands/nowplaying.js b/src/client/commands/nowplaying.js index 7a59e38..9ae1c0b 100644 --- a/src/client/commands/nowplaying.js +++ b/src/client/commands/nowplaying.js @@ -1,7 +1,5 @@ module.exports = { name: 'nowplaying', - alias: 'np', - usage: '', description: 'Current Radio Station', permission: 'none', category: 'radio', diff --git a/src/client/commands/play.js b/src/client/commands/play.js index 041e9ad..ac10c47 100644 --- a/src/client/commands/play.js +++ b/src/client/commands/play.js @@ -6,7 +6,6 @@ const { module.exports = { name: "play", - alias: "p", usage: "", description: "Play radio", options: [ diff --git a/src/client/commands/previous.js b/src/client/commands/previous.js index 7faa125..98dec3a 100644 --- a/src/client/commands/previous.js +++ b/src/client/commands/previous.js @@ -1,6 +1,5 @@ module.exports = { name: 'previous', - usage: '', description: 'Previous Station', permission: 'none', category: 'info', diff --git a/src/client/commands/statistics.js b/src/client/commands/statistics.js index dcd81a5..d342363 100644 --- a/src/client/commands/statistics.js +++ b/src/client/commands/statistics.js @@ -1,7 +1,5 @@ module.exports = { name: 'statistics', - alias: 'stats', - usage: '', description: 'Show statistics', permission: 'none', category: 'info', diff --git a/src/client/commands/status.js b/src/client/commands/status.js index 6d9cf63..2ec9bbd 100644 --- a/src/client/commands/status.js +++ b/src/client/commands/status.js @@ -1,7 +1,5 @@ module.exports = { name: 'status', - alias: 'st', - usage: '', description: 'Bot Status', permission: 'none', category: 'info', diff --git a/src/client/commands/stop.js b/src/client/commands/stop.js index 19d4c56..facc949 100644 --- a/src/client/commands/stop.js +++ b/src/client/commands/stop.js @@ -1,8 +1,6 @@ module.exports = { name: 'stop', description: 'Stop radio', - alias: 's', - usage: '', permission: 'none', category: 'radio', async execute(interaction, client, Discord, command) { From c81dbddab1ce4562e7b739005101b0c07202f924 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Sun, 5 Sep 2021 02:54:56 +0300 Subject: [PATCH 14/30] Renamed previous to prev command --- src/client/commands/{previous.js => prev.js} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/client/commands/{previous.js => prev.js} (97%) diff --git a/src/client/commands/previous.js b/src/client/commands/prev.js similarity index 97% rename from src/client/commands/previous.js rename to src/client/commands/prev.js index 98dec3a..7e5b211 100644 --- a/src/client/commands/previous.js +++ b/src/client/commands/prev.js @@ -1,5 +1,5 @@ module.exports = { - name: 'previous', + name: 'prev', description: 'Previous Station', permission: 'none', category: 'info', From ec6ea7e839ff7a24037a08e03ccc7dbe63118438 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Sun, 5 Sep 2021 03:06:47 +0300 Subject: [PATCH 15/30] Removed unused variable command from commands. --- src/client/commands/next.js | 2 +- src/client/commands/nowplaying.js | 2 +- src/client/commands/prev.js | 2 +- src/client/commands/statistics.js | 2 +- src/client/commands/status.js | 2 +- src/client/commands/stop.js | 2 +- src/client/events/interactionCreate.js | 4 ++-- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/client/commands/next.js b/src/client/commands/next.js index 1604385..cadeb34 100644 --- a/src/client/commands/next.js +++ b/src/client/commands/next.js @@ -3,7 +3,7 @@ module.exports = { description: 'Next Station', permission: 'none', category: 'info', - async execute(interaction, client, Discord, command) { + async execute(interaction, client, Discord) { let message = {}; const radio = client.radio.get(interaction.guild.id); if (!radio) return interaction.reply({ diff --git a/src/client/commands/nowplaying.js b/src/client/commands/nowplaying.js index 9ae1c0b..2e335fb 100644 --- a/src/client/commands/nowplaying.js +++ b/src/client/commands/nowplaying.js @@ -3,7 +3,7 @@ module.exports = { description: 'Current Radio Station', permission: 'none', category: 'radio', - async execute(interaction, client, Discord, command) { + async execute(interaction, client, Discord) { let message = {}; const radio = client.radio.get(interaction.guild.id); if (!radio) return interaction.reply({ diff --git a/src/client/commands/prev.js b/src/client/commands/prev.js index 7e5b211..476dc28 100644 --- a/src/client/commands/prev.js +++ b/src/client/commands/prev.js @@ -3,7 +3,7 @@ module.exports = { description: 'Previous Station', permission: 'none', category: 'info', - async execute(interaction, client, Discord, command) { + async execute(interaction, client, Discord) { let message = {}; const radio = client.radio.get(interaction.guild.id); if (!radio) return interaction.reply({ diff --git a/src/client/commands/statistics.js b/src/client/commands/statistics.js index d342363..2a71ed8 100644 --- a/src/client/commands/statistics.js +++ b/src/client/commands/statistics.js @@ -3,7 +3,7 @@ module.exports = { description: 'Show statistics', permission: 'none', category: 'info', - execute(interaction, client, Discord, command) { + execute(interaction, client, Discord) { let message = {}; let stations = client.stations; let currentGuild = client.datastore.getEntry(interaction.guild.id); diff --git a/src/client/commands/status.js b/src/client/commands/status.js index 2ec9bbd..078cd02 100644 --- a/src/client/commands/status.js +++ b/src/client/commands/status.js @@ -3,7 +3,7 @@ module.exports = { description: 'Bot Status', permission: 'none', category: 'info', - async execute(interaction, client, Discord, command) { + async execute(interaction, client, Discord) { let message = {}; message.statusTitle = client.messages.statusTitle.replace("%client.user.username%", client.user.username); diff --git a/src/client/commands/stop.js b/src/client/commands/stop.js index facc949..c12cb9c 100644 --- a/src/client/commands/stop.js +++ b/src/client/commands/stop.js @@ -3,7 +3,7 @@ module.exports = { description: 'Stop radio', permission: 'none', category: 'radio', - async execute(interaction, client, Discord, command) { + async execute(interaction, client, Discord) { const radio = client.radio.get(interaction.guild.id); if (client.funcs.check(client, interaction, command)) { client.funcs.statisticsUpdate(client, interaction.guild, radio); diff --git a/src/client/events/interactionCreate.js b/src/client/events/interactionCreate.js index 67d2666..b069289 100644 --- a/src/client/events/interactionCreate.js +++ b/src/client/events/interactionCreate.js @@ -13,7 +13,7 @@ module.exports = { if (!command) return; try { - command.execute(interaction, client, Discord, command); + command.execute(interaction, client, Discord); } catch (error) { interaction.reply({ content: client.messages.runningCommandFailed, @@ -27,7 +27,7 @@ module.exports = { if (!command) return; try { - command.execute(interaction, client, Discord, command); + command.execute(interaction, client, Discord); } catch (error) { interaction.reply({ content: client.messages.runningCommandFailed, From 17132cd51a1a9138b6e69f878c119fd0dbce4299 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Sun, 5 Sep 2021 03:11:51 +0300 Subject: [PATCH 16/30] Moved listStations into funcs folder --- src/Client.ts | 1 + src/client/commands/list.js | 46 ++------------------------------ src/client/commands/play.js | 46 +++----------------------------- src/client/funcs/listStations.js | 45 +++++++++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 87 deletions(-) create mode 100644 src/client/funcs/listStations.js diff --git a/src/Client.ts b/src/Client.ts index 7c0e3ef..f1ebe9d 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -41,6 +41,7 @@ class RadioClient extends Client { this.funcs.loadState = require("./client/funcs/loadState.js"); this.funcs.searchStation = require("./client/funcs/searchStation.js"); this.funcs.play = require("./client/funcs/play.js"); + this.funcs.listStations = require("./client/funcs/listStations.js"); console.log('RadioX ' + this.config.version); console.log('Internet Radio to your Discord guild'); diff --git a/src/client/commands/list.js b/src/client/commands/list.js index 9de8b3b..c6c7f34 100644 --- a/src/client/commands/list.js +++ b/src/client/commands/list.js @@ -3,7 +3,7 @@ module.exports = { description: 'List radio stations', permission: 'none', category: 'radio', - execute(interaction, client, Discord, command) { + execute(interaction, client, Discord) { let message = {}; if(!client.stations) { message.errorToGetPlaylist = client.messages.errorToGetPlaylist.replace("%client.config.supportGuild%", client.config.supportGuild); @@ -13,49 +13,7 @@ module.exports = { const radio = client.radio.get(interaction.guild.id); if(radio){ - let menu = []; - - let stations = new Array(); - - let options = new Array(); - options[1] = new Array(); - options[2] = new Array(); - - stations[1] = client.stations.slice(0,24).forEach(station => { - station = { - label: station.name, - description: station.owner, - value: station.name - }; - options[1].push(station); - }); - - stations[2] = client.stations.slice(25).forEach(station => { - station = { - label: station.name, - description: station.owner, - value: station.name - }; - options[2].push(station); - }); - - menu = new Discord.MessageActionRow() - .addComponents( - new Discord.MessageSelectMenu() - .setCustomId('play') - .setPlaceholder('Change station') - .addOptions(options[1]) - .addOptions(options[2]) - ); - - stations = null; - options = null; - - interaction.reply({ - content: '**Select station:**', - components: [menu], - ephemeral: true - }); + client.funcs.listStations(client, interaction); } else { let stations = `${client.stations.map(s => `**#** ${s.name}`).join('\n')}` const hashs = stations.split('**#**').length; diff --git a/src/client/commands/play.js b/src/client/commands/play.js index ac10c47..a1f9326 100644 --- a/src/client/commands/play.js +++ b/src/client/commands/play.js @@ -22,47 +22,7 @@ module.exports = { return interaction.reply(client.messageEmojis["error"] + message.errorToGetPlaylist); } - let stations = new Array(); - - let options = new Array(); - options[1] = new Array(); - options[2] = new Array(); - - stations[1] = client.stations.slice(0,24).forEach(station => { - station = { - label: station.name, - description: station.owner, - value: station.name - }; - options[1].push(station); - }); - - stations[2] = client.stations.slice(25).forEach(station => { - station = { - label: station.name, - description: station.owner, - value: station.name - }; - options[2].push(station); - }); - - const menu = new Discord.MessageActionRow() - .addComponents( - new Discord.MessageSelectMenu() - .setCustomId('play') - .setPlaceholder('Nothing selected') - .addOptions(options[1]) - .addOptions(options[2]) - ); - - stations = null; - options = null; - - return interaction.reply({ - content: '**Select station:**', - components: [menu], - ephemeral: true - }); + client.funcs.listStations(client, interaction); } let url = query ? query.replace(/<(.+)>/g, "$1") : ""; const radio = client.radio.get(interaction.guild.id); @@ -139,7 +99,7 @@ module.exports = { radio.station = station; radio.textChannel = interaction.channel; radio.startTime = date.getTime(); - client.funcs.play(interaction, interaction.guild, client, url, Discord); + client.funcs.play(interaction, interaction.guild, client, url); return; } @@ -165,7 +125,7 @@ module.exports = { construct.connection = connection; let date = new Date(); construct.startTime = date.getTime(); - client.funcs.play(interaction, interaction.guild, client, url, Discord); + client.funcs.play(interaction, interaction.guild, client, url); client.datastore.checkEntry(interaction.guild.id); construct.currentGuild = client.datastore.getEntry(interaction.guild.id); diff --git a/src/client/funcs/listStations.js b/src/client/funcs/listStations.js new file mode 100644 index 0000000..f410032 --- /dev/null +++ b/src/client/funcs/listStations.js @@ -0,0 +1,45 @@ +import Discord from "discord.js"; + +module.exports = function (client, interaction){ + let stations = new Array(); + + let options = new Array(); + options[1] = new Array(); + options[2] = new Array(); + + stations[1] = client.stations.slice(0,24).forEach(station => { + station = { + label: station.name, + description: station.owner, + value: station.name + }; + options[1].push(station); + }); + + stations[2] = client.stations.slice(25).forEach(station => { + station = { + label: station.name, + description: station.owner, + value: station.name + }; + options[2].push(station); + }); + + const menu = new Discord.MessageActionRow() + .addComponents( + new Discord.MessageSelectMenu() + .setCustomId('play') + .setPlaceholder('Nothing selected') + .addOptions(options[1]) + .addOptions(options[2]) + ); + + stations = null; + options = null; + + return interaction.reply({ + content: '**Select station:**', + components: [menu], + ephemeral: true + }); +} \ No newline at end of file From 16bc2aab52f96f7a89f5b91cfdb4f6e42498070d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Sun, 5 Sep 2021 03:12:23 +0300 Subject: [PATCH 17/30] Updated play function --- src/client/funcs/play.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/client/funcs/play.js b/src/client/funcs/play.js index 83f9729..24addeb 100644 --- a/src/client/funcs/play.js +++ b/src/client/funcs/play.js @@ -1,8 +1,9 @@ +import Discord from "discord.js"; const { createAudioResource } = require("@discordjs/voice"); -module.exports = async function play(interaction, guild, client, url, Discord) { +module.exports = async function play(interaction, guild, client, url) { let message = {}; const radio = client.radio.get(guild.id); const resource = createAudioResource(url); From 2d41c7a76b6ebb69c6771b985ebf2962a53cd38a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Sun, 5 Sep 2021 03:17:21 +0300 Subject: [PATCH 18/30] Updated commands and interactionCreate event --- src/client/commands/bug.js | 4 +++- src/client/commands/help.js | 4 +++- src/client/commands/invite.js | 4 +++- src/client/commands/list.js | 4 +++- src/client/commands/maintenance.js | 4 +++- src/client/commands/next.js | 2 +- src/client/commands/nowplaying.js | 4 +++- src/client/commands/play.js | 2 +- src/client/commands/prev.js | 2 +- src/client/commands/statistics.js | 4 +++- src/client/commands/status.js | 4 +++- src/client/commands/stop.js | 4 +++- src/client/events/interactionCreate.js | 6 ++---- 13 files changed, 32 insertions(+), 16 deletions(-) diff --git a/src/client/commands/bug.js b/src/client/commands/bug.js index 667a623..a87a638 100644 --- a/src/client/commands/bug.js +++ b/src/client/commands/bug.js @@ -1,9 +1,11 @@ +import Discord from "discord.js"; + module.exports = { name: 'bug', description: 'Report a bug', permission: 'none', category: 'info', - async execute(interaction, client, Discord, command) { + async execute(interaction, client) { let message = {}; message.bugTitle = client.messages.bugTitle.replace("%client.user.username%", client.user.username); diff --git a/src/client/commands/help.js b/src/client/commands/help.js index 9ed5e44..2b7da61 100644 --- a/src/client/commands/help.js +++ b/src/client/commands/help.js @@ -1,9 +1,11 @@ +import Discord from "discord.js"; + module.exports = { name: 'help', description: 'Get help using bot', permission: 'none', category: 'info', - execute(interaction, client, Discord, command) { + execute(interaction, client) { let message = {}; const categories = []; diff --git a/src/client/commands/invite.js b/src/client/commands/invite.js index a833c43..38db87a 100644 --- a/src/client/commands/invite.js +++ b/src/client/commands/invite.js @@ -1,9 +1,11 @@ +import Discord from "discord.js"; + module.exports = { name: 'invite', description: 'Invite Bot', permission: 'none', category: 'info', - execute(interaction, client, Discord, command) { + execute(interaction, client) { let message = {}; message.inviteTitle = client.messages.inviteTitle.replace("%client.user.username%", client.user.username); const embed = new Discord.MessageEmbed() diff --git a/src/client/commands/list.js b/src/client/commands/list.js index c6c7f34..b0ce3fd 100644 --- a/src/client/commands/list.js +++ b/src/client/commands/list.js @@ -1,9 +1,11 @@ +import Discord from "discord.js"; + module.exports = { name: 'list', description: 'List radio stations', permission: 'none', category: 'radio', - execute(interaction, client, Discord) { + execute(interaction, client) { let message = {}; if(!client.stations) { message.errorToGetPlaylist = client.messages.errorToGetPlaylist.replace("%client.config.supportGuild%", client.config.supportGuild); diff --git a/src/client/commands/maintenance.js b/src/client/commands/maintenance.js index 53085fe..9913f4d 100644 --- a/src/client/commands/maintenance.js +++ b/src/client/commands/maintenance.js @@ -1,9 +1,11 @@ +import Discord from "discord.js"; + module.exports = { name: 'maintenance', description: 'Bot Maintenance', permission: 'none', category: 'info', - execute(interaction, client, Discord, command) { + execute(interaction, client) { let message = {}; if(!client.funcs.isDev(client.config.devId, interaction.user.id)) return interaction.reply(client.messageEmojis["error"] + client.messages.notAllowed); diff --git a/src/client/commands/next.js b/src/client/commands/next.js index cadeb34..3570995 100644 --- a/src/client/commands/next.js +++ b/src/client/commands/next.js @@ -3,7 +3,7 @@ module.exports = { description: 'Next Station', permission: 'none', category: 'info', - async execute(interaction, client, Discord) { + async execute(interaction, client) { let message = {}; const radio = client.radio.get(interaction.guild.id); if (!radio) return interaction.reply({ diff --git a/src/client/commands/nowplaying.js b/src/client/commands/nowplaying.js index 2e335fb..f5fc153 100644 --- a/src/client/commands/nowplaying.js +++ b/src/client/commands/nowplaying.js @@ -1,9 +1,11 @@ +import Discord from "discord.js"; + module.exports = { name: 'nowplaying', description: 'Current Radio Station', permission: 'none', category: 'radio', - async execute(interaction, client, Discord) { + async execute(interaction, client) { let message = {}; const radio = client.radio.get(interaction.guild.id); if (!radio) return interaction.reply({ diff --git a/src/client/commands/play.js b/src/client/commands/play.js index a1f9326..d8960fe 100644 --- a/src/client/commands/play.js +++ b/src/client/commands/play.js @@ -13,7 +13,7 @@ module.exports = { ], permission: "none", category: "radio", - async execute(interaction, client, Discord, command) { + async execute(interaction, client) { let message = {}; let query = interaction.options?.getString("query") ?? interaction.values?.[0]; if(!query){ diff --git a/src/client/commands/prev.js b/src/client/commands/prev.js index 476dc28..6b37ab7 100644 --- a/src/client/commands/prev.js +++ b/src/client/commands/prev.js @@ -3,7 +3,7 @@ module.exports = { description: 'Previous Station', permission: 'none', category: 'info', - async execute(interaction, client, Discord) { + async execute(interaction, client) { let message = {}; const radio = client.radio.get(interaction.guild.id); if (!radio) return interaction.reply({ diff --git a/src/client/commands/statistics.js b/src/client/commands/statistics.js index 2a71ed8..02886fe 100644 --- a/src/client/commands/statistics.js +++ b/src/client/commands/statistics.js @@ -1,9 +1,11 @@ +import Discord from "discord.js"; + module.exports = { name: 'statistics', description: 'Show statistics', permission: 'none', category: 'info', - execute(interaction, client, Discord) { + execute(interaction, client) { let message = {}; let stations = client.stations; let currentGuild = client.datastore.getEntry(interaction.guild.id); diff --git a/src/client/commands/status.js b/src/client/commands/status.js index 078cd02..6a3ce7b 100644 --- a/src/client/commands/status.js +++ b/src/client/commands/status.js @@ -1,9 +1,11 @@ +import Discord from "discord.js"; + module.exports = { name: 'status', description: 'Bot Status', permission: 'none', category: 'info', - async execute(interaction, client, Discord) { + async execute(interaction, client) { let message = {}; message.statusTitle = client.messages.statusTitle.replace("%client.user.username%", client.user.username); diff --git a/src/client/commands/stop.js b/src/client/commands/stop.js index c12cb9c..8f09b77 100644 --- a/src/client/commands/stop.js +++ b/src/client/commands/stop.js @@ -1,9 +1,11 @@ +import Discord from "discord.js"; + module.exports = { name: 'stop', description: 'Stop radio', permission: 'none', category: 'radio', - async execute(interaction, client, Discord) { + async execute(interaction, client) { const radio = client.radio.get(interaction.guild.id); if (client.funcs.check(client, interaction, command)) { client.funcs.statisticsUpdate(client, interaction.guild, radio); diff --git a/src/client/events/interactionCreate.js b/src/client/events/interactionCreate.js index b069289..4261d50 100644 --- a/src/client/events/interactionCreate.js +++ b/src/client/events/interactionCreate.js @@ -1,5 +1,3 @@ -import Discord from "discord.js"; - module.exports = { name: 'interactionCreate', async execute(client, interaction) { @@ -13,7 +11,7 @@ module.exports = { if (!command) return; try { - command.execute(interaction, client, Discord); + command.execute(interaction, client); } catch (error) { interaction.reply({ content: client.messages.runningCommandFailed, @@ -27,7 +25,7 @@ module.exports = { if (!command) return; try { - command.execute(interaction, client, Discord); + command.execute(interaction, client); } catch (error) { interaction.reply({ content: client.messages.runningCommandFailed, From 38a8571ddcd8ca4748db58a5c09679dd6f84f8a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Sun, 5 Sep 2021 03:33:15 +0300 Subject: [PATCH 19/30] Updated nowplaying command --- src/client/commands/nowplaying.js | 55 +++++++++++++------------------ 1 file changed, 23 insertions(+), 32 deletions(-) diff --git a/src/client/commands/nowplaying.js b/src/client/commands/nowplaying.js index f5fc153..df0328f 100644 --- a/src/client/commands/nowplaying.js +++ b/src/client/commands/nowplaying.js @@ -6,40 +6,31 @@ module.exports = { permission: 'none', category: 'radio', async execute(interaction, client) { - let message = {}; - const radio = client.radio.get(interaction.guild.id); - if (!radio) return interaction.reply({ - content: 'There is nothing playing.', - ephemeral: true - }); - if(!client.stations) { - message.errorToGetPlaylist = client.messages.errorToGetPlaylist.replace("%client.config.supportGuild%", client.config.supportGuild); - return interaction.reply({ - content: client.messageEmojis["error"] + message.errorToGetPlaylist, + if (client.funcs.check(client, interaction, command)) { + let message = {}; + const radio = client.radio.get(interaction.guild.id); + + let date = new Date(); + radio.currentTime = date.getTime(); + radio.playTime = parseInt(radio.currentTime)-parseInt(radio.startTime); + const completed = (radio.playTime); + + 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("%client.funcs.msToTime(completed)%", client.funcs.msToTime(completed)); + + const embed = new Discord.MessageEmbed() + .setTitle(client.messages.nowplayingTitle) + .setThumbnail((radio.station.logo || "https://cdn.discordapp.com/emojis/" + client.messageEmojis["play"].replace(/[^0-9]+/g, ''))) + .setColor(client.config.embedColor) + .setDescription(message.nowplayingDescription) + .setImage('https://waren.io/berriabot-temp-sa7a36a9xm6837br/images/empty-3.png') + .setFooter(client.messages.footerText, "https://cdn.discordapp.com/emojis/" + client.messageEmojis["eximiabots"].replace(/[^0-9]+/g, '')); + + interaction.reply({ + embeds: [embed], ephemeral: true }); } - - let date = new Date(); - radio.currentTime = date.getTime(); - radio.playTime = parseInt(radio.currentTime)-parseInt(radio.startTime); - const completed = (radio.playTime); - - 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("%client.funcs.msToTime(completed)%", client.funcs.msToTime(completed)); - - const embed = new Discord.MessageEmbed() - .setTitle(client.messages.nowplayingTitle) - .setThumbnail((radio.station.logo || "https://cdn.discordapp.com/emojis/" + client.messageEmojis["play"].replace(/[^0-9]+/g, ''))) - .setColor(client.config.embedColor) - .setDescription(message.nowplayingDescription) - .setImage('https://waren.io/berriabot-temp-sa7a36a9xm6837br/images/empty-3.png') - .setFooter(client.messages.footerText, "https://cdn.discordapp.com/emojis/" + client.messageEmojis["eximiabots"].replace(/[^0-9]+/g, '')); - - interaction.reply({ - embeds: [embed], - ephemeral: true - }); } }; \ No newline at end of file From ea2be5d5fb09637d20ac10015c221726ccf3385e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Sun, 5 Sep 2021 03:33:48 +0300 Subject: [PATCH 20/30] Updated check function --- src/client/funcs/check.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/client/funcs/check.js b/src/client/funcs/check.js index e7987ed..5e8222f 100644 --- a/src/client/funcs/check.js +++ b/src/client/funcs/check.js @@ -2,6 +2,13 @@ module.exports = function (client, interaction, command) { let message = {}; const radio = client.radio.get(interaction.guild.id); const permissions = interaction.channel.permissionsFor(interaction.user); + if(!client.stations) { + message.errorToGetPlaylist = client.messages.errorToGetPlaylist.replace("%client.config.supportGuild%", client.config.supportGuild); + return interaction.reply({ + content: client.messageEmojis["error"] + message.errorToGetPlaylist, + ephemeral: true + }); + } if (!radio) { interaction.reply({ content: client.messageEmojis["error"] + client.messages.notPlaying, From 534bc74936f448ff4d99c3aafed6c2d14b0df0d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Sun, 5 Sep 2021 03:37:03 +0300 Subject: [PATCH 21/30] Updated code --- src/client/commands/next.js | 19 ++++--------------- src/client/commands/nowplaying.js | 2 +- src/client/commands/prev.js | 17 +++-------------- src/client/commands/stop.js | 2 +- src/client/events/interactionCreate.js | 2 +- 5 files changed, 10 insertions(+), 32 deletions(-) diff --git a/src/client/commands/next.js b/src/client/commands/next.js index 3570995..c49d8b6 100644 --- a/src/client/commands/next.js +++ b/src/client/commands/next.js @@ -3,21 +3,10 @@ module.exports = { description: 'Next Station', permission: 'none', category: 'info', - async execute(interaction, client) { - let message = {}; - const radio = client.radio.get(interaction.guild.id); - if (!radio) return interaction.reply({ - content: 'There is nothing playing.', - ephemeral: true - }); - if(!client.stations) { - message.errorToGetPlaylist = client.messages.errorToGetPlaylist.replace("%client.config.supportGuild%", client.config.supportGuild); - return interaction.reply({ - content: client.messageEmojis["error"] + message.errorToGetPlaylist, - ephemeral: true - }); + async execute(interaction, client, command) { + if (client.funcs.check(client, interaction, command)) { + const radio = client.radio.get(interaction.guild.id); + console.log(client.stations.find(station => station.name == radio.station.name)); } - - } } \ No newline at end of file diff --git a/src/client/commands/nowplaying.js b/src/client/commands/nowplaying.js index df0328f..e6b2e62 100644 --- a/src/client/commands/nowplaying.js +++ b/src/client/commands/nowplaying.js @@ -5,7 +5,7 @@ module.exports = { description: 'Current Radio Station', permission: 'none', category: 'radio', - async execute(interaction, client) { + async execute(interaction, client, command) { if (client.funcs.check(client, interaction, command)) { let message = {}; const radio = client.radio.get(interaction.guild.id); diff --git a/src/client/commands/prev.js b/src/client/commands/prev.js index 6b37ab7..a7646e2 100644 --- a/src/client/commands/prev.js +++ b/src/client/commands/prev.js @@ -4,20 +4,9 @@ module.exports = { permission: 'none', category: 'info', async execute(interaction, client) { - let message = {}; - const radio = client.radio.get(interaction.guild.id); - if (!radio) return interaction.reply({ - content: 'There is nothing playing.', - ephemeral: true - }); - if(!client.stations) { - message.errorToGetPlaylist = client.messages.errorToGetPlaylist.replace("%client.config.supportGuild%", client.config.supportGuild); - return interaction.reply({ - content: client.messageEmojis["error"] + message.errorToGetPlaylist, - ephemeral: true - }); + if (client.funcs.check(client, interaction, command)) { + const radio = client.radio.get(interaction.guild.id); + console.log(client.stations.find(station => station.name == radio.station.name)); } - - } } \ No newline at end of file diff --git a/src/client/commands/stop.js b/src/client/commands/stop.js index 8f09b77..9c53249 100644 --- a/src/client/commands/stop.js +++ b/src/client/commands/stop.js @@ -5,7 +5,7 @@ module.exports = { description: 'Stop radio', permission: 'none', category: 'radio', - async execute(interaction, client) { + async execute(interaction, client, command) { const radio = client.radio.get(interaction.guild.id); if (client.funcs.check(client, interaction, command)) { client.funcs.statisticsUpdate(client, interaction.guild, radio); diff --git a/src/client/events/interactionCreate.js b/src/client/events/interactionCreate.js index 4261d50..b917b3b 100644 --- a/src/client/events/interactionCreate.js +++ b/src/client/events/interactionCreate.js @@ -25,7 +25,7 @@ module.exports = { if (!command) return; try { - command.execute(interaction, client); + command.execute(interaction, client, command); } catch (error) { interaction.reply({ content: client.messages.runningCommandFailed, From 38af503626f64cb692252498a5f43c75ac0a9532 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Sun, 5 Sep 2021 03:44:28 +0300 Subject: [PATCH 22/30] Fixed bug replated to sending error message in interactionCreate.js --- src/client/events/interactionCreate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/events/interactionCreate.js b/src/client/events/interactionCreate.js index b917b3b..64e06b9 100644 --- a/src/client/events/interactionCreate.js +++ b/src/client/events/interactionCreate.js @@ -3,7 +3,7 @@ module.exports = { async execute(client, interaction) { const permissions = interaction.channel.permissionsFor(interaction.client.user); - if (!permissions.has('EMBED_LINKS')) return interaction.send(client.messages.noPermsEmbed); + if (!permissions.has('EMBED_LINKS')) return interaction.reply(client.messages.noPermsEmbed); if(interaction.isCommand()){ const commandName = interaction.commandName; From 7e3a83743de2889accdef301c6915fc8f92c0769 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Sun, 5 Sep 2021 04:36:32 +0300 Subject: [PATCH 23/30] Disabled removing commands when bot is going offline --- src/client/events/SIGINT.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/client/events/SIGINT.js b/src/client/events/SIGINT.js index 59495c7..52ed167 100644 --- a/src/client/events/SIGINT.js +++ b/src/client/events/SIGINT.js @@ -35,7 +35,7 @@ module.exports = { radio = currentRadios.next(); } - const rest = new REST({ version: '9' }).setToken(token); + /*const rest = new REST({ version: '9' }).setToken(token); if(version.includes("-dev")){ await rest.put( Routes.applicationCommands(client.user.id), @@ -47,13 +47,13 @@ module.exports = { try { await rest.put( Routes.applicationGuildCommands(client.user.id, guild.id), - { body: [] }, + { body: [] } ); } catch (DiscordAPIError) { } }); - } + }*/ setInterval(() => { if(radio.done){ From 11573a5113caa803258fcd2727dd048993e7aa13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Sun, 5 Sep 2021 04:41:53 +0300 Subject: [PATCH 24/30] Updated commands.js --- src/client/commands.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/client/commands.js b/src/client/commands.js index 078a8ee..a1a8a14 100644 --- a/src/client/commands.js +++ b/src/client/commands.js @@ -44,16 +44,17 @@ module.exports = { try { await rest.put( Routes.applicationGuildCommands(client.user.id, guild.id), - { body: commands }, + { body: commands } ); + client.funcs.logger('Slash Commands', 'Guild Applications – Successful' + "\n" + guild.id + " / " + guild.name); } catch (DiscordAPIError) { - + client.funcs.logger('Slash Commands', 'Guild Applications – Failed' + "\n" + guild.id + " / " + guild.name); } }); } else { await rest.put( Routes.applicationCommands(client.user.id), - { body: commands }, + { body: commands } ); } From 8fdcdd0116b23de1b8adfe17f0bd9ccbb86aa10f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Sun, 5 Sep 2021 04:42:11 +0300 Subject: [PATCH 25/30] Updated next & prev command --- src/client/commands/next.js | 13 ++++++++++++- src/client/commands/prev.js | 13 ++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/client/commands/next.js b/src/client/commands/next.js index c49d8b6..da92e5a 100644 --- a/src/client/commands/next.js +++ b/src/client/commands/next.js @@ -6,7 +6,18 @@ module.exports = { async execute(interaction, client, command) { if (client.funcs.check(client, interaction, command)) { const radio = client.radio.get(interaction.guild.id); - console.log(client.stations.find(station => station.name == radio.station.name)); + let station = client.stations[client.stations.findIndex(station => station.name == radio.station.name) + 1]; + + client.funcs.statisticsUpdate(client, interaction.guild, radio); + radio.audioPlayer.stop(); + + let date = new Date(); + radio.station = station; + radio.textChannel = interaction.channel; + radio.startTime = date.getTime(); + client.funcs.play(interaction, interaction.guild, client, url); + + return; } } } \ No newline at end of file diff --git a/src/client/commands/prev.js b/src/client/commands/prev.js index a7646e2..9e698d4 100644 --- a/src/client/commands/prev.js +++ b/src/client/commands/prev.js @@ -6,7 +6,18 @@ module.exports = { async execute(interaction, client) { if (client.funcs.check(client, interaction, command)) { const radio = client.radio.get(interaction.guild.id); - console.log(client.stations.find(station => station.name == radio.station.name)); + let station = client.stations[client.stations.findIndex(station => station.name == radio.station.name) - 1]; + + client.funcs.statisticsUpdate(client, interaction.guild, radio); + radio.audioPlayer.stop(); + + let date = new Date(); + radio.station = station; + radio.textChannel = interaction.channel; + radio.startTime = date.getTime(); + client.funcs.play(interaction, interaction.guild, client, url); + + return; } } } \ No newline at end of file From dfada15b007ed47bba6b1b27728ea30b24481049 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Sun, 5 Sep 2021 05:41:13 +0300 Subject: [PATCH 26/30] Updated next command --- src/client/commands/next.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/client/commands/next.js b/src/client/commands/next.js index da92e5a..a8a2e9d 100644 --- a/src/client/commands/next.js +++ b/src/client/commands/next.js @@ -6,8 +6,21 @@ module.exports = { async execute(interaction, client, command) { if (client.funcs.check(client, interaction, command)) { const radio = client.radio.get(interaction.guild.id); - let station = client.stations[client.stations.findIndex(station => station.name == radio.station.name) + 1]; + let index = client.stations.findIndex(station => station.name == radio.station.name) + 1; + if(index == client.stations.length) index = 0; + + let station = client.stations[index]; + + if(!station) return interaction.reply({ + content: client.messageEmojis["error"] + client.messages.noSearchResults, + ephemeral: true + }); + + interaction.deferUpdate(); + + let url = station.stream[station.stream.default]; + client.funcs.statisticsUpdate(client, interaction.guild, radio); radio.audioPlayer.stop(); @@ -15,9 +28,8 @@ module.exports = { radio.station = station; radio.textChannel = interaction.channel; radio.startTime = date.getTime(); - client.funcs.play(interaction, interaction.guild, client, url); + client.funcs.play(null, interaction.guild, client, url); - return; } } } \ No newline at end of file From 933140502d6a1e00c5e627be0a3bf220afb92c01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Sun, 5 Sep 2021 05:41:22 +0300 Subject: [PATCH 27/30] Updated prev command --- src/client/commands/prev.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/client/commands/prev.js b/src/client/commands/prev.js index 9e698d4..148961a 100644 --- a/src/client/commands/prev.js +++ b/src/client/commands/prev.js @@ -3,10 +3,23 @@ module.exports = { description: 'Previous Station', permission: 'none', category: 'info', - async execute(interaction, client) { + async execute(interaction, client, command) { if (client.funcs.check(client, interaction, command)) { const radio = client.radio.get(interaction.guild.id); - let station = client.stations[client.stations.findIndex(station => station.name == radio.station.name) - 1]; + + let index = client.stations.findIndex(station => station.name == radio.station.name) - 1; + if(index == -1) index = client.stations.length - 1; + + let station = client.stations[index]; + + if(!station) return interaction.reply({ + content: client.messageEmojis["error"] + client.messages.noSearchResults, + ephemeral: true + }); + + interaction.deferUpdate(); + + let url = station.stream[station.stream.default]; client.funcs.statisticsUpdate(client, interaction.guild, radio); radio.audioPlayer.stop(); @@ -15,9 +28,8 @@ module.exports = { radio.station = station; radio.textChannel = interaction.channel; radio.startTime = date.getTime(); - client.funcs.play(interaction, interaction.guild, client, url); + client.funcs.play(null, interaction.guild, client, url); - return; } } } \ No newline at end of file From b280981e1c2fcdac328530854657da2cdc856b1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Sun, 5 Sep 2021 06:15:54 +0300 Subject: [PATCH 28/30] Updated statistics command --- src/client/commands/statistics.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/client/commands/statistics.js b/src/client/commands/statistics.js index 02886fe..b96ef04 100644 --- a/src/client/commands/statistics.js +++ b/src/client/commands/statistics.js @@ -9,6 +9,7 @@ module.exports = { let message = {}; let stations = client.stations; let currentGuild = client.datastore.getEntry(interaction.guild.id); + let global = client.datastore.getEntry("global"); let statistics = ""; if(!client.stations) { @@ -21,9 +22,13 @@ module.exports = { } else { Object.keys(stations).forEach(function(station) { if(currentGuild.statistics[stations[station].name] && currentGuild.statistics[stations[station].name].time && parseInt(currentGuild.statistics[stations[station].name].time) > 0 && currentGuild.statistics[stations[station].name].used && parseInt(currentGuild.statistics[stations[station].name].used) > 0){ - statistics += `**${parseInt(station) + 1}** ` + stations[station].name + " \n"; - statistics += "Time: " + client.funcs.msToTime(currentGuild.statistics[stations[station].name].time) + "\n"; - statistics += "Used: " + currentGuild.statistics[stations[station].name].used + "\n"; + statistics += `**${parseInt(station) + 1}. ` + stations[station].name + "** \n"; + if(global && global.statistics[stations[station].name] && global.statistics[stations[station].name].time && parseInt(global.statistics[stations[station].name].time) > 0 && global.statistics[stations[station].name].used && parseInt(global.statistics[stations[station].name].used) > 0){ + statistics += "Guild – Time: " + client.funcs.msToTime(currentGuild.statistics[stations[station].name].time) + " (" + ((currentGuild.statistics[stations[station].name].time / global.statistics[stations[station].name].time) * 100) + "%" + ")" + " / " + "Used: " + currentGuild.statistics[stations[station].name].used + " (" + ((currentGuild.statistics[stations[station].name].used / global.statistics[stations[station].name].used) * 100) + "%" + ")" + "\n"; + statistics += "Global – Time: " + client.funcs.msToTime(global.statistics[stations[station].name].time) + " / " + "Used: " + global.statistics[stations[station].name].used + "\n\n"; + } else { + statistics += "Time: " + client.funcs.msToTime(currentGuild.statistics[stations[station].name].time) + " / " + "Used: " + currentGuild.statistics[stations[station].name].used + "\n\n"; + } } }); } From 479c0ee13d691e305de3adeeaf50b4eb586efdb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Sun, 5 Sep 2021 06:22:47 +0300 Subject: [PATCH 29/30] Fixed check function --- src/client/funcs/check.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/client/funcs/check.js b/src/client/funcs/check.js index 5e8222f..38fe48a 100644 --- a/src/client/funcs/check.js +++ b/src/client/funcs/check.js @@ -4,10 +4,11 @@ module.exports = function (client, interaction, command) { const permissions = interaction.channel.permissionsFor(interaction.user); if(!client.stations) { message.errorToGetPlaylist = client.messages.errorToGetPlaylist.replace("%client.config.supportGuild%", client.config.supportGuild); - return interaction.reply({ + interaction.reply({ content: client.messageEmojis["error"] + message.errorToGetPlaylist, ephemeral: true }); + return false; } if (!radio) { interaction.reply({ From 7a0a3e0d50d933782ebae5be077de92c15610c80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Sun, 5 Sep 2021 06:26:34 +0300 Subject: [PATCH 30/30] Updated category in next and prev command --- src/client/commands/next.js | 2 +- src/client/commands/prev.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client/commands/next.js b/src/client/commands/next.js index a8a2e9d..56747d3 100644 --- a/src/client/commands/next.js +++ b/src/client/commands/next.js @@ -2,7 +2,7 @@ module.exports = { name: 'next', description: 'Next Station', permission: 'none', - category: 'info', + category: 'radio', async execute(interaction, client, command) { if (client.funcs.check(client, interaction, command)) { const radio = client.radio.get(interaction.guild.id); diff --git a/src/client/commands/prev.js b/src/client/commands/prev.js index 148961a..eb7e572 100644 --- a/src/client/commands/prev.js +++ b/src/client/commands/prev.js @@ -2,7 +2,7 @@ module.exports = { name: 'prev', description: 'Previous Station', permission: 'none', - category: 'info', + category: 'radio', async execute(interaction, client, command) { if (client.funcs.check(client, interaction, command)) { const radio = client.radio.get(interaction.guild.id);