diff options
| -rw-r--r-- | AudioBackend/AudioControl.js (renamed from backend/AudioControl.js) | 0 | ||||
| -rw-r--r-- | AudioBackend/PlayAudio.js (renamed from backend/PlayAudio.js) | 2 | ||||
| -rw-r--r-- | AudioBackend/QueueSystem.js (renamed from backend/QueueSystem.js) | 0 | ||||
| -rw-r--r-- | AudioBackend/Shutdown.js (renamed from backend/Shutdown.js) | 0 | ||||
| -rw-r--r-- | AudioBackend/VoiceInitialization.js (renamed from backend/VoiceInitialization.js) | 0 | ||||
| -rw-r--r-- | Commands/about.js (renamed from commands/about.js) | 0 | ||||
| -rw-r--r-- | Commands/join.js (renamed from commands/join.js) | 2 | ||||
| -rw-r--r-- | Commands/leave.js (renamed from commands/leave.js) | 2 | ||||
| -rw-r--r-- | Commands/list.js | 63 | ||||
| -rw-r--r-- | Commands/next.js (renamed from commands/next.js) | 4 | ||||
| -rw-r--r-- | Commands/pause.js (renamed from commands/pause.js) | 2 | ||||
| -rw-r--r-- | Commands/ping.js (renamed from commands/ping.js) | 0 | ||||
| -rw-r--r-- | Commands/play.js (renamed from commands/play.js) | 6 | ||||
| -rw-r--r-- | Commands/previous.js (renamed from commands/previous.js) | 2 | ||||
| -rw-r--r-- | Commands/reshuffle.js (renamed from commands/reshuffle.js) | 4 | ||||
| -rw-r--r-- | Commands/shutdown.js (renamed from commands/shutdown.js) | 2 | ||||
| -rw-r--r-- | Commands/status.js (renamed from commands/status.js) | 5 | ||||
| -rw-r--r-- | README.md | 5 | ||||
| -rw-r--r-- | bot.js | 10 | ||||
| -rw-r--r-- | commands/list.js | 42 | ||||
| -rw-r--r-- | deploy-command.js | 4 | ||||
| -rw-r--r-- | package.json | 2 | ||||
| -rw-r--r-- | yarn.lock | 12 |
23 files changed, 97 insertions, 72 deletions
diff --git a/backend/AudioControl.js b/AudioBackend/AudioControl.js index 447e040..447e040 100644 --- a/backend/AudioControl.js +++ b/AudioBackend/AudioControl.js diff --git a/backend/PlayAudio.js b/AudioBackend/PlayAudio.js index fea4b3d..5d18534 100644 --- a/backend/PlayAudio.js +++ b/AudioBackend/PlayAudio.js @@ -24,7 +24,7 @@ import { readdirSync, readFileSync, writeFile } from 'node:fs'; import { EmbedBuilder } from 'discord.js'; import { player } from './VoiceInitialization.js'; import { audioState, files } from './AudioControl.js'; -import { integer } from '../commands/play.js'; +import { integer } from '../Commands/play.js'; const { statusChannel, txtFile } = JSON.parse(readFileSync('./config.json', 'utf-8')); let fileData; diff --git a/backend/QueueSystem.js b/AudioBackend/QueueSystem.js index 0cd6ded..0cd6ded 100644 --- a/backend/QueueSystem.js +++ b/AudioBackend/QueueSystem.js diff --git a/backend/Shutdown.js b/AudioBackend/Shutdown.js index fb89505..fb89505 100644 --- a/backend/Shutdown.js +++ b/AudioBackend/Shutdown.js diff --git a/backend/VoiceInitialization.js b/AudioBackend/VoiceInitialization.js index a9e1149..a9e1149 100644 --- a/backend/VoiceInitialization.js +++ b/AudioBackend/VoiceInitialization.js diff --git a/commands/about.js b/Commands/about.js index 23c750e..23c750e 100644 --- a/commands/about.js +++ b/Commands/about.js diff --git a/commands/join.js b/Commands/join.js index aa3eb66..739ebba 100644 --- a/commands/join.js +++ b/Commands/join.js @@ -20,7 +20,7 @@ ***************************************************************************/ import { SlashCommandBuilder } from 'discord.js'; -import { voiceInit } from '../backend/VoiceInitialization.js'; +import { voiceInit } from '../AudioBackend/VoiceInitialization.js'; import { PermissionFlagsBits } from 'discord-api-types/v10'; export default { diff --git a/commands/leave.js b/Commands/leave.js index 1577baa..cea791a 100644 --- a/commands/leave.js +++ b/Commands/leave.js @@ -20,7 +20,7 @@ ***************************************************************************/ import { SlashCommandBuilder } from 'discord.js'; -import { destroyAudio } from '../backend/Shutdown.js'; +import { destroyAudio } from '../AudioBackend/Shutdown.js'; import { PermissionFlagsBits } from 'discord-api-types/v10'; export default { diff --git a/Commands/list.js b/Commands/list.js new file mode 100644 index 0000000..176ae61 --- /dev/null +++ b/Commands/list.js @@ -0,0 +1,63 @@ +/************************************************************************** + * + * 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 { EmbedBuilder, SlashCommandBuilder } from 'discord.js'; +import { readdir } from 'node:fs'; + +const musicFolder = './music'; + +export default { + data: new SlashCommandBuilder() + .setName('list') + .setDescription('Lists the available audio tracks') + .addIntegerOption(option => + option.setName('page') + .setDescription('Input a number to change the page of the list') + ), + async execute(interaction, bot) { + const page = interaction.options.getInteger('page') || 1; // If no page is specified, default to page 1 + readdir(musicFolder, async(err, files) => { + if (err) { + console.error(err); + } else { + const trackList = files.map((file, i) => `${i}: ${file}`); // Create an array of track names + const pageSize = 10; // Number of tracks per page + const numPages = Math.ceil(trackList.length / pageSize); // Total number of pages + if (page < 1 || page > numPages) { // Check if the page number is valid + return await interaction.reply({ content: `Invalid page number. Please specify a number between 1 and ${numPages}.`, ephemeral: true }); + } + // Split the track list into pages + const pages = []; + for (let i = 0; i < numPages; i++) { + const start = i * pageSize; + const end = start + pageSize; + pages.push(trackList.slice(start, end)); + } + // Send the specified page with the page number and total number of pages + const listEmbed = new EmbedBuilder(); + listEmbed.setAuthor({ name: `${bot.user.username} List`, iconURL: bot.user.avatarURL() }); + listEmbed.addFields({ name: `Listing ${trackList.length} audio tracks...`, value: `\`\`\`\n${pages[page - 1].join('\n')}\n\`\`\`` }); + listEmbed.setFooter({ text: `Page ${page}/${numPages}` }); + listEmbed.setColor('#0066ff'); + await interaction.reply({ embeds: [listEmbed] }); + } + }); + } +}; diff --git a/commands/next.js b/Commands/next.js index 759c5bb..d3240cf 100644 --- a/commands/next.js +++ b/Commands/next.js @@ -20,8 +20,8 @@ ***************************************************************************/ import { SlashCommandBuilder } from 'discord.js'; -import { player } from '../backend/VoiceInitialization.js'; -import { nextAudio, playerState } from '../backend/AudioControl.js'; +import { player } from '../AudioBackend/VoiceInitialization.js'; +import { nextAudio, playerState } from '../AudioBackend/AudioControl.js'; import { PermissionFlagsBits } from 'discord-api-types/v10'; export default { diff --git a/commands/pause.js b/Commands/pause.js index 61b9e21..e461a4c 100644 --- a/commands/pause.js +++ b/Commands/pause.js @@ -20,7 +20,7 @@ ***************************************************************************/ import { SlashCommandBuilder } from 'discord.js'; -import { toggleAudioState, isAudioStatePaused } from '../backend/AudioControl.js'; +import { toggleAudioState, isAudioStatePaused } from '../AudioBackend/AudioControl.js'; import { PermissionFlagsBits } from 'discord-api-types/v10'; export default { diff --git a/commands/ping.js b/Commands/ping.js index 72ef024..72ef024 100644 --- a/commands/ping.js +++ b/Commands/ping.js diff --git a/commands/play.js b/Commands/play.js index 4c95ab8..a0af3f3 100644 --- a/commands/play.js +++ b/Commands/play.js @@ -20,9 +20,9 @@ ***************************************************************************/ import { SlashCommandBuilder } from 'discord.js'; -import { inputAudio } from '../backend/QueueSystem.js'; -import { files, isAudioStatePaused, toggleAudioState } from '../backend/AudioControl.js'; -import { audio } from '../backend/PlayAudio.js'; +import { inputAudio } from '../AudioBackend/QueueSystem.js'; +import { files, isAudioStatePaused, toggleAudioState } from '../AudioBackend/AudioControl.js'; +import { audio } from '../AudioBackend/PlayAudio.js'; import { PermissionFlagsBits } from 'discord-api-types/v10'; export let integer; diff --git a/commands/previous.js b/Commands/previous.js index ebedbb6..dd79a98 100644 --- a/commands/previous.js +++ b/Commands/previous.js @@ -20,7 +20,7 @@ ***************************************************************************/ import { SlashCommandBuilder } from 'discord.js'; -import { playerState, previousAudio } from '../backend/AudioControl.js'; +import { playerState, previousAudio } from '../AudioBackend/AudioControl.js'; import { PermissionFlagsBits } from 'discord-api-types/v10'; export default { diff --git a/commands/reshuffle.js b/Commands/reshuffle.js index e1d37d0..f3e70c2 100644 --- a/commands/reshuffle.js +++ b/Commands/reshuffle.js @@ -20,10 +20,10 @@ ***************************************************************************/ import { SlashCommandBuilder } from 'discord.js'; -import { shufflePlaylist } from '../backend/QueueSystem.js'; +import { shufflePlaylist } from '../AudioBackend/QueueSystem.js'; import { PermissionFlagsBits } from 'discord-api-types/v10'; import { readFileSync } from 'node:fs'; -import { audioState } from '../backend/AudioControl.js'; +import { audioState } from '../AudioBackend/AudioControl.js'; // import config from './config.json' assert {type: 'json'} const { shuffle } = JSON.parse(readFileSync('./config.json', 'utf-8')); diff --git a/commands/shutdown.js b/Commands/shutdown.js index 313866b..d97922c 100644 --- a/commands/shutdown.js +++ b/Commands/shutdown.js @@ -20,7 +20,7 @@ ***************************************************************************/ import { SlashCommandBuilder } from 'discord.js'; -import { stopBot } from '../backend/Shutdown.js'; +import { stopBot } from '../AudioBackend/Shutdown.js'; import { PermissionFlagsBits } from 'discord-api-types/v10'; export default { diff --git a/commands/status.js b/Commands/status.js index d19e4ac..fc1229d 100644 --- a/commands/status.js +++ b/Commands/status.js @@ -21,8 +21,8 @@ import { EmbedBuilder, SlashCommandBuilder } from 'discord.js'; import { parseFile } from 'music-metadata'; -import { audio, metadataEmpty, duration, audioTitle, currentTrack } from '../backend/PlayAudio.js'; -import { files, playerState } from '../backend/AudioControl.js'; +import { audio, metadataEmpty, duration, audioTitle, currentTrack } from '../AudioBackend/PlayAudio.js'; +import { files, playerState } from '../AudioBackend/AudioControl.js'; export default { data: new SlashCommandBuilder() @@ -56,6 +56,7 @@ export default { { name: 'State', value: playerState }, { name: 'Tracks', value: `${audioID}/${files.length}` }, { name: 'Duration', value: duration } + // { name: 'Session Uptime', value: `` } ) .setColor('#0066ff'); @@ -22,6 +22,7 @@ Make a new file called `config.json`. "statusChannel": "channel_id", "voiceChannel": "voice_channel_id", "presenceActivity": "activity_here", + "activityType": [0 (Playing)/1 (Streaming)/2 (Listening)/3 (Watching)/4 (Custom)/5 (Competing)], "clientID": "client_id" } ``` @@ -41,6 +42,8 @@ Public Only ping - Pong! status - Checks what audio file is playing currently. about - Information about the bot. +list - Lists the available audio tracks. +list (page) - Input a number to change the page of the list. Bot Owner Only -------------- @@ -50,7 +53,7 @@ play (int) - Input a number for the selection for the audio file. pause - Pauses music. next - Goes to next music. previous - Goes to previous music. -reshuffle - Reshuffles the playlist +reshuffle - Reshuffles the playlist. leave - Leaves voice chat. shutdown - Powers off the bot. ``` @@ -19,10 +19,10 @@ * ***************************************************************************/ import { Client, GatewayIntentBits, EmbedBuilder, Collection, version, InteractionType } from 'discord.js'; -import { voiceInit } from './backend/VoiceInitialization.js'; +import { voiceInit } from './AudioBackend/VoiceInitialization.js'; import { readdirSync, readFileSync } from 'node:fs'; // import config from './config.json' assert { type: 'json' } Not supported by ESLint yet -const { token, statusChannel, voiceChannel, shuffle, repeat, presenceActivity } = JSON.parse(readFileSync('./config.json', 'utf-8')); +const { token, statusChannel, voiceChannel, shuffle, repeat, presenceActivity, activityType } = JSON.parse(readFileSync('./config.json', 'utf-8')); const bot = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildVoiceStates] }); bot.login(token); @@ -34,10 +34,10 @@ bot.login(token); // Slash Command Handler bot.commands = new Collection(); -const commandFiles = readdirSync('./commands').filter(file => file.endsWith('.js')); +const commandFiles = readdirSync('./Commands').filter(file => file.endsWith('.js')); for (const file of commandFiles) { - const { default: command } = await import(`./commands/${file}`); + const { default: command } = await import(`./Commands/${file}`); bot.commands.set(command.data.name, command); } @@ -54,7 +54,7 @@ bot.once('ready', async() => { bot.user.setPresence({ activities: [{ name: presenceActivity, - type: 'LISTENING' + type: activityType }], status: 'online' }); diff --git a/commands/list.js b/commands/list.js deleted file mode 100644 index 8eddcda..0000000 --- a/commands/list.js +++ /dev/null @@ -1,42 +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 'discord.js'; -import { readdirSync, readdir } from 'node:fs'; - -const musicFolder = './music'; - -export default { - data: new SlashCommandBuilder() - .setName('list') - .setDescription('Lists the available audio tracks'), - async execute(interaction) { - // If someone figures out how to either split the list or make pages when the max character reaches, please do so and make a pull request. - - const beats = readdirSync(musicFolder).join('\n'); - readdir(musicFolder, async(err, files) => { - await interaction.reply(`Listing ${files.length} audio tracks...\n\`\`\`\n${beats}\n\`\`\``); - if (err) { - console.error(err); - } - }); - } -}; diff --git a/deploy-command.js b/deploy-command.js index cd698ee..fd9de7a 100644 --- a/deploy-command.js +++ b/deploy-command.js @@ -5,10 +5,10 @@ import { Routes } from 'discord-api-types/v10'; const { clientID, token } = JSON.parse(readFileSync('./config.json')); const commands = []; -const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js')); +const commandFiles = fs.readdirSync('./Commands').filter(file => file.endsWith('.js')); for (const file of commandFiles) { - const { default: command } = await import(`./commands/${file}`); + const { default: command } = await import(`./Commands/${file}`); commands.push(command.data.toJSON()); } diff --git a/package.json b/package.json index aeb0672..5757d02 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "discord-api-types": "^0.37.15", "discord.js": "^14.6.0", "ffmpeg-static": "^5.1.0", - "i18next": "^22.0.6", + "i18next": "^22.4.5", "music-metadata": "^8.1.0", "sodium": "^3.0.2" }, @@ -2,7 +2,7 @@ # yarn lockfile v1 -"@babel/runtime@^7.17.2": +"@babel/runtime@^7.20.6": version "7.20.6" resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.20.6.tgz#facf4879bfed9b5326326273a64220f099b0fce3" integrity sha512-Q+8MqP7TiHMWzSfwiJwXCjyf4GYA4Dgw3emg/7xmwsdLJOZUp+nMqcOwOzzYheuM1rhDu8FSj2l0aoMygEuXuA== @@ -988,12 +988,12 @@ https-proxy-agent@^5.0.0: agent-base "6" debug "4" -i18next@^22.0.6: - version "22.0.6" - resolved "https://registry.yarnpkg.com/i18next/-/i18next-22.0.6.tgz#d7029912f8aa74ff295c0d9afd1b7dea45859b49" - integrity sha512-RlreNGoPIdDP4QG+qSA9PxZKGwlzmcozbI9ObI6+OyUa/Rp0EjZZA9ubyBjw887zVNZsC+7FI3sXX8oiTzAfig== +i18next@^22.4.5: + version "22.4.5" + resolved "https://registry.yarnpkg.com/i18next/-/i18next-22.4.5.tgz#7324e4946c2facbe743ca25bca8980af05b0a109" + integrity sha512-Kc+Ow0guRetUq+kv02tj0Yof9zveROPBAmJ8UxxNODLVBRSwsM4iD0Gw3BEieOmkWemF6clU3K1fbnCuTqiN2Q== dependencies: - "@babel/runtime" "^7.17.2" + "@babel/runtime" "^7.20.6" ieee754@^1.2.1: version "1.2.1" |
