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] 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