diff options
| author | Andrew Lee <alee14498@protonmail.com> | 2022-07-05 23:08:59 -0400 |
|---|---|---|
| committer | Andrew Lee <alee14498@protonmail.com> | 2022-07-05 23:08:59 -0400 |
| commit | 1e294d91c3eab7e65936010c8f0c81c4c4f73b96 (patch) | |
| tree | 26d3310e2df215bdc621e116ad97ed93ab0dab35 | |
| parent | 7630b6ca8445cc8f6fc5dfb5284ab23b7c26be46 (diff) | |
| download | DLAP-1e294d91c3eab7e65936010c8f0c81c4c4f73b96.tar.gz DLAP-1e294d91c3eab7e65936010c8f0c81c4c4f73b96.tar.bz2 DLAP-1e294d91c3eab7e65936010c8f0c81c4c4f73b96.zip | |
Removed help; Updated all the new commands; Finally removed final control panel code
| -rw-r--r-- | AudioBackend.js | 131 | ||||
| -rw-r--r-- | bot.js | 1 | ||||
| -rw-r--r-- | commands/help.js | 41 | ||||
| -rw-r--r-- | commands/join.js | 1 | ||||
| -rw-r--r-- | commands/pause.js | 14 | ||||
| -rw-r--r-- | commands/play.js | 17 | ||||
| -rw-r--r-- | commands/skip.js | 4 | ||||
| -rw-r--r-- | commands/stop.js | 1 | ||||
| -rw-r--r-- | deploy-command.js | 2 |
9 files changed, 26 insertions, 186 deletions
diff --git a/AudioBackend.js b/AudioBackend.js index bf4210f..15fa45e 100644 --- a/AudioBackend.js +++ b/AudioBackend.js @@ -37,7 +37,7 @@ let fileData; let runOnce = false export let playerState; -let isAudioStatePaused; +export let isAudioStatePaused; export async function voiceInit(bot) { bot.channels.fetch(config.voiceChannel).then(async channel => { @@ -65,135 +65,6 @@ export async function voiceInit(bot) { }).catch(e => { console.error(e) }) } -export async function controlPanel(interaction, bot) { - let controlEmbed - let controlButtons - let controlButtons2 - - if (runOnce === true) return await interaction.reply({content:'You already executed this command', ephemeral:true}) - - controlEmbed = new MessageEmbed() - .setAuthor({name: `${bot.user.username} Control Panel`, iconURL: bot.user.avatarURL()}) - .addField('State', playerState) - .addField('Currently Playing', audio) - //.addField('Next Music', '(a possible feature when queue system is implemented?)') - .setColor('#0066ff') - - controlButtons = new MessageActionRow() - .addComponents( - new MessageButton() - .setStyle('SUCCESS') - .setLabel('Join') - .setCustomId('join') - .setEmoji('⬆️') - .setDisabled(true), - new MessageButton() - .setStyle('SECONDARY') - .setLabel('Play') - .setCustomId('play') - .setEmoji('▶️') - .setDisabled(true), - new MessageButton() - .setStyle('SECONDARY') - .setLabel('Pause') - .setCustomId('pause') - .setEmoji('⏸️'), - new MessageButton() - .setStyle('SECONDARY') - .setLabel('Skip') - .setCustomId('skip') - .setEmoji('⏭️'), - new MessageButton() - .setStyle('PRIMARY') - .setEmoji('⏩') - .setCustomId('next'), - ); - - controlButtons2 = new MessageActionRow() - .addComponents( - new MessageButton() - .setStyle('PRIMARY') - .setEmoji('⏪') - .setCustomId('back'), - new MessageButton() - .setStyle('DANGER') - .setLabel('Leave') - .setCustomId('leave') - .setEmoji('⏏️'), - new MessageButton() - .setStyle('DANGER') - .setLabel('Power Off') - .setCustomId('stop') - .setEmoji('🛑') - ) - - const filter = i => i.user.id === config.botOwner; - - const collector = interaction.channel.createMessageComponentCollector({filter}); - - collector.on('collect', async ctlButton => { - if (ctlButton.customId === 'join') { - controlButtons.components[0].setDisabled(true); - controlButtons.components[1].setDisabled(true); - controlButtons.components[2].setDisabled(false); - controlButtons.components[3].setDisabled(false); - controlButtons2.components[1].setDisabled(false); - await interaction.editReply({components:[controlButtons]}); - await voiceInit(bot); - return await ctlButton.reply({content:'Joining voice channel', ephemeral:true}); - } - if (ctlButton.customId === 'play') { - controlButtons.components[2].setDisabled(false); - controlButtons.components[1].setDisabled(true); - await interaction.editReply({components:[controlButtons]}); - audioState(); - player.unpause(); - return await ctlButton.reply({content:'Resuming music', ephemeral:true}); - } - if (ctlButton.customId === 'pause') { - controlButtons.components[2].setDisabled(true); - controlButtons.components[1].setDisabled(false); - await interaction.editReply({components:[controlButtons]}); - audioState(); - player.pause(); - return await ctlButton.reply({content:'Pausing music', ephemeral:true}); - } - if (ctlButton.customId === 'skip') { - player.stop(); - await searchAudio(bot, interaction); - return await ctlButton.reply({content:`Skipping ${audio}`, ephemeral:true}); - } - if (ctlButton.customId === 'next') { - return await interaction.editReply({ components: [controlButtons2] }).then(ctlButton.deferUpdate()); - } - if (ctlButton.customId === 'back') { - return await interaction.editReply({ components: [controlButtons] }).then(ctlButton.deferUpdate()); - } - if (ctlButton.customId === 'leave') { - console.log('Leaving voice channel...'); - controlButtons.components[0].setDisabled(false); - controlButtons.components[1].setDisabled(true); - controlButtons.components[2].setDisabled(true); - controlButtons.components[3].setDisabled(true); - controlButtons2.components[1].setDisabled(true); - await interaction.editReply({components:[controlButtons2]}); - await destroyAudio(interaction); - return await ctlButton.reply({content:'Leaving voice channel', ephemeral:true}); - } - if (ctlButton.customId === 'stop') { - await ctlButton.reply({content:`Powering off ${bot.user.username}...`, ephemeral:true}); - await interaction.deleteReply(); - await collector.stop(); - return await stopBot(bot, interaction); - } - }); - - collector.on('end', collected => console.log(`Collected ${collected.size} items`)); - - runOnce = true - return await interaction.reply({embeds:[controlEmbed], components:[controlButtons]}); -} - export async function searchAudio(bot){ //TODO: Eventually this system will need a rework so it won't repeat the same files. @@ -33,7 +33,6 @@ bot.login(config.token); * New queue system * Shuffle or "Play by order" mode * Audio streaming - * Attempt to disable buttons (for control command) for regular users */ // Slash Command Handler diff --git a/commands/help.js b/commands/help.js deleted file mode 100644 index ec0283c..0000000 --- a/commands/help.js +++ /dev/null @@ -1,41 +0,0 @@ -/************************************************************************** - * - * DLAP Bot: A Discord bot that plays local audio tracks. - * (C) Copyright 2022 - * Programmed by Andrew Lee - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <https://www.gnu.org/licenses/>. - * - ***************************************************************************/ - -import { SlashCommandBuilder } from '@discordjs/builders' -import { MessageEmbed } from 'discord.js' -import { audio } from '../AudioBackend.js' - -export default { - data: new SlashCommandBuilder() - .setName('help') - .setDescription('Displays commands'), - async execute(interaction, bot) { - const helpEmbed = new MessageEmbed() - .setAuthor({name:`${bot.user.username} Help`, iconURL:bot.user.avatarURL()}) - .setDescription(`Currently playing \`${audio}\``) - .addField('Public Commands', `/help\n/ping\n/about\n`, true) - .addField('Bot Owner Only', `/join\n/control\n/stop\n`, true) - .setFooter({text:'© Copyright 2020-2022 Andrew Lee'}) - .setColor('#0066ff') - - return await interaction.reply({ embeds: [helpEmbed] }); - }, -};
\ No newline at end of file diff --git a/commands/join.js b/commands/join.js index 0de2f14..8ede21a 100644 --- a/commands/join.js +++ b/commands/join.js @@ -28,7 +28,6 @@ export default { .setName('join') .setDescription('Joins voice chat.'), 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({ content: 'Joining voice channel', ephemeral: true }) return await voiceInit(bot); }, diff --git a/commands/pause.js b/commands/pause.js index c0edeeb..7615573 100644 --- a/commands/pause.js +++ b/commands/pause.js @@ -21,15 +21,19 @@ import { SlashCommandBuilder } from '@discordjs/builders' import config from '../config.json' assert {type: 'json'} - -export let integer; +import {audioState, isAudioStatePaused, player} from "../AudioBackend.js"; export default { data: new SlashCommandBuilder() .setName('pause') .setDescription('Pauses the player'), - 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 }); - + async execute(interaction) { + if (isAudioStatePaused === false) { + audioState(); + player.pause(); + return await interaction.reply({content:'Pausing music', ephemeral:true}); + } else { + return await interaction.reply({content:"Music is already paused", ephemeral:true}) + } }, };
\ No newline at end of file diff --git a/commands/play.js b/commands/play.js index a6d3453..2a5a385 100644 --- a/commands/play.js +++ b/commands/play.js @@ -20,7 +20,7 @@ ***************************************************************************/ import { SlashCommandBuilder } from '@discordjs/builders' -import { inputAudio, audio } from '../AudioBackend.js' +import { isAudioStatePaused, inputAudio, audio, audioState, player } from '../AudioBackend.js' import config from '../config.json' assert {type: 'json'} export let integer; @@ -33,10 +33,19 @@ export default { option.setName('int') .setDescription('Input a number for the selection for the audio file.'), ), + 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 }); integer = interaction.options.getInteger('int'); - await inputAudio(bot, integer); - return await interaction.reply({ content: `Now playing: ${audio}`, ephemeral: true }); + if (integer) { + await inputAudio(bot, integer); + return await interaction.reply({ content: `Now playing: ${audio}`, ephemeral: true }); + } + if (isAudioStatePaused === true) { + audioState(); + player.unpause(); + return await interaction.reply({content:'Resuming music', ephemeral:true}); + } else { + return await interaction.reply({content:"Music is already playing", ephemeral:true}) + } }, };
\ No newline at end of file diff --git a/commands/skip.js b/commands/skip.js index 4860209..a49b904 100644 --- a/commands/skip.js +++ b/commands/skip.js @@ -27,8 +27,8 @@ export default { .setName('skip') .setDescription('Skips the track'), async execute(interaction, bot) { + await interaction.reply({content:`Skipping ${audio}`, ephemeral:true}); player.stop(); - await searchAudio(bot, interaction); - return await interaction.reply({content:`Skipping ${audio}`, ephemeral:true}); + return await searchAudio(bot, interaction); }, };
\ No newline at end of file diff --git a/commands/stop.js b/commands/stop.js index ced8fe5..b3997e2 100644 --- a/commands/stop.js +++ b/commands/stop.js @@ -28,7 +28,6 @@ export default { .setName('stop') .setDescription('Powers off the bot'), 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({ content: 'Powering off...', ephemeral: true}) return await stopBot(bot, interaction); }, diff --git a/deploy-command.js b/deploy-command.js index 9543f37..b3c2d76 100644 --- a/deploy-command.js +++ b/deploy-command.js @@ -11,7 +11,7 @@ for (const file of commandFiles) { commands.push(command.data.toJSON()); } -const rest = new REST({ version: '9' }).setToken(config.token); +const rest = new REST({ version: '10' }).setToken(config.token); rest.put(Routes.applicationGuildCommands(config.clientID, config.guildID), { body: commands }) .then(() => console.log('Successfully registered application commands.')) |
