diff options
| author | Andrew Lee <alee14498@protonmail.com> | 2022-03-28 19:53:00 -0400 |
|---|---|---|
| committer | Andrew Lee <alee14498@protonmail.com> | 2022-03-28 19:53:00 -0400 |
| commit | 08aae8cd9e5417bd7451b9af2e3190bf9c6a4e43 (patch) | |
| tree | 965f234d6683b726bddc07ce19914e84b335cd44 | |
| parent | 0f5a1a252964861e149a0d784a90f0ad74aa09cb (diff) | |
| download | DLAP-08aae8cd9e5417bd7451b9af2e3190bf9c6a4e43.tar.gz DLAP-08aae8cd9e5417bd7451b9af2e3190bf9c6a4e43.tar.bz2 DLAP-08aae8cd9e5417bd7451b9af2e3190bf9c6a4e43.zip | |
Removed old cmd handler; Brought back join; New cmd
| -rw-r--r-- | AudioBackend.js | 30 | ||||
| -rw-r--r-- | README.md | 14 | ||||
| -rw-r--r-- | bot.js | 107 | ||||
| -rw-r--r-- | commands/about.js | 2 | ||||
| -rw-r--r-- | commands/control.js | 10 | ||||
| -rw-r--r-- | commands/help.js | 2 | ||||
| -rw-r--r-- | commands/join.js | 33 | ||||
| -rw-r--r-- | commands/stop.js | 47 |
8 files changed, 120 insertions, 125 deletions
diff --git a/AudioBackend.js b/AudioBackend.js index 070e717..c53c57e 100644 --- a/AudioBackend.js +++ b/AudioBackend.js @@ -34,7 +34,6 @@ export const player = createAudioPlayer(); export let audio; let fileData; - export function voiceInit(bot) { bot.channels.fetch(config.voiceChannel).then(channel => { const connection = joinVoiceChannel({ @@ -64,7 +63,7 @@ export function voiceInit(bot) { export function playAudio(bot) { let files = fs.readdirSync('music'); - // Eventually this system will need a rework so it won't repeat the same files. + //TODO: Eventually this system will need a rework so it won't repeat the same files. while (true) { audio = files[Math.floor(Math.random() * files.length)]; @@ -79,11 +78,14 @@ export function playAudio(bot) { player.play(resource); console.log('Now playing: ' + audio); - fileData = "Now Playing: " + audio; - fs.writeFile("./now-playing.txt", fileData, (err) => { - if (err) - console.log(err); - }); + + if (config.txtFile === true) { + fileData = "Now Playing: " + audio; + fs.writeFile("./now-playing.txt", fileData, (err) => { + if (err) + console.log(err); + }); + } const statusEmbed = new MessageEmbed() .addField('Now Playing', `${audio}`) @@ -96,11 +98,15 @@ export function playAudio(bot) { } export function destroyAudio(interaction) { - fileData = "Now Playing: Nothing"; - fs.writeFile("now-playing.txt", fileData, (err) => { - if (err) - console.log(err); - }); + + if (config.txtFile === true) { + fileData = "Now Playing: Nothing"; + fs.writeFile("now-playing.txt", fileData, (err) => { + if (err) + console.log(err); + }); + } + audio = "Not Playing"; player.stop(); const connection = getVoiceConnection(interaction.guild.id); @@ -4,7 +4,7 @@ A Discord bot that plays local MP3 audio tracks. Written in Discord.JS. [Video Tutorial](https://www.youtube.com/watch?v=7X3FAhYW31I) -If there's anything wrong or wanting to add a feature, feel free to make a fork and put a pull request. +If you want to add a feature or there's anything wrong, feel free to make a fork and put a pull request. # Configuration Make a new file called `config.json`. @@ -12,6 +12,7 @@ Make a new file called `config.json`. { "token": "token_here", "botOwner": "your_user_id_here", + "txtFile": true/false "statusChannel": "channel_id", "voiceChannel": "voice_channel_id" "guildID": "guild_id", @@ -32,7 +33,6 @@ Public Only help - Displays commands. ping - Pong! git - Links to the source repo. -playing - Tells you what it's playing at the moment. about - Information about the bot. Bot Owner Only @@ -44,3 +44,13 @@ skip - Skips the audio track. leave - Leaves voice chat. stop - Stops bot. ``` + +# Forking +When forking the project, you can make your own version of DLMP3 or help contribute to the project (See the "Contributing" section). + +But you need to edit `/commands/about.js` to uncomment the `.addField('Forked by', '[your name] (discord#0000)')` section. + +Be sure to replace that with your name. + +# Contributing +When contributing, be sure to add yourself to the contributors list in `/commands/about.js`.
\ No newline at end of file @@ -99,110 +99,3 @@ bot.on('interactionCreate', async interaction => { } } }); - -/* -bot.on('messageCreate', async msg => { - if (msg.author.bot) return; - if (!msg.guild) return; - if (!msg.content.startsWith(config.prefix)) return; - let command = msg.content.split(' ')[0]; - command = command.slice(config.prefix.length); - - // Public allowed commands - - if (command === 'help') { - const helpEmbed = new MessageEmbed() - .setAuthor({name:`${bot.user.username} Help`, iconURL:bot.user.avatarURL()}) - .setDescription(`Currently playing \`${audio}\`.`) - .addField('Public Commands', `${config.prefix}help\n${config.prefix}ping\n${config.prefix}git\n${config.prefix}playing\n${config.prefix}about\n`, true) - .addField('Bot Owner Only', `${config.prefix}join\n${config.prefix}resume\n${config.prefix}pause\n${config.prefix}skip\n${config.prefix}leave\n${config.prefix}stop\n`, true) - .setFooter({text:'© Copyright 2022 Andrew Lee. Licensed with GPL-3.0.'}) - .setColor('#0066ff') - - msg.channel.send({ embeds: [helpEmbed]}); - - } - - if (command === 'ping') { - msg.reply('Pong!'); - } - - if (command === 'git') { - msg.reply('This is the source code of this project.\nhttps://github.com/Alee14/DLMP3'); - } - - if (command === 'playing') { - msg.channel.send('Currently playing `' + audio + '`.'); - } - - if (command === 'about') { - msg.channel.send('The bot code was created by Andrew Lee (Alee#4277). Written in Discord.JS and licensed with GPL-3.0.'); - } - - if (![config.botOwner].includes(msg.author.id)) return; - - // Bot owner exclusive - - if (command === 'join') { - msg.reply('Joining voice channel.'); - //voiceInit(); - } - - if (command === 'resume') { - msg.reply('Resuming music.'); - //player.unpause(); - } - - if (command === 'pause') { - msg.reply('Pausing music.'); - //player.pause(); - } - - if (command === 'skip') { - msg.reply('Skipping `' + audio + '`...'); - //player.pause() - //playAudio(); - } - - if (command === 'leave') { - msg.reply('Leaving voice channel.'); - console.log('Leaving voice channel.'); - if (txtFile === true) { - fileData = "Now Playing: Nothing"; - fs.writeFile("now-playing.txt", fileData, (err) => { - if (err) - console.log(err); - }); - } - audio = "Not Playing"; - //player.stop(); - const connection = getVoiceConnection(msg.guild.id); - connection.destroy(); - - } - - if (command === 'stop') { - await msg.reply('Powering off...'); - if (txtFile === true) { - fileData = "Now Playing: Nothing"; - await fs.writeFile("now-playing.txt", fileData, (err) => { - if (err) - console.log(err); - }); - } - 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...'); - player.stop(); - const connection = getVoiceConnection(msg.guild.id); - connection.destroy(); - bot.destroy(); - process.exit(0); - } - -});*/ diff --git a/commands/about.js b/commands/about.js index b7771db..8177d81 100644 --- a/commands/about.js +++ b/commands/about.js @@ -31,6 +31,8 @@ export default { .setAuthor({name:`About ${bot.user.username}`, iconURL:bot.user.avatarURL()}) .addField('Information', 'A Discord bot that plays local MP3 audio tracks.') .addField('Original Creator', 'Andrew Lee (Alee#4277)') + //.addField('Contributors', '[your name] (discord#0000)') + //.addField('Forked by', '[your name] (discord#0000)') .addField('Frameworks', `Discord.JS ${version} + Voice`) .addField('License', 'GNU General Public License v3.0') .setFooter({text:'© Copyright 2020-2022 Andrew Lee. Licensed with GPL-3.0.'}) diff --git a/commands/control.js b/commands/control.js index 4c8c7a6..b3dd0bf 100644 --- a/commands/control.js +++ b/commands/control.js @@ -21,7 +21,9 @@ 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 } from '../AudioBackend.js' + +import config from '../config.json' assert {type: 'json'} export default { data: new SlashCommandBuilder() @@ -38,7 +40,7 @@ export default { const controlButtons = new MessageActionRow() .addComponents( new MessageButton() - .setStyle('SUCCESS') + .setStyle('SECONDARY') .setLabel('Join') .setCustomId('join'), new MessageButton() @@ -47,7 +49,7 @@ export default { .setCustomId('play'), new MessageButton() .setStyle('PRIMARY') - .setLabel('Pause') //possible toggle button instead + .setLabel('Pause') //TODO: possibly toggle button instead .setCustomId('pause'), new MessageButton() .setStyle('SECONDARY') @@ -98,6 +100,7 @@ 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}...`) @@ -105,6 +108,7 @@ export default { 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(); diff --git a/commands/help.js b/commands/help.js index ec79628..b1ba51f 100644 --- a/commands/help.js +++ b/commands/help.js @@ -26,7 +26,7 @@ import { audio } from '../AudioBackend.js' export default { data: new SlashCommandBuilder() .setName('help') - .setDescription('Displays commands.'), + .setDescription('Displays commands'), async execute(interaction, bot) { const helpEmbed = new MessageEmbed() .setAuthor({name:`${bot.user.username} Help`, iconURL:bot.user.avatarURL()}) diff --git a/commands/join.js b/commands/join.js new file mode 100644 index 0000000..45f513c --- /dev/null +++ b/commands/join.js @@ -0,0 +1,33 @@ +/************************************************************************** + * + * DLMP3 Bot: A Discord bot that plays local MP3 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 { voiceInit } from "../AudioBackend.js"; + +export default { + data: new SlashCommandBuilder() + .setName('join') + .setDescription('Joins voice chat.'), + async execute(interaction, bot) { + await interaction.reply('Joining voice channel') + voiceInit(bot); + }, +};
\ No newline at end of file diff --git a/commands/stop.js b/commands/stop.js new file mode 100644 index 0000000..3059997 --- /dev/null +++ b/commands/stop.js @@ -0,0 +1,47 @@ +/************************************************************************** + * + * DLMP3 Bot: A Discord bot that plays local MP3 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 config from '../config.json' assert {type: 'json'} +import { destroyAudio } from "../AudioBackend.js"; + +export default { + data: new SlashCommandBuilder() + .setName('stop') + .setDescription('Powers off the bot'), + async execute(interaction, bot) { + 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); + }, +};
\ No newline at end of file |
