aboutsummaryrefslogtreecommitdiff
path: root/commands
diff options
context:
space:
mode:
Diffstat (limited to 'commands')
-rw-r--r--commands/control.js51
-rw-r--r--commands/stop.js17
2 files changed, 29 insertions, 39 deletions
diff --git a/commands/control.js b/commands/control.js
index 28c3aad..7f5e9cb 100644
--- a/commands/control.js
+++ b/commands/control.js
@@ -21,17 +21,18 @@
import { SlashCommandBuilder } from '@discordjs/builders'
import { MessageEmbed, MessageActionRow, MessageButton } from 'discord.js'
-import { audio, player, playAudio, destroyAudio, voiceInit } from '../AudioBackend.js'
-
+import { audio, player, playAudio, destroyAudio, voiceInit, stopBot } from '../AudioBackend.js'
import config from '../config.json' assert {type: 'json'}
+export let controlEmbed
+
export default {
data: new SlashCommandBuilder()
.setName('control')
.setDescription('Controlling the music'),
async execute(interaction, bot) {
if (![config.botOwner].includes(interaction.user.id)) return await interaction.reply({ content: "You do not have permissions to execute this command.", ephemeral: true });
- const controlEmbed = new MessageEmbed()
+ controlEmbed = new MessageEmbed()
.setAuthor({name: `${bot.user.username} Control Panel`, iconURL: bot.user.avatarURL()})
.addField('State', 'Playing')
.addField('Currently Playing', audio)
@@ -50,21 +51,25 @@ export default {
.setCustomId('play'),
new MessageButton()
.setStyle('PRIMARY')
- .setLabel('Pause') //TODO: possibly toggle button instead
+ .setLabel('Pause')
.setCustomId('pause'),
new MessageButton()
- .setStyle('SECONDARY')
+ .setStyle('DANGER')
.setLabel('Skip')
.setCustomId('skip'),
new MessageButton()
.setStyle('SECONDARY')
- .setLabel('More')
- .setCustomId('soon'),
+ .setLabel('>>')
+ .setCustomId('more'),
);
const controlButtons2 = new MessageActionRow()
.addComponents(
new MessageButton()
+ .setStyle('SECONDARY')
+ .setLabel('<<')
+ .setCustomId('less'),
+ new MessageButton()
.setStyle('DANGER')
.setLabel('Leave')
.setCustomId('leave'),
@@ -74,7 +79,9 @@ export default {
.setCustomId('stop')
)
- const collector = interaction.channel.createMessageComponentCollector();
+ const filter = i => i.user.id === config.botOwner;
+
+ const collector = interaction.channel.createMessageComponentCollector({filter});
collector.on('collect', async ctlButton => {
if (ctlButton.customId === 'join') {
@@ -82,18 +89,24 @@ export default {
voiceInit(bot);
}
if (ctlButton.customId === 'play') {
- player.unpause();
await ctlButton.reply({content:'Resuming music', ephemeral:true})
+ player.unpause();
}
if (ctlButton.customId === 'pause') {
- player.pause();
await ctlButton.reply({content:'Pausing music', ephemeral:true})
+ player.pause();
}
if (ctlButton.customId === 'skip') {
- player.pause();
await ctlButton.reply({content:`Skipping \`${audio}\`...`, ephemeral:true})
+ player.pause();
playAudio(bot);
}
+ if (ctlButton.customId === 'more') {
+ await interaction.editReply({ components: [controlButtons2] });
+ }
+ if (ctlButton.customId === 'less') {
+ await interaction.editReply({ components: [controlButtons] });
+ }
if (ctlButton.customId === 'leave') {
await ctlButton.reply({content:'Leaving voice channel.', ephemeral:true})
console.log('Leaving voice channel...');
@@ -101,22 +114,12 @@ export default {
}
if (ctlButton.customId === 'stop') {
await ctlButton.reply({content:'Powering off...', ephemeral:true})
-
- const statusEmbed = new MessageEmbed()
- .setAuthor({name:bot.user.username, iconURL:bot.user.avatarURL()})
- .setDescription(`That\'s all folks! Powering down ${bot.user.username}...`)
- .setColor('#0066ff')
- let statusChannel = bot.channels.cache.get(config.statusChannel);
- if (!statusChannel) return console.error('The status channel does not exist! Skipping.');
- await statusChannel.send({ embeds: [statusEmbed] });
-
- console.log('Powering off...');
- destroyAudio(interaction);
- bot.destroy();
- process.exit(0);
+ await stopBot(bot, interaction);
}
});
+ collector.on('end', collected => console.log(`Collected ${collected.size} items`));
+
return interaction.reply({embeds:[controlEmbed], components:[controlButtons]});
},
}; \ No newline at end of file
diff --git a/commands/stop.js b/commands/stop.js
index 62f4b1a..f1bd8eb 100644
--- a/commands/stop.js
+++ b/commands/stop.js
@@ -20,9 +20,8 @@
***************************************************************************/
import { SlashCommandBuilder } from '@discordjs/builders'
-import { MessageEmbed } from "discord.js";
import config from '../config.json' assert {type: 'json'}
-import { destroyAudio } from "../AudioBackend.js";
+import { stopBot } from "../AudioBackend.js";
export default {
data: new SlashCommandBuilder()
@@ -31,18 +30,6 @@ export default {
async execute(interaction, bot) {
if (![config.botOwner].includes(interaction.user.id)) return await interaction.reply({ content: "You do not have permissions to execute this command.", ephemeral: true });
await interaction.reply('Powering off...')
-
- const statusEmbed = new MessageEmbed()
- .setAuthor({name:bot.user.username, iconURL:bot.user.avatarURL()})
- .setDescription(`That\'s all folks! Powering down ${bot.user.username}...`)
- .setColor('#0066ff')
- let statusChannel = bot.channels.cache.get(config.statusChannel);
- if (!statusChannel) return console.error('The status channel does not exist! Skipping.');
- await statusChannel.send({ embeds: [statusEmbed] });
-
- console.log('Powering off...');
- destroyAudio(interaction);
- bot.destroy();
- process.exit(0);
+ await stopBot(bot, interaction);
},
}; \ No newline at end of file