mirror of
https://github.com/Alee14/DLAP.git
synced 2025-01-22 10:52:03 -05:00
Improved list command; Directory name change; Fixed ActivityType
This commit is contained in:
parent
4c25284974
commit
c55e480e4d
23 changed files with 97 additions and 72 deletions
|
@ -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;
|
|
@ -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 {
|
|
@ -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 {
|
63
Commands/list.js
Normal file
63
Commands/list.js
Normal file
|
@ -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] });
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
|
@ -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 {
|
|
@ -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 {
|
|
@ -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;
|
|
@ -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 {
|
|
@ -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'));
|
||||
|
|
@ -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 {
|
|
@ -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.
|
||||
```
|
||||
|
|
10
bot.js
10
bot.js
|
@ -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'
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
@ -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"
|
||||
},
|
||||
|
|
12
yarn.lock
12
yarn.lock
|
@ -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"
|
||||
|
|
Loading…
Reference in a new issue