diff --git a/.env.example b/.env.example index 0f4d278..3c7feaa 100644 --- a/.env.example +++ b/.env.example @@ -1,14 +1,26 @@ +# This file contains all the environment variables that are used by the bot. + +# For production use, set NODE_ENV to production +# For development use, set NODE_ENV to development NODE_ENV=development -MINIMUM_LOG_LEVEL=debug -MINIMUM_LOG_LEVEL_CONSOLE=info + +# Required: Login credentials for the bot +# Retrieve your bot token and application id from https://discordapp.com/developers/applications/me DISCORD_BOT_TOKEN=YOUR_DISCORD_BOT_TOKEN -DISCORD_CLIENT_ID=YOUR_DISCOR_BOT_CLIENT_ID -UV_THREADPOOL_SIZE=4 -NODE_OPTIONS= +DISCORD_APPLICATION_ID=YOUR_DISCORD_BOT_APPLICATION_ID + +# Optional: Set a YouTube cookie to reduce the chance of getting rate limited / 429 Too Many Requests YOUTUBE_COOKIE= + +# Optional: Authentication tokens for botlist websites to automatically update server count, etc. +# See /src/utils/postBotStats.js for more information BOTLIST_TOP_GG_API_TOKEN= BOTLIST_DISCORD_BOT_LIST_COM_API_TOKEN= BOTLIST_DISCORDS_COM_API_TOKEN= BOTLIST_DISCORD_BOTS_GG_API_TOKEN= BOTLIST_BOTLIST_ME_API_TOKEN= BOTLIST_DISCORDLIST_GG_API_TOKEN= + +# Optional: Only change this if you know what you are doing +NODE_OPTIONS= +UV_THREADPOOL_SIZE= diff --git a/.gitignore b/.gitignore index a0596c3..d64da02 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ /node_modules /config.json +/src/config.js /.env /app-*.log /logs diff --git a/config.json.example b/config.json.example deleted file mode 100644 index ee6a4c9..0000000 --- a/config.json.example +++ /dev/null @@ -1,132 +0,0 @@ -{ - "botInfo": { - "name": "Cadence", - "websiteUrl": "Unknown", - "botInviteUrl": "Unknown", - "supportServerInviteUrl": "Unknown" - }, - "systemServerGuildIds": [ - "Server id where system commands can be used", - "Another server id where system commands can be used" - ], - "systemMessageChannelId": "", - "systemUserId": "", - "embedColors": { - "colorSuccess": "#23A55A", - "colorWarning": "#F0B232", - "colorError": "#F23F43", - "colorInfo": "#5865F2", - "colorNote": "#80848E" - }, - "playerOptions": { - "leaveOnEmpty": true, - "leaveOnEmptyCooldown": 60000, - "leaveOnEnd": true, - "leaveonEndCooldown": 60000, - "leaveOnStop": true, - "leaveOnStopCooldown": 60000, - "defaultVolume": 50, - "maxQueueSize": 1000, - "maxHistorySize": 100 - }, - "progressBarOptions": { - "length": 14, - "timecodes": false, - "separator": "┃", - "indicator": "🔘", - "leftChar": "▬", - "rightChar": "▬" - }, - "embedIcons": { - "logo": "🤖", - "beta": "`beta`", - "new": "`new`", - "rule": "📒", - "support": "❓", - "bot": "🤖", - "audioPlaying": "🎶", - "audioStartedPlaying": "🎶", - "success": "✅", - "error": "⚠️", - "warning": "⚠️", - "disable": "🚫", - "enable": "✅", - "disabled": "✅", - "enabled": "✅", - "nextTrack": "⏭️", - "previousTrack": "⏮️", - "pauseResumeTrack": "⏯️", - "shuffleQueue": "🔀", - "loop": "🔁", - "loopAction": "🔁", - "autoplay": "♾️", - "autoplayAction": "♾️", - "looping": "🔁", - "autoplaying": "♾️", - "skipped": "⏭️", - "back": "⏮️", - "pauseResumed": "⏯️", - "shuffled": "🔀", - "volume": "🔊", - "volumeIsMuted": "🔇", - "volumeChanged": "🔊", - "volumeMuted": "🔇", - "queue": "🎶", - "sourceArbitrary": "🎵", - "sourceAppleMusic": "🎵", - "sourceYouTube": "🎵", - "sourceSoundCloud": "🎵", - "sourceSpotify": "🎵" - }, - "filterThreadAmount": "2", - "filterList": [ - { - "label": "Bass boost", - "value": "bassboost_low", - "description": "Boost the bass of the audio.", - "emoji": "🔉" - }, - { - "label": "Bass boost high", - "value": "bassboost", - "description": "Boost the bass of the audio a lot.", - "emoji": "🔊" - }, - { - "label": "Night core", - "value": "nightcore", - "description": "Speed up the audio (higher pitch).", - "emoji": "🐱" - }, - { - "label": "Lo-fi", - "value": "lofi", - "description": "Low fidelity effect (lower quality).", - "emoji": "📻" - }, - { - "label": "Vaporwave", - "value": "vaporwave", - "description": "Slow down the audio (lower pitch).", - "emoji": "🌸" - }, - { - "label": "Ear rape", - "value": "earrape", - "description": "Extremely loud and distorted audio.", - "emoji": "👂" - }, - { - "label": "8D", - "value": "8D", - "description": "Simulate 8D audio effect (surround).", - "emoji": "🎧" - }, - { - "label": "Treble", - "value": "treble", - "description": "Increase the high frequencies.", - "emoji": "🎼" - } - ] -} diff --git a/src/commands/info/help.js b/src/commands/info/help.js index ca8d1ca..373f3fe 100644 --- a/src/commands/info/help.js +++ b/src/commands/info/help.js @@ -1,7 +1,5 @@ -const path = require('node:path'); -const { SlashCommandBuilder } = require('@discordjs/builders'); -const { EmbedBuilder } = require('discord.js'); -const { embedColors, embedIcons, botInfo } = require(path.resolve('./config.json')); +const { embedOptions, botOptions } = require('../../config'); +const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); module.exports = { data: new SlashCommandBuilder() @@ -13,22 +11,22 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `${embedIcons.rule} **List of commands**\n` + + `${embedOptions.icons.rule} **List of commands**\n` + '- **`/play` `query`** - Add a track or playlist to the queue by url or search.\n' + '- **`/pause`** - Pause or resume the current track.\n' + '- **`/queue` `[page]`** - Show the list of tracks added to the queue.\n' + '- **`/nowplaying`** - Show information about the track currently playing.\n' + - `- **\`/seek\` \`duration\`** - ${embedIcons.new} Seek to a specified duration in the current track.\n` + - `- **\`/loop\` \`mode\`** - ${embedIcons.beta} Toggle looping a track, the whole queue or autoplay.\n` + + `- **\`/seek\` \`duration\`** - ${embedOptions.icons.new} Seek to a specified duration in the current track.\n` + + `- **\`/loop\` \`mode\`** - ${embedOptions.icons.beta} Toggle looping a track, the whole queue or autoplay.\n` + '- **`/filters`** - Toggle various audio filters during playback.\n' + '- **`/volume` `[percentage]`** - Show or set the playback volume for tracks.\n' + '- **`/skip` `[tracknumber]`** - Skip to next or specified track.\n' + '- **`/remove` `tracknumber`** - Remove specified track from the queue.\n' + '- **`/leave`** - Clear the queue and remove the bot from voice channel.\n\n' + - `${embedIcons.support} **Support server**\nJoin the support server for help or suggestions: \n**${botInfo.supportServerInviteUrl}**\n\n` + - `${embedIcons.bot} **Enjoying ${botInfo.name}?**\nAdd me to another server: \n**[Click me!](${botInfo.botInviteUrl})**` + `${embedOptions.icons.support} **Support server**\nJoin the support server for help or suggestions: \n**${botOptions.serverInviteUrl}**\n\n` + + `${embedOptions.icons.bot} **Enjoying ${botOptions.name}?**\nAdd me to another server: \n**[Click me!](${botOptions.botInviteUrl})**` ) - .setColor(embedColors.colorInfo) + .setColor(embedOptions.colors.info) ] }); } diff --git a/src/commands/player/filters.js b/src/commands/player/filters.js index 85e8223..a7e3d71 100644 --- a/src/commands/player/filters.js +++ b/src/commands/player/filters.js @@ -1,14 +1,13 @@ -const path = require('node:path'); -const { SlashCommandBuilder } = require('@discordjs/builders'); -const { useQueue } = require('discord-player'); +const { embedOptions, ffmpegFilterOptions } = require('../../config'); const { + SlashCommandBuilder, EmbedBuilder, + ActionRowBuilder, StringSelectMenuBuilder, StringSelectMenuOptionBuilder, - ActionRowBuilder, ButtonBuilder } = require('discord.js'); -const { embedColors, embedIcons, filterList, filterThreadAmount } = require(path.resolve('./config.json')); +const { useQueue } = require('discord-player'); module.exports = { data: new SlashCommandBuilder() @@ -21,9 +20,9 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**${embedIcons.warning} Oops!**\nYou need to be in a voice channel to use this command.` + `**${embedOptions.icons.warning} Oops!**\nYou need to be in a voice channel to use this command.` ) - .setColor(embedColors.colorWarning) + .setColor(embedOptions.colors.warning) ] }); } @@ -35,16 +34,16 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**${embedIcons.warning} Oops!**\nThere are no tracks in the queue. First add some tracks with **\`/play\`**!` + `**${embedOptions.icons.warning} Oops!**\nThere are no tracks in the queue. First add some tracks with **\`/play\`**!` ) - .setColor(embedColors.colorWarning) + .setColor(embedOptions.colors.warning) ] }); } let filterOptions = []; - filterList.forEach((filter) => { + ffmpegFilterOptions.availableFilters.forEach((filter) => { let isEnabled = false; if (queue.filters.ffmpeg.filters.includes(filter.value)) { @@ -75,16 +74,16 @@ module.exports = { .setCustomId('disable-filters') .setLabel('Disable all filters') .setStyle('Secondary') - .setEmoji(embedIcons.disable) + .setEmoji(embedOptions.icons.disable) ); const response = await interaction.editReply({ embeds: [ new EmbedBuilder() .setDescription( - `**Toggle filters** ${embedIcons.beta}\nEnable or disable audio filters for playback from the menu.` + `**Toggle filters** ${embedOptions.icons.beta}\nEnable or disable audio filters for playback from the menu.` ) - .setColor(embedColors.colorInfo) + .setColor(embedOptions.colors.info) ], components: [filterActionRow, disableFiltersActionRow] }); @@ -100,7 +99,7 @@ module.exports = { queue.filters.ffmpeg.setInputArgs([ '-threads', - filterThreadAmount, + ffmpegFilterOptions.threadAmount, '-reconnect', '1', '-reconnect_streamed', @@ -124,9 +123,9 @@ module.exports = { iconURL: interaction.user.avatarURL() }) .setDescription( - `**${embedIcons.success} Disabled filters**\nAll audio filters have been disabled.` + `**${embedOptions.icons.success} Disabled filters**\nAll audio filters have been disabled.` ) - .setColor(embedColors.colorSuccess) + .setColor(embedOptions.colors.success) ], components: [] }); @@ -143,11 +142,20 @@ module.exports = { iconURL: interaction.user.avatarURL() }) .setDescription( - `**${embedIcons.success} Filters toggled**\nNow using these filters:\n${confirmation.values - .map((enabled) => `\`${filterList.find((filter) => enabled == filter.value).label}\``) + `**${ + embedOptions.icons.success + } Filters toggled**\nNow using these filters:\n${confirmation.values + .map( + (enabled) => + `\`${ + ffmpegFilterOptions.availableFilters.find( + (filter) => enabled == filter.value + ).label + }\`` + ) .join(', ')}.` ) - .setColor(embedColors.colorSuccess) + .setColor(embedOptions.colors.success) ], components: [] }); diff --git a/src/commands/player/leave.js b/src/commands/player/leave.js index 41909ca..9b994a4 100644 --- a/src/commands/player/leave.js +++ b/src/commands/player/leave.js @@ -1,8 +1,6 @@ -const path = require('node:path'); -const { SlashCommandBuilder } = require('@discordjs/builders'); +const { embedOptions } = require('../../config'); +const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); const { useQueue } = require('discord-player'); -const { EmbedBuilder } = require('discord.js'); -const { embedColors, embedIcons } = require(path.resolve('./config.json')); module.exports = { data: new SlashCommandBuilder() @@ -17,9 +15,9 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**${embedIcons.warning} Oops!**\nYou need to be in a voice channel to use this command.` + `**${embedOptions.icons.warning} Oops!**\nYou need to be in a voice channel to use this command.` ) - .setColor(embedColors.colorWarning) + .setColor(embedOptions.colors.warning) ] }); } @@ -31,9 +29,9 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**${embedIcons.warning} Oops!**\n_Hmm.._ It seems I am not in a voice channel!` + `**${embedOptions.icons.warning} Oops!**\n_Hmm.._ It seems I am not in a voice channel!` ) - .setColor(embedColors.colorWarning) + .setColor(embedOptions.colors.warning) ] }); } @@ -49,9 +47,9 @@ module.exports = { iconURL: interaction.user.avatarURL() }) .setDescription( - `**${embedIcons.success} Leaving channel**\nCleared the track queue and left voice channel.\n\nTo play more music, use the **\`/play\`** command!` + `**${embedOptions.icons.success} Leaving channel**\nCleared the track queue and left voice channel.\n\nTo play more music, use the **\`/play\`** command!` ) - .setColor(embedColors.colorSuccess) + .setColor(embedOptions.colors.success) ] }); } diff --git a/src/commands/player/loop.js b/src/commands/player/loop.js index 5a4081c..2566c8d 100644 --- a/src/commands/player/loop.js +++ b/src/commands/player/loop.js @@ -1,8 +1,6 @@ -const path = require('node:path'); -const { SlashCommandBuilder } = require('@discordjs/builders'); +const { embedOptions, botOptions } = require('../../config'); +const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); const { useQueue } = require('discord-player'); -const { EmbedBuilder } = require('discord.js'); -const { embedColors, embedIcons, botInfo } = require(path.resolve('./config.json')); module.exports = { data: new SlashCommandBuilder() @@ -27,9 +25,9 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**${embedIcons.warning} Oops!**\nYou need to be in a voice channel to use this command.` + `**${embedOptions.icons.warning} Oops!**\nYou need to be in a voice channel to use this command.` ) - .setColor(embedColors.colorWarning) + .setColor(embedOptions.colors.warning) ] }); } @@ -41,9 +39,9 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**${embedIcons.warning} Oops!**\nThere are no tracks in the queue and nothing currently playing. First add some tracks with **\`/play\`**!` + `**${embedOptions.icons.warning} Oops!**\nThere are no tracks in the queue and nothing currently playing. First add some tracks with **\`/play\`**!` ) - .setColor(embedColors.colorWarning) + .setColor(embedOptions.colors.warning) ] }); } @@ -66,10 +64,10 @@ module.exports = { new EmbedBuilder() .setDescription( `**${ - currentMode === 3 ? embedIcons.autoplay : embedIcons.loop + currentMode === 3 ? embedOptions.icons.autoplay : embedOptions.icons.loop } Current loop mode**\nThe looping mode is currently set to \`${currentModeUserString}\`.` ) - .setColor(embedColors.colorInfo) + .setColor(embedOptions.colors.info) ] }); } @@ -78,8 +76,10 @@ module.exports = { return await interaction.editReply({ embeds: [ new EmbedBuilder() - .setDescription(`**${embedIcons.warning} Oops!**\nLoop mode is already \`${modeUserString}\`.`) - .setColor(embedColors.colorWarning) + .setDescription( + `**${embedOptions.icons.warning} Oops!**\nLoop mode is already \`${modeUserString}\`.` + ) + .setColor(embedOptions.colors.warning) ] }); } @@ -91,9 +91,9 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**${embedIcons.error} Uh-oh... Failed to change loop mode!**\nI tried to change the loop mode to \`${modeUserString}\`, but something went wrong.\n\nYou can try to perform the command again.\n\n_If you think this message is incorrect or the issue persists, please submit a bug report in the **[support server](${botInfo.supportServerInviteUrl})**._` + `**${embedOptions.icons.error} Uh-oh... Failed to change loop mode!**\nI tried to change the loop mode to \`${modeUserString}\`, but something went wrong.\n\nYou can try to perform the command again.\n\n_If you think this message is incorrect or the issue persists, please submit a bug report in the **[support server](${botOptions.serverInviteUrl})**._` ) - .setColor(embedColors.colorError) + .setColor(embedOptions.colors.error) ] }); } @@ -107,9 +107,9 @@ module.exports = { iconURL: interaction.user.avatarURL() }) .setDescription( - `**${embedIcons.success} Loop mode disabled**\nChanging loop mode from \`${currentModeUserString}\` to \`${modeUserString}\`.\n\nThe ${currentModeUserString} will no longer play on repeat!` + `**${embedOptions.icons.success} Loop mode disabled**\nChanging loop mode from \`${currentModeUserString}\` to \`${modeUserString}\`.\n\nThe ${currentModeUserString} will no longer play on repeat!` ) - .setColor(embedColors.colorSuccess) + .setColor(embedOptions.colors.success) ] }); } @@ -123,9 +123,9 @@ module.exports = { iconURL: interaction.user.avatarURL() }) .setDescription( - `**${embedIcons.autoplaying} Loop mode changed**\nChanging loop mode from \`${currentModeUserString}\` to \`${modeUserString}\`.\n\nWhen the queue is empty, similar tracks will start playing!` + `**${embedOptions.icons.autoplaying} Loop mode changed**\nChanging loop mode from \`${currentModeUserString}\` to \`${modeUserString}\`.\n\nWhen the queue is empty, similar tracks will start playing!` ) - .setColor(embedColors.colorSuccess) + .setColor(embedOptions.colors.success) ] }); } @@ -138,9 +138,9 @@ module.exports = { iconURL: interaction.user.avatarURL() }) .setDescription( - `**${embedIcons.looping} Loop mode changed**\nChanging loop mode from \`${currentModeUserString}\` to \`${modeUserString}\`.\n\nThe ${modeUserString} will now play on repeat!` + `**${embedOptions.icons.looping} Loop mode changed**\nChanging loop mode from \`${currentModeUserString}\` to \`${modeUserString}\`.\n\nThe ${modeUserString} will now play on repeat!` ) - .setColor(embedColors.colorSuccess) + .setColor(embedOptions.colors.success) ] }); } diff --git a/src/commands/player/nowplaying.js b/src/commands/player/nowplaying.js index 750bfa9..991cdc3 100644 --- a/src/commands/player/nowplaying.js +++ b/src/commands/player/nowplaying.js @@ -1,8 +1,6 @@ -const path = require('node:path'); -const { SlashCommandBuilder } = require('@discordjs/builders'); +const { embedOptions, playerOptions } = require('../../config'); +const { SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ButtonBuilder } = require('discord.js'); const { useQueue } = require('discord-player'); -const { EmbedBuilder, ActionRowBuilder, ButtonBuilder } = require('discord.js'); -const { embedColors, embedIcons, progressBarOptions } = require(path.resolve('./config.json')); module.exports = { data: new SlashCommandBuilder() @@ -15,9 +13,9 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**${embedIcons.warning} Oops!**\nYou need to be in a voice channel to use this command.` + `**${embedOptions.icons.warning} Oops!**\nYou need to be in a voice channel to use this command.` ) - .setColor(embedColors.colorWarning) + .setColor(embedOptions.colors.warning) ] }); } @@ -29,9 +27,9 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**${embedIcons.warning} Oops!**\nThere are no tracks in the queue and nothing currently playing. First add some tracks with **\`/play\`**!` + `**${embedOptions.icons.warning} Oops!**\nThere are no tracks in the queue and nothing currently playing. First add some tracks with **\`/play\`**!` ) - .setColor(embedColors.colorWarning) + .setColor(embedOptions.colors.warning) ] }); } @@ -41,9 +39,9 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**${embedIcons.warning} Oops!**\nThere is nothing currently playing. First add some tracks with **\`/play\`**!` + `**${embedOptions.icons.warning} Oops!**\nThere is nothing currently playing. First add some tracks with **\`/play\`**!` ) - .setColor(embedColors.colorWarning) + .setColor(embedOptions.colors.warning) ] }); } @@ -57,11 +55,11 @@ module.exports = { ]); const sourceIcons = new Map([ - ['youtube', embedIcons.sourceYouTube], - ['soundcloud', embedIcons.sourceSoundCloud], - ['spotify', embedIcons.sourceSpotify], - ['apple_music', embedIcons.sourceAppleMusic], - ['arbitrary', embedIcons.sourceArbitrary] + ['youtube', embedOptions.icons.sourceYouTube], + ['soundcloud', embedOptions.icons.sourceSoundCloud], + ['spotify', embedOptions.icons.sourceSpotify], + ['apple_music', embedOptions.icons.sourceAppleMusic], + ['arbitrary', embedOptions.icons.sourceArbitrary] ]); const currentTrack = queue.currentTrack; @@ -88,11 +86,11 @@ module.exports = { const timestamp = queue.node.getTimestamp(); let bar = `**\`${timestamp.current.label}\`** ${queue.node.createProgressBar({ queue: false, - length: progressBarOptions.length ?? 12, - timecodes: progressBarOptions.timecodes ?? false, - indicator: progressBarOptions.indicator ?? '🔘', - leftChar: progressBarOptions.leftChar ?? '▬', - rightChar: progressBarOptions.rightChar ?? '▬' + length: playerOptions.progressBar.length ?? 12, + timecodes: playerOptions.progressBar.timecodes ?? false, + indicator: playerOptions.progressBar.indicator ?? '🔘', + leftChar: playerOptions.progressBar.leftChar ?? '▬', + rightChar: playerOptions.progressBar.rightChar ?? '▬' })} **\`${timestamp.total.label}\`**`; if (currentTrack.raw.duration === 0 || currentTrack.duration === '0:00') { @@ -104,7 +102,7 @@ module.exports = { .setCustomId('nowplaying-skip') .setLabel('Skip track') .setStyle('Secondary') - .setEmoji(embedIcons.nextTrack) + .setEmoji(embedOptions.icons.nextTrack) ); const loopModesFormatted = new Map([ @@ -126,7 +124,7 @@ module.exports = { .setDescription( (queue.node.isPaused() ? '**Currently Paused**\n' - : `**${embedIcons.audioPlaying} Now Playing**\n`) + + : `**${embedOptions.icons.audioPlaying} Now Playing**\n`) + `**[${currentTrack.title}](${currentTrack.url})**` + `\nRequested by: <@${currentTrack.requestedBy.id}>` + `\n ${bar}\n\n` + @@ -134,7 +132,7 @@ module.exports = { queue.repeatMode === 0 ? '' : `**${ - queue.repeatMode === 3 ? embedIcons.autoplay : embedIcons.loop + queue.repeatMode === 3 ? embedOptions.icons.autoplay : embedOptions.icons.loop } Looping**\nLoop mode is set to ${loopModeUserString}. You can change it with **\`/loop\`**.` }` ) @@ -159,7 +157,7 @@ module.exports = { text: queueLength ? `${queueLength} other tracks in the queue...` : ' ' }) .setThumbnail(queue.currentTrack.thumbnail) - .setColor(embedColors.colorInfo) + .setColor(embedOptions.colors.info) ], components: [nowPlayingActionRow] }); @@ -179,9 +177,9 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**${embedIcons.warning} Oops!**\nThere is nothing currently playing. First add some tracks with **\`/play\`**!` + `**${embedOptions.icons.warning} Oops!**\nThere is nothing currently playing. First add some tracks with **\`/play\`**!` ) - .setColor(embedColors.colorWarning) + .setColor(embedOptions.colors.warning) ], components: [] }); @@ -192,9 +190,9 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**${embedIcons.warning} Oops!**\nThis track has already been skipped or is no longer playing.` + `**${embedOptions.icons.warning} Oops!**\nThis track has already been skipped or is no longer playing.` ) - .setColor(embedColors.colorWarning) + .setColor(embedOptions.colors.warning) ], components: [] }); @@ -217,17 +215,19 @@ module.exports = { iconURL: interaction.user.avatarURL() }) .setDescription( - `**${embedIcons.skipped} Skipped track**\n**${durationFormat} [${skippedTrack.title}](${skippedTrack.url})**` + + `**${embedOptions.icons.skipped} Skipped track**\n**${durationFormat} [${skippedTrack.title}](${skippedTrack.url})**` + `${ queue.repeatMode === 0 ? '' : `\n\n**${ - queue.repeatMode === 3 ? embedIcons.autoplaying : embedIcons.looping + queue.repeatMode === 3 + ? embedOptions.icons.autoplaying + : embedOptions.icons.looping } Looping**\nLoop mode is set to ${repeatModeUserString}. You can change it with **\`/loop\`**.` }` ) .setThumbnail(skippedTrack.thumbnail) - .setColor(embedColors.colorSuccess) + .setColor(embedOptions.colors.success) ], components: [] }); diff --git a/src/commands/player/pause.js b/src/commands/player/pause.js index a14c9ee..787f1c6 100644 --- a/src/commands/player/pause.js +++ b/src/commands/player/pause.js @@ -1,8 +1,6 @@ -const path = require('node:path'); -const { SlashCommandBuilder } = require('@discordjs/builders'); +const { embedOptions } = require('../../config'); +const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); const { useQueue } = require('discord-player'); -const { EmbedBuilder } = require('discord.js'); -const { embedColors, embedIcons } = require(path.resolve('./config.json')); module.exports = { data: new SlashCommandBuilder() @@ -15,9 +13,9 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**${embedIcons.warning} Oops!**\nYou need to be in a voice channel to use this command.` + `**${embedOptions.icons.warning} Oops!**\nYou need to be in a voice channel to use this command.` ) - .setColor(embedColors.colorWarning) + .setColor(embedOptions.colors.warning) ] }); } @@ -29,9 +27,9 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**${embedIcons.warning} Oops!**\nThere are no tracks in the queue and nothing currently playing. First add some tracks with **\`/play\`**!` + `**${embedOptions.icons.warning} Oops!**\nThere are no tracks in the queue and nothing currently playing. First add some tracks with **\`/play\`**!` ) - .setColor(embedColors.colorWarning) + .setColor(embedOptions.colors.warning) ] }); } @@ -41,9 +39,9 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**${embedIcons.warning} Oops!**\nThere is nothing currently playing. First add some tracks with **\`/play\`**!` + `**${embedOptions.icons.warning} Oops!**\nThere is nothing currently playing. First add some tracks with **\`/play\`**!` ) - .setColor(embedColors.colorWarning) + .setColor(embedOptions.colors.warning) ] }); } @@ -64,12 +62,12 @@ module.exports = { iconURL: interaction.user.avatarURL() }) .setDescription( - `**${embedIcons.pauseResumed} ${ + `**${embedOptions.icons.pauseResumed} ${ queue.node.isPaused() ? 'Paused Track' : 'Resumed track' }**\n**${durationFormat} [${queue.currentTrack.title}](${queue.currentTrack.url})**` ) .setThumbnail(queue.currentTrack.thumbnail) - .setColor(embedColors.colorSuccess) + .setColor(embedOptions.colors.success) ] }); } diff --git a/src/commands/player/play.js b/src/commands/player/play.js index d3177b8..a66db10 100644 --- a/src/commands/player/play.js +++ b/src/commands/player/play.js @@ -1,8 +1,6 @@ -const path = require('node:path'); -const { SlashCommandBuilder } = require('@discordjs/builders'); +const { embedOptions, playerOptions, botOptions } = require('../../config'); +const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); const { useMainPlayer, useQueue } = require('discord-player'); -const { EmbedBuilder } = require('discord.js'); -const { embedColors, embedIcons, playerOptions, botInfo } = require(path.resolve('./config.json')); module.exports = { data: new SlashCommandBuilder() @@ -16,9 +14,9 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**${embedIcons.warning} Oops!**\nYou need to be in a voice channel to use this command.` + `**${embedOptions.icons.warning} Oops!**\nYou need to be in a voice channel to use this command.` ) - .setColor(embedColors.colorWarning) + .setColor(embedOptions.colors.warning) ] }); } @@ -35,9 +33,9 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**${embedIcons.warning} No track found**\nNo results found for \`${query}\`.\n\nIf you specified a URL, please make sure it is valid and public.` + `**${embedOptions.icons.warning} No track found**\nNo results found for \`${query}\`.\n\nIf you specified a URL, please make sure it is valid and public.` ) - .setColor(embedColors.colorWarning) + .setColor(embedOptions.colors.warning) ] }); } @@ -51,9 +49,9 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**${embedIcons.warning} Unsupported audio source**\nYouTube live streams are currently not supported. This is due to issues with extracting audio from the livestream.\n\n_If you think this message is incorrect, please submit a bug report in the **[support server](${botInfo.supportServerInviteUrl})**._` + `**${embedOptions.icons.warning} Unsupported audio source**\nYouTube live streams are currently not supported. This is due to issues with extracting audio from the livestream.\n\n_If you think this message is incorrect, please submit a bug report in the **[support server](${botOptions.serverInviteUrl})**._` ) - .setColor(embedColors.colorWarning) + .setColor(embedOptions.colors.warning) ] }); } @@ -81,9 +79,9 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**${embedIcons.warning} Cannot retrieve audio for track**\nThis audio source is age restricted and requires login to access. Because of this I cannot retrieve the audio for the track.\n\n_If you think this message is incorrect, please submit a bug report in the **[support server](${botInfo.supportServerInviteUrl})**._` + `**${embedOptions.icons.warning} Cannot retrieve audio for track**\nThis audio source is age restricted and requires login to access. Because of this I cannot retrieve the audio for the track.\n\n_If you think this message is incorrect, please submit a bug report in the **[support server](${botOptions.serverInviteUrl})**._` ) - .setColor(embedColors.colorWarning) + .setColor(embedOptions.colors.warning) ] }); } @@ -98,9 +96,9 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**${embedIcons.error} Uh-oh... Failed to add track!**\nAfter finding a result, I was unable to retrieve audio for the track.\n\nYou can try to perform the command again.\n\n_If you think this message is incorrect, please submit a bug report in the **[support server](${botInfo.supportServerInviteUrl})**._` + `**${embedOptions.icons.error} Uh-oh... Failed to add track!**\nAfter finding a result, I was unable to retrieve audio for the track.\n\nYou can try to perform the command again.\n\n_If you think this message is incorrect, please submit a bug report in the **[support server](${botOptions.serverInviteUrl})**._` ) - .setColor(embedColors.colorError) + .setColor(embedOptions.colors.error) ] }); } @@ -110,9 +108,9 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**${embedIcons.error} Uh-oh... Failed to add track!**\nSomething unexpected happened and the operation was cancelled.\n\nYou can try to perform the command again.\n\n_If you think this message is incorrect, please submit a bug report in the **[support server](${botInfo.supportServerInviteUrl})**._` + `**${embedOptions.icons.error} Uh-oh... Failed to add track!**\nSomething unexpected happened and the operation was cancelled.\n\nYou can try to perform the command again.\n\n_If you think this message is incorrect, please submit a bug report in the **[support server](${botOptions.serverInviteUrl})**._` ) - .setColor(embedColors.colorError) + .setColor(embedOptions.colors.error) ] }); } @@ -125,9 +123,9 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**${embedIcons.error} Uh-oh... Failed to add track!**\nThere was an issue adding this track to the queue.\n\nYou can try to perform the command again.\n\n_If this problem persists, please submit a bug report in the **[support server](${botInfo.supportServerInviteUrl})**._` + `**${embedOptions.icons.error} Uh-oh... Failed to add track!**\nThere was an issue adding this track to the queue.\n\nYou can try to perform the command again.\n\n_If this problem persists, please submit a bug report in the **[support server](${botOptions.serverInviteUrl})**._` ) - .setColor(embedColors.colorError) + .setColor(embedOptions.colors.error) ] }); } @@ -148,14 +146,14 @@ module.exports = { iconURL: interaction.user.avatarURL() }) .setDescription( - `**${embedIcons.success} Added playlist to queue**\n**${durationFormat} [${track.title}](${ - track.url - })**\n\nAnd **${ + `**${embedOptions.icons.success} Added playlist to queue**\n**${durationFormat} [${ + track.title + }](${track.url})**\n\nAnd **${ searchResult.tracks.length - 1 }** more tracks... **\`/queue\`** to view all.` ) .setThumbnail(track.thumbnail) - .setColor(embedColors.colorSuccess) + .setColor(embedOptions.colors.success) ] }); } @@ -170,10 +168,10 @@ module.exports = { iconURL: interaction.user.avatarURL() }) .setDescription( - `**${embedIcons.audioStartedPlaying} Started playing**\n**${durationFormat} [${track.title}](${track.url})**` + `**${embedOptions.icons.audioStartedPlaying} Started playing**\n**${durationFormat} [${track.title}](${track.url})**` ) .setThumbnail(track.thumbnail) - .setColor(embedColors.colorSuccess) + .setColor(embedOptions.colors.success) ] }); } @@ -186,10 +184,10 @@ module.exports = { iconURL: interaction.user.avatarURL() }) .setDescription( - `${embedIcons.success} **Added to queue**\n**${durationFormat} [${track.title}](${track.url})**` + `${embedOptions.icons.success} **Added to queue**\n**${durationFormat} [${track.title}](${track.url})**` ) .setThumbnail(track.thumbnail) - .setColor(embedColors.colorSuccess) + .setColor(embedOptions.colors.success) ] }); } diff --git a/src/commands/player/queue.js b/src/commands/player/queue.js index f5a2547..c7875f1 100644 --- a/src/commands/player/queue.js +++ b/src/commands/player/queue.js @@ -1,8 +1,6 @@ -const path = require('node:path'); -const { SlashCommandBuilder } = require('@discordjs/builders'); +const { embedOptions, playerOptions } = require('../../config'); +const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); const { useQueue } = require('discord-player'); -const { EmbedBuilder } = require('discord.js'); -const { embedColors, embedIcons, progressBarOptions } = require(path.resolve('./config.json')); module.exports = { data: new SlashCommandBuilder() @@ -16,9 +14,9 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**${embedIcons.warning} Oops!**\nYou need to be in a voice channel to use this command.` + `**${embedOptions.icons.warning} Oops!**\nYou need to be in a voice channel to use this command.` ) - .setColor(embedColors.colorWarning) + .setColor(embedOptions.colors.warning) ] }); } @@ -33,11 +31,11 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**${embedIcons.warning} Oops!**\nPage \`${ + `**${embedOptions.icons.warning} Oops!**\nPage \`${ pageIndex + 1 }\` is not a valid page number.\n\nThe queue is currently empty, first add some tracks with **\`/play\`**!` ) - .setColor(embedColors.colorWarning) + .setColor(embedOptions.colors.warning) ] }); } @@ -50,8 +48,8 @@ module.exports = { name: interaction.guild.name, iconURL: interaction.guild.iconURL() }) - .setDescription(`**${embedIcons.queue} Tracks in queue**\n${queueString}`) - .setColor(embedColors.colorInfo) + .setDescription(`**${embedOptions.icons.queue} Tracks in queue**\n${queueString}`) + .setColor(embedOptions.colors.info) .setFooter({ text: 'Page 1 of 1' }) @@ -66,11 +64,11 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**${embedIcons.warning} Oops!**\nPage \`${ + `**${embedOptions.icons.warning} Oops!**\nPage \`${ pageIndex + 1 }\` is not a valid page number.\n\nThere are only a total of \`${totalPages}\` pages in the queue.` ) - .setColor(embedColors.colorWarning) + .setColor(embedOptions.colors.warning) ] }); } @@ -104,7 +102,7 @@ module.exports = { queue.repeatMode === 0 ? '' : `**${ - queue.repeatMode === 3 ? embedIcons.autoplay : embedIcons.loop + queue.repeatMode === 3 ? embedOptions.icons.autoplay : embedOptions.icons.loop } Looping**\nLoop mode is set to ${loopModeUserString}. You can change it with **\`/loop\`**.\n\n` }`; @@ -117,23 +115,23 @@ module.exports = { iconURL: interaction.guild.iconURL() }) .setDescription( - `${repeatModeString}` + `**${embedIcons.queue} Tracks in queue**\n${queueString}` + `${repeatModeString}` + `**${embedOptions.icons.queue} Tracks in queue**\n${queueString}` ) .setFooter({ text: `Page ${pageIndex + 1} of ${totalPages}` }) - .setColor(embedColors.colorInfo) + .setColor(embedOptions.colors.info) ] }); } else { const timestamp = queue.node.getTimestamp(); let bar = `**\`${timestamp.current.label}\`** ${queue.node.createProgressBar({ queue: false, - length: progressBarOptions.length ?? 12, - timecodes: progressBarOptions.timecodes ?? false, - indicator: progressBarOptions.indicator ?? '🔘', - leftChar: progressBarOptions.leftChar ?? '▬', - rightChar: progressBarOptions.rightChar ?? '▬' + length: playerOptions.progressBar.length ?? 12, + timecodes: playerOptions.progressBar.timecodes ?? false, + indicator: playerOptions.progressBar.indicator ?? '🔘', + leftChar: playerOptions.progressBar.leftChar ?? '▬', + rightChar: playerOptions.progressBar.rightChar ?? '▬' })} **\`${timestamp.total.label}\`**`; if (currentTrack.raw.duration === 0 || currentTrack.duration === '0:00') { @@ -148,18 +146,18 @@ module.exports = { iconURL: interaction.guild.iconURL() }) .setDescription( - `**${embedIcons.audioPlaying} Now playing**\n` + + `**${embedOptions.icons.audioPlaying} Now playing**\n` + (currentTrack ? `**[${currentTrack.title}](${currentTrack.url})**` : 'None') + `\nRequested by: <@${currentTrack.requestedBy.id}>` + `\n ${bar}\n\n` + `${repeatModeString}` + - `**${embedIcons.queue} Tracks in queue**\n${queueString}` + `**${embedOptions.icons.queue} Tracks in queue**\n${queueString}` ) .setThumbnail(queue.currentTrack.thumbnail) .setFooter({ text: `Page ${pageIndex + 1} of ${totalPages}` }) - .setColor(embedColors.colorInfo) + .setColor(embedOptions.colors.info) ] }); } diff --git a/src/commands/player/remove.js b/src/commands/player/remove.js index 3a3eabb..6ea818f 100644 --- a/src/commands/player/remove.js +++ b/src/commands/player/remove.js @@ -1,8 +1,6 @@ -const path = require('node:path'); -const { SlashCommandBuilder } = require('@discordjs/builders'); +const { embedOptions } = require('../../config'); +const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); const { useQueue } = require('discord-player'); -const { EmbedBuilder } = require('discord.js'); -const { embedColors, embedIcons } = require(path.resolve('./config.json')); module.exports = { data: new SlashCommandBuilder() @@ -22,9 +20,9 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**${embedIcons.warning} Oops!**\nYou need to be in a voice channel to use this command.` + `**${embedOptions.icons.warning} Oops!**\nYou need to be in a voice channel to use this command.` ) - .setColor(embedColors.colorWarning) + .setColor(embedOptions.colors.warning) ] }); } @@ -36,9 +34,9 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**${embedIcons.warning} Oops!**\nThere are no tracks in the queue and nothing currently playing. First add some tracks with **\`/play\`**!` + `**${embedOptions.icons.warning} Oops!**\nThere are no tracks in the queue and nothing currently playing. First add some tracks with **\`/play\`**!` ) - .setColor(embedColors.colorWarning) + .setColor(embedOptions.colors.warning) ] }); } @@ -50,9 +48,9 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**${embedIcons.warning} Oops!**\nTrack \`${removeTrackNumber}\` is not a valid track number. There are a total of\`${queue.tracks.data.length}\` tracks in the queue.\n\nView tracks added to the queue with **\`/queue\`**.` + `**${embedOptions.icons.warning} Oops!**\nTrack \`${removeTrackNumber}\` is not a valid track number. There are a total of\`${queue.tracks.data.length}\` tracks in the queue.\n\nView tracks added to the queue with **\`/queue\`**.` ) - .setColor(embedColors.colorWarning) + .setColor(embedOptions.colors.warning) ] }); } @@ -70,10 +68,10 @@ module.exports = { iconURL: interaction.user.avatarURL() }) .setDescription( - `**${embedIcons.success} Removed track**\n**${durationFormat} [${removedTrack.title}](${removedTrack.url})**` + `**${embedOptions.icons.success} Removed track**\n**${durationFormat} [${removedTrack.title}](${removedTrack.url})**` ) .setThumbnail(removedTrack.thumbnail) - .setColor(embedColors.colorSuccess) + .setColor(embedOptions.colors.success) ] }); } diff --git a/src/commands/player/seek.js b/src/commands/player/seek.js index d7c05ae..13a2119 100644 --- a/src/commands/player/seek.js +++ b/src/commands/player/seek.js @@ -1,8 +1,6 @@ -const path = require('node:path'); -const { SlashCommandBuilder } = require('@discordjs/builders'); +const { embedOptions } = require('../../config'); +const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); const { useQueue } = require('discord-player'); -const { EmbedBuilder } = require('discord.js'); -const { embedColors, embedIcons } = require(path.resolve('./config.json')); module.exports = { data: new SlashCommandBuilder() @@ -21,9 +19,9 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**${embedIcons.warning} Oops!**\nYou need to be in a voice channel to use this command.` + `**${embedOptions.icons.warning} Oops!**\nYou need to be in a voice channel to use this command.` ) - .setColor(embedColors.colorWarning) + .setColor(embedOptions.colors.warning) ] }); } @@ -35,9 +33,9 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**${embedIcons.warning} Oops!**\nThere are no tracks in the queue and nothing currently playing. First add some tracks with **\`/play\`**!` + `**${embedOptions.icons.warning} Oops!**\nThere are no tracks in the queue and nothing currently playing. First add some tracks with **\`/play\`**!` ) - .setColor(embedColors.colorWarning) + .setColor(embedOptions.colors.warning) ] }); } @@ -47,9 +45,9 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**${embedIcons.warning} Oops!**\nThere is nothing currently playing. First add some tracks with **\`/play\`**!` + `**${embedOptions.icons.warning} Oops!**\nThere is nothing currently playing. First add some tracks with **\`/play\`**!` ) - .setColor(embedColors.colorWarning) + .setColor(embedOptions.colors.warning) ] }); } @@ -73,12 +71,12 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**${embedIcons.warning} Oops!**\nYou entered an invalid duration format, \`${durationString}\`.\n\nPlease use the format \`HH:mm:ss\`, \`mm:ss\` or \`ss\`, where \`HH\` is hours, \`mm\` is minutes and \`ss\` is seconds.\n\n**Examples:**\n` + + `**${embedOptions.icons.warning} Oops!**\nYou entered an invalid duration format, \`${durationString}\`.\n\nPlease use the format \`HH:mm:ss\`, \`mm:ss\` or \`ss\`, where \`HH\` is hours, \`mm\` is minutes and \`ss\` is seconds.\n\n**Examples:**\n` + '- `/seek` **`1:24:12`** - Seek to 1 hour, 24 minutes and 12 seconds.\n' + '- `/seek` **`3:27`** - Seek to 3 minutes and 27 seconds.\n' + '- `/seek` **`42`** - Seek to 42 seconds.' ) - .setColor(embedColors.colorWarning) + .setColor(embedOptions.colors.warning) ] }); } @@ -98,12 +96,12 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**${embedIcons.warning} Oops!**\nYou entered an invalid duration format, \`${durationString}\`.\n\nPlease use the format \`HH:mm:ss\`, \`mm:ss\` or \`ss\`, where \`HH\` is hours, \`mm\` is minutes and \`ss\` is seconds.\n\n**Examples:**\n` + + `**${embedOptions.icons.warning} Oops!**\nYou entered an invalid duration format, \`${durationString}\`.\n\nPlease use the format \`HH:mm:ss\`, \`mm:ss\` or \`ss\`, where \`HH\` is hours, \`mm\` is minutes and \`ss\` is seconds.\n\n**Examples:**\n` + '- `/seek` **`1:24:12`** - Seek to 1 hour, 24 minutes and 12 seconds.\n' + '- `/seek` **`3:27`** - Seek to 3 minutes and 27 seconds.\n' + '- `/seek` **`42`** - Seek to 42 seconds.' ) - .setColor(embedColors.colorWarning) + .setColor(embedOptions.colors.warning) ] }); } @@ -118,12 +116,12 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**${embedIcons.warning} Oops!**\nYou entered an invalid duration format, \`${durationString}\`.\n\nPlease use the format \`HH:mm:ss\`, \`mm:ss\` or \`ss\`, where \`HH\` is hours, \`mm\` is minutes and \`ss\` is seconds.\n\n**Examples:**\n` + + `**${embedOptions.icons.warning} Oops!**\nYou entered an invalid duration format, \`${durationString}\`.\n\nPlease use the format \`HH:mm:ss\`, \`mm:ss\` or \`ss\`, where \`HH\` is hours, \`mm\` is minutes and \`ss\` is seconds.\n\n**Examples:**\n` + '- `/seek` **`1:24:12`** - Seek to 1 hour, 24 minutes and 12 seconds.\n' + '- `/seek` **`3:27`** - Seek to 3 minutes and 27 seconds.\n' + '- `/seek` **`42`** - Seek to 42 seconds.' ) - .setColor(embedColors.colorWarning) + .setColor(embedOptions.colors.warning) ] }); } @@ -136,9 +134,9 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**${embedIcons.warning} Oops!**\nYou entered **\`${durationString}\`**, which is a duration that is longer than the duration for the current track.\n\nPlease try a duration that is less than the duration of the track (**\`${queue.currentTrack.duration}\`**).` + `**${embedOptions.icons.warning} Oops!**\nYou entered **\`${durationString}\`**, which is a duration that is longer than the duration for the current track.\n\nPlease try a duration that is less than the duration of the track (**\`${queue.currentTrack.duration}\`**).` ) - .setColor(embedColors.colorWarning) + .setColor(embedOptions.colors.warning) ] }); } @@ -152,10 +150,10 @@ module.exports = { iconURL: interaction.user.avatarURL() }) .setDescription( - `**${embedIcons.success} Seeking to duration**\nSeeking to **\`${durationString}\`** in current track.` + `**${embedOptions.icons.success} Seeking to duration**\nSeeking to **\`${durationString}\`** in current track.` ) .setThumbnail(queue.currentTrack.thumbnail) - .setColor(embedColors.colorSuccess) + .setColor(embedOptions.colors.success) ] }); } diff --git a/src/commands/player/skip.js b/src/commands/player/skip.js index 5b2423a..6ba871d 100644 --- a/src/commands/player/skip.js +++ b/src/commands/player/skip.js @@ -1,8 +1,6 @@ -const path = require('node:path'); -const { SlashCommandBuilder } = require('@discordjs/builders'); +const { embedOptions } = require('../../config'); +const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); const { useQueue } = require('discord-player'); -const { EmbedBuilder } = require('discord.js'); -const { embedColors, embedIcons } = require(path.resolve('./config.json')); module.exports = { data: new SlashCommandBuilder() @@ -18,9 +16,9 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**${embedIcons.warning} Oops!**\nYou need to be in a voice channel to use this command.` + `**${embedOptions.icons.warning} Oops!**\nYou need to be in a voice channel to use this command.` ) - .setColor(embedColors.colorWarning) + .setColor(embedOptions.colors.warning) ] }); } @@ -32,9 +30,9 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**${embedIcons.warning} Oops!**\nThere are no tracks in the queue and nothing currently playing. First add some tracks with **\`/play\`**!` + `**${embedOptions.icons.warning} Oops!**\nThere are no tracks in the queue and nothing currently playing. First add some tracks with **\`/play\`**!` ) - .setColor(embedColors.colorWarning) + .setColor(embedOptions.colors.warning) ] }); } @@ -47,9 +45,9 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**${embedIcons.warning} Oops!**\nThere are only \`${queue.tracks.data.length}\` tracks in the queue. You cannot skip to track \`${skipToTrack}\`.\n\nView tracks added to the queue with **\`/queue\`**.` + `**${embedOptions.icons.warning} Oops!**\nThere are only \`${queue.tracks.data.length}\` tracks in the queue. You cannot skip to track \`${skipToTrack}\`.\n\nView tracks added to the queue with **\`/queue\`**.` ) - .setColor(embedColors.colorWarning) + .setColor(embedOptions.colors.warning) ] }); } else { @@ -68,10 +66,10 @@ module.exports = { iconURL: interaction.user.avatarURL() }) .setDescription( - `**${embedIcons.skipped} Skipped track**\n**${durationFormat} [${skippedTrack.title}](${skippedTrack.url})**` + `**${embedOptions.icons.skipped} Skipped track**\n**${durationFormat} [${skippedTrack.title}](${skippedTrack.url})**` ) .setThumbnail(skippedTrack.thumbnail) - .setColor(embedColors.colorSuccess) + .setColor(embedOptions.colors.success) ] }); } @@ -81,9 +79,9 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**${embedIcons.warning} Oops!**\nThere is nothing currently playing. First add some tracks with **\`/play\`**!` + `**${embedOptions.icons.warning} Oops!**\nThere is nothing currently playing. First add some tracks with **\`/play\`**!` ) - .setColor(embedColors.colorWarning) + .setColor(embedOptions.colors.warning) ] }); } @@ -112,17 +110,19 @@ module.exports = { iconURL: interaction.user.avatarURL() }) .setDescription( - `**${embedIcons.skipped} Skipped track**\n**${durationFormat} [${skippedTrack.title}](${skippedTrack.url})**` + + `**${embedOptions.icons.skipped} Skipped track**\n**${durationFormat} [${skippedTrack.title}](${skippedTrack.url})**` + `${ queue.repeatMode === 0 ? '' : `\n\n**${ - queue.repeatMode === 3 ? embedIcons.autoplaying : embedIcons.looping + queue.repeatMode === 3 + ? embedOptions.icons.autoplaying + : embedOptions.icons.looping } Looping**\nLoop mode is set to ${loopModeUserString}. You can change it with **\`/loop\`**.` }` ) .setThumbnail(skippedTrack.thumbnail) - .setColor(embedColors.colorSuccess) + .setColor(embedOptions.colors.success) ] }); } diff --git a/src/commands/player/volume.js b/src/commands/player/volume.js index 1cbbd8c..28ba226 100644 --- a/src/commands/player/volume.js +++ b/src/commands/player/volume.js @@ -1,8 +1,6 @@ -const path = require('node:path'); -const { SlashCommandBuilder } = require('@discordjs/builders'); +const { embedOptions } = require('../../config'); +const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); const { useQueue } = require('discord-player'); -const { EmbedBuilder } = require('discord.js'); -const { embedColors, embedIcons } = require(path.resolve('./config.json')); module.exports = { data: new SlashCommandBuilder() @@ -22,9 +20,9 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**${embedIcons.warning} Oops!**\nYou need to be in a voice channel to use this command.` + `**${embedOptions.icons.warning} Oops!**\nYou need to be in a voice channel to use this command.` ) - .setColor(embedColors.colorWarning) + .setColor(embedOptions.colors.warning) ] }); } @@ -36,9 +34,9 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**${embedIcons.warning} Oops!**\nThere are no tracks in the queue and nothing currently playing. First add some tracks with **\`/play\`**!` + `**${embedOptions.icons.warning} Oops!**\nThere are no tracks in the queue and nothing currently playing. First add some tracks with **\`/play\`**!` ) - .setColor(embedColors.colorWarning) + .setColor(embedOptions.colors.warning) ] }); } @@ -53,10 +51,10 @@ module.exports = { new EmbedBuilder() .setDescription( `**${ - currentVolume === 0 ? embedIcons.volumeIsMuted : embedIcons.volume + currentVolume === 0 ? embedOptions.icons.volumeIsMuted : embedOptions.icons.volume } Playback volume**\nThe playback volume is currently set to \`${currentVolume}%\`.` ) - .setColor(embedColors.colorInfo) + .setColor(embedOptions.colors.info) ] }); } else if (volume > 100 || volume < 0) { @@ -64,9 +62,9 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**${embedIcons.warning} Oops!**\nYou cannot set the volume to \`${volume}\`, please pick a value betwen \`1\`% and \`100\`%.` + `**${embedOptions.icons.warning} Oops!**\nYou cannot set the volume to \`${volume}\`, please pick a value betwen \`1\`% and \`100\`%.` ) - .setColor(embedColors.colorWarning) + .setColor(embedOptions.colors.warning) ] }); } else { @@ -81,9 +79,9 @@ module.exports = { iconURL: interaction.user.avatarURL() }) .setDescription( - `**${embedIcons.volumeMuted} Audio muted**\nPlayback audio has been muted, because volume was set to \`${volume}%\`.` + `**${embedOptions.icons.volumeMuted} Audio muted**\nPlayback audio has been muted, because volume was set to \`${volume}%\`.` ) - .setColor(embedColors.colorSuccess) + .setColor(embedOptions.colors.success) ] }); } @@ -96,9 +94,9 @@ module.exports = { iconURL: interaction.user.avatarURL() }) .setDescription( - `**${embedIcons.volumeChanged} Volume changed**\nPlayback volume has been changed to \`${volume}%\`.` + `**${embedOptions.icons.volumeChanged} Volume changed**\nPlayback volume has been changed to \`${volume}%\`.` ) - .setColor(embedColors.colorSuccess) + .setColor(embedOptions.colors.success) ] }); } diff --git a/src/commands/system/guilds.js b/src/commands/system/guilds.js index f1a909d..7bac512 100644 --- a/src/commands/system/guilds.js +++ b/src/commands/system/guilds.js @@ -1,7 +1,5 @@ -const path = require('node:path'); -const { SlashCommandBuilder } = require('@discordjs/builders'); -const { EmbedBuilder } = require('discord.js'); -const { embedColors, embedIcons, systemServerGuildIds } = require(path.resolve('./config.json')); +const { embedOptions, systemOptions } = require('../../config'); +const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); module.exports = { isSystemCommand: true, @@ -10,14 +8,14 @@ module.exports = { .setDescription('Show list of guilds where bot is added.') .setDMPermission(false), execute: async ({ interaction, client }) => { - if (!systemServerGuildIds.includes(interaction.guildId)) { + if (!systemOptions.systemGuildIds.includes(interaction.guildId)) { return await interaction.editReply({ embeds: [ new EmbedBuilder() .setDescription( - `**${embedIcons.warning} Oops!**\nNo permission to execute this command.\n\nThe command \`${interaction.commandName}\` cannot be executed in this server.` + `**${embedOptions.icons.warning} Oops!**\nNo permission to execute this command.\n\nThe command \`${interaction.commandName}\` cannot be executed in this server.` ) - .setColor(embedColors.colorWarning) + .setColor(embedOptions.colors.warning) ] }); } @@ -37,7 +35,7 @@ module.exports = { const totalMemberCount = client.guilds.cache.reduce((a, b) => a + b.memberCount, 0); let embedDescription = - `**${embedIcons.bot} ${ + `**${embedOptions.icons.bot} ${ client.guilds.cache.size < 50 ? `Top ${client.guilds.cache.size} guilds` : 'Top 50 guilds' } by member count (${client.guilds.cache.size} total)**\n${guildsList}` + `\n\n**Total members:** \`${totalMemberCount}\``; @@ -47,7 +45,7 @@ module.exports = { } return await interaction.editReply({ - embeds: [new EmbedBuilder().setDescription(embedDescription).setColor(embedColors.colorInfo)] + embeds: [new EmbedBuilder().setDescription(embedDescription).setColor(embedOptions.colors.info)] }); } }; diff --git a/src/commands/system/status.js b/src/commands/system/status.js index 53a408f..09dec62 100644 --- a/src/commands/system/status.js +++ b/src/commands/system/status.js @@ -1,23 +1,21 @@ -const path = require('node:path'); -const { SlashCommandBuilder } = require('@discordjs/builders'); -const { EmbedBuilder } = require('discord.js'); +const { embedOptions, systemOptions } = require('../../config'); +const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); const { useQueue } = require('discord-player'); -const { embedColors, embedIcons, systemServerGuildIds } = require(path.resolve('./config.json')); const osu = require('node-os-utils'); -const packageJson = require(path.resolve('./package.json')); +const { version, dependencies } = require('../../../package.json'); module.exports = { isSystemCommand: true, data: new SlashCommandBuilder().setName('status').setDescription('Show bot status.').setDMPermission(false), execute: async ({ interaction, client }) => { - if (!systemServerGuildIds.includes(interaction.guildId)) { + if (!systemOptions.systemGuildIds.includes(interaction.guildId)) { return await interaction.editReply({ embeds: [ new EmbedBuilder() .setDescription( - `**${embedIcons.warning} Oops!**\nNo permission to execute this command.\n\nThe command \`${interaction.commandName}\` cannot be executed in this server.` + `**${embedOptions.icons.warning} Oops!**\nNo permission to execute this command.\n\nThe command \`${interaction.commandName}\` cannot be executed in this server.` ) - .setColor(embedColors.colorWarning) + .setColor(embedOptions.colors.warning) ] }); } @@ -32,9 +30,9 @@ module.exports = { const cpuUsage = await osu.cpu.usage(); const cpuCores = await osu.cpu.count(); const platform = await osu.os.platform(); - const releaseVersion = packageJson.version; - const discordJsVersion = packageJson.dependencies['discord.js']; - const discordPlayerVersion = packageJson.dependencies['discord-player']; + const releaseVersion = version; + const discordJsVersion = dependencies['discord.js']; + const discordPlayerVersion = dependencies['discord-player']; const discordApiLatency = client.ws.ping; let activeVoiceConnections = 0; client.guilds.cache.forEach((guild) => { @@ -49,7 +47,7 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**${embedIcons.bot} System and bot status**\n` + + `**${embedOptions.icons.bot} System and bot status**\n` + `Uptime: \`${uptimeString}\`\n` + `Platform: \`${platform}\`\n` + `CPU cores: \`${cpuCores}\`\n` + @@ -65,7 +63,7 @@ module.exports = { `Active voice connections: \`${activeVoiceConnections}\`\n` + `Joined guilds: \`${client.guilds.cache.size}\`` ) - .setColor(embedColors.colorInfo) + .setColor(embedOptions.colors.info) ] }); } diff --git a/src/config_example.js b/src/config_example.js new file mode 100644 index 0000000..bf6f918 --- /dev/null +++ b/src/config_example.js @@ -0,0 +1,152 @@ +// Description: Config file for Cadence Discord bot. + +// General options for information about the bot. +module.exports.botOptions = { + name: 'Cadence', + websiteUrl: 'Unknown', + botInviteUrl: 'Unknown', + serverInviteUrl: 'Unknown' +}; + +// Logging options for the bot, can set logging level to file and console separately. +module.exports.loggerOptions = { + minimumLogLevel: 'debug', + minimumLogLevelConsole: 'info' +}; + +// systemGuildIds: Array of guild ids where system commands should be available. +// systemMessageChannelId: Channel id where system messages should be sent, such as error events. +// systemUserId: User id of the system administrator, used for pining on certain system messages. +module.exports.systemOptions = { + systemGuildIds: ['Guild id where system commands can be used'], + systemMessageChannelId: 'Channel id where system messages will be sent', + systemUserId: 'User id of the system administrator which will receive pings on certain system messages' +}; + +// Options for embed messages, like colors and custom emojis. +module.exports.embedOptions = { + colors: { + success: '#23A55A', + warning: '#F0B232', + error: '#F23F43', + info: '#5865F2', + note: '#80848E' + }, + icons: { + logo: '🤖', + beta: '`beta`', + new: '`new`', + rule: '📒', + support: '❓', + bot: '🤖', + audioPlaying: '🎶', + audioStartedPlaying: '🎶', + success: '✅', + error: '⚠️', + warning: '⚠️', + disable: '🚫', + enable: '✅', + disabled: '✅', + enabled: '✅', + nextTrack: '⏭️', + previousTrack: '⏮️', + pauseResumeTrack: '⏯️', + shuffleQueue: '🔀', + loop: '🔁', + loopAction: '🔁', + autoplay: '♾️', + autoplayAction: '♾️', + looping: '🔁', + autoplaying: '♾️', + skipped: '⏭️', + back: '⏮️', + pauseResumed: '⏯️', + shuffled: '🔀', + volume: '🔊', + volumeIsMuted: '🔇', + volumeChanged: '🔊', + volumeMuted: '🔇', + queue: '🎶', + sourceArbitrary: '🎵', + sourceAppleMusic: '🎵', + sourceYouTube: '🎵', + sourceSoundCloud: '🎵', + sourceSpotify: '🎵' + } +}; + +// Options for the discord-player player. +module.exports.playerOptions = { + leaveOnEmpty: true, + leaveOnEmptyCooldown: 300000, + leaveOnEnd: true, + leaveonEndCooldown: 300000, + leaveOnStop: true, + leaveOnStopCooldown: 300000, + defaultVolume: 50, + maxQueueSize: 1000, + maxHistorySize: 100, + progressBar: { + length: 14, + timecodes: false, + separator: '┃', + indicator: '🔘', + leftChar: '▬', + rightChar: '▬' + } +}; + +// Options to be used by the ffmpeg, and available ffmpeg filters shown in filter commands. +module.exports.ffmpegFilterOptions = { + threadAmount: '2', + filterList: [ + { + label: 'Bass boost', + value: 'bassboost_low', + description: 'Boost the bass of the audio.', + emoji: '🔉' + }, + { + label: 'Bass boost high', + value: 'bassboost', + description: 'Boost the bass of the audio a lot.', + emoji: '🔊' + }, + { + label: 'Night core', + value: 'nightcore', + description: 'Speed up the audio (higher pitch).', + emoji: '🐱' + }, + { + label: 'Lo-fi', + value: 'lofi', + description: 'Low fidelity effect (lower quality).', + emoji: '📻' + }, + { + label: 'Vaporwave', + value: 'vaporwave', + description: 'Slow down the audio (lower pitch).', + emoji: '🌸' + }, + { + label: 'Ear rape', + value: 'earrape', + description: 'Extremely loud and distorted audio.', + emoji: '👂' + }, + { + label: '8D', + value: '8D', + description: 'Simulate 8D audio effect (surround).', + emoji: '🎧' + }, + { + label: 'Treble', + value: 'treble', + description: 'Increase the high frequencies.', + emoji: '🎼' + } + ] +}; diff --git a/src/events/client/debug.js b/src/events/client/debug.js index c4738c6..0416747 100644 --- a/src/events/client/debug.js +++ b/src/events/client/debug.js @@ -1,5 +1,4 @@ -const path = require('node:path'); -const logger = require(path.resolve('./src/services/logger.js')); +const logger = require('../../services/logger'); const { Events } = require('discord.js'); module.exports = { diff --git a/src/events/client/disconnect.js b/src/events/client/disconnect.js index f026722..bad4645 100644 --- a/src/events/client/disconnect.js +++ b/src/events/client/disconnect.js @@ -1,7 +1,6 @@ -const path = require('node:path'); -const logger = require(path.resolve('./src/services/logger.js')); +const logger = require('../../services/logger'); +const { embedOptions, systemOptions } = require('../../config'); const { EmbedBuilder } = require('discord.js'); -const { systemMessageChannelId, systemUserId, embedColors, embedIcons } = require(path.resolve('./config.json')); module.exports = { name: 'disconnect', @@ -11,15 +10,15 @@ module.exports = { logger.warn(`${client.user.tag} lost connection to Discord APIs. Disconnected.`); // send message to system message channel for event - if (systemMessageChannelId && systemUserId) { - await client.channels.cache.get(systemMessageChannelId).send({ + if (systemOptions.systemMessageChannelId && systemOptions.systemUserId) { + await client.channels.cache.get(systemOptions.systemMessageChannelId).send({ embeds: [ new EmbedBuilder() .setDescription( - `${embedIcons.warning} **${client.user.tag}** is **\`disconnected\`**!` + - `\n<@${systemUserId}>` + `${embedOptions.icons.warning} **${client.user.tag}** is **\`disconnected\`**!` + + `\n<@${systemOptions.systemUserId}>` ) - .setColor(embedColors.colorWarning) + .setColor(embedOptions.colors.warning) ] }); } diff --git a/src/events/client/error.js b/src/events/client/error.js index 285f503..f182933 100644 --- a/src/events/client/error.js +++ b/src/events/client/error.js @@ -1,5 +1,4 @@ -const path = require('node:path'); -const logger = require(path.resolve('./src/services/logger.js')); +const logger = require('../../services/logger'); const { Events } = require('discord.js'); module.exports = { diff --git a/src/events/client/guildCreate.js b/src/events/client/guildCreate.js index b700dd8..819882d 100644 --- a/src/events/client/guildCreate.js +++ b/src/events/client/guildCreate.js @@ -1,5 +1,4 @@ -const path = require('node:path'); -const logger = require(path.resolve('./src/services/logger.js')); +const logger = require('../../services/logger'); const { Events } = require('discord.js'); module.exports = { diff --git a/src/events/client/guildDelete.js b/src/events/client/guildDelete.js index 0da2e4f..4656580 100644 --- a/src/events/client/guildDelete.js +++ b/src/events/client/guildDelete.js @@ -1,5 +1,4 @@ -const path = require('node:path'); -const logger = require(path.resolve('./src/services/logger.js')); +const logger = require('../../services/logger'); const { Events } = require('discord.js'); module.exports = { diff --git a/src/events/client/ready.js b/src/events/client/ready.js index bbafd62..2813bcf 100644 --- a/src/events/client/ready.js +++ b/src/events/client/ready.js @@ -1,8 +1,7 @@ -const path = require('node:path'); -const logger = require(path.resolve('./src/services/logger.js')); +const logger = require('../../services/logger'); +const { embedOptions, systemOptions } = require('../../config'); const { Events, ActivityType, PresenceUpdateStatus, EmbedBuilder } = require('discord.js'); -const { postBotStats } = require(path.resolve('./src/utils/postBotStats.js')); -const { systemMessageChannelId, embedColors, embedIcons } = require(path.resolve('./config.json')); +const { postBotStats } = require('../../utils/postBotStats.js'); module.exports = { name: Events.ClientReady, @@ -24,12 +23,12 @@ module.exports = { process.env.NODE_ENV === 'production' ? postBotStats(client) : null; // send message to system message channel for event - if (systemMessageChannelId) { - await client.channels.cache.get(systemMessageChannelId).send({ + if (systemOptions.systemMessageChannelId) { + await client.channels.cache.get(systemOptions.systemMessageChannelId).send({ embeds: [ new EmbedBuilder() - .setDescription(`${embedIcons.success} **${client.user.tag}** is now **\`online\`**!`) - .setColor(embedColors.colorSuccess) + .setDescription(`${embedOptions.icons.success} **${client.user.tag}** is now **\`online\`**!`) + .setColor(embedOptions.colors.success) ] }); } diff --git a/src/events/client/reconnecting.js b/src/events/client/reconnecting.js index 8eb22db..e2f3184 100644 --- a/src/events/client/reconnecting.js +++ b/src/events/client/reconnecting.js @@ -1,7 +1,6 @@ -const path = require('node:path'); -const logger = require(path.resolve('./src/services/logger.js')); +const logger = require('../../services/logger'); +const { embedOptions, systemOptions } = require('../../config'); const { EmbedBuilder } = require('discord.js'); -const { systemMessageChannelId, systemUserId, embedColors, embedIcons } = require(path.resolve('./config.json')); module.exports = { name: 'reconnecting', @@ -11,15 +10,15 @@ module.exports = { logger.warn(`${client.user.tag} is reconnecting to Discord APIs.`); // send message to system message channel for event - if (systemMessageChannelId && systemUserId) { - await client.channels.cache.get(systemMessageChannelId).send({ + if (systemOptions.systemMessageChannelId && systemOptions.systemUserId) { + await client.channels.cache.get(systemOptions.systemMessageChannelId).send({ embeds: [ new EmbedBuilder() .setDescription( - `${embedIcons.warning} **${client.user.tag}** is **\`reconnecting\`**!` + - `\n<@${systemUserId}>` + `${embedOptions.icons.warning} **${client.user.tag}** is **\`reconnecting\`**!` + + `\n<@${systemOptions.systemUserId}>` ) - .setColor(embedColors.colorWarning) + .setColor(embedOptions.colors.warning) ] }); } diff --git a/src/events/client/warn.js b/src/events/client/warn.js index 06b7f4b..33e63a0 100644 --- a/src/events/client/warn.js +++ b/src/events/client/warn.js @@ -1,5 +1,4 @@ -const path = require('node:path'); -const logger = require(path.resolve('./src/services/logger.js')); +const logger = require('../../services/logger'); const { Events } = require('discord.js'); module.exports = { diff --git a/src/events/interactions/interactionCreate.js b/src/events/interactions/interactionCreate.js index 69906f6..bfe4da7 100644 --- a/src/events/interactions/interactionCreate.js +++ b/src/events/interactions/interactionCreate.js @@ -1,7 +1,6 @@ -const path = require('node:path'); -const logger = require(path.resolve('./src/services/logger.js')); +const logger = require('../../services/logger'); +const { embedOptions, botOptions } = require('../../config'); const { Events, EmbedBuilder } = require('discord.js'); -const { embedColors, embedIcons, botInfo } = require(path.resolve('./config.json')); module.exports = { name: Events.InteractionCreate, @@ -46,11 +45,11 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**${embedIcons.warning} Warning**\nThis command took ${ + `**${embedOptions.icons.warning} Warning**\nThis command took ${ executionTime / 1000 } seconds to execute.\n\n_If you experienced problems with the command, please try again._` ) - .setColor(embedColors.colorWarning) + .setColor(embedOptions.colors.warning) ] }); } else { @@ -68,9 +67,9 @@ module.exports = { embeds: [ new EmbedBuilder() .setDescription( - `**${embedIcons.error} Uh-oh... _Something_ went wrong!**\nThere was an unexpected error while trying to execute this command.\n\nYou can try to perform the command again.\n\n_If this problem persists, please submit a bug report in the **[support server](${botInfo.supportServerInviteUrl})**._` + `**${embedOptions.icons.error} Uh-oh... _Something_ went wrong!**\nThere was an unexpected error while trying to execute this command.\n\nYou can try to perform the command again.\n\n_If this problem persists, please submit a bug report in the **[support server](${botOptions.serverInviteUrl})**._` ) - .setColor(embedColors.colorError) + .setColor(embedOptions.colors.error) ] }); } diff --git a/src/events/player/error.js b/src/events/player/error.js index dc9789b..8a1c23a 100644 --- a/src/events/player/error.js +++ b/src/events/player/error.js @@ -1,6 +1,4 @@ -const path = require('node:path'); -const logger = require(path.resolve('./src/services/logger.js')); -require('dotenv').config(); +const logger = require('../../services/logger'); // Emitted when the player queue encounters error module.exports = { diff --git a/src/events/player/generalDebug.js b/src/events/player/generalDebug.js index 54e9dbc..1a42b06 100644 --- a/src/events/player/generalDebug.js +++ b/src/events/player/generalDebug.js @@ -1,6 +1,4 @@ -const path = require('node:path'); -const logger = require(path.resolve('./src/services/logger.js')); -require('dotenv').config(); +const logger = require('../../services/logger'); module.exports = { name: 'debug', diff --git a/src/events/player/playerDebug.js b/src/events/player/playerDebug.js index 5caf330..be15191 100644 --- a/src/events/player/playerDebug.js +++ b/src/events/player/playerDebug.js @@ -1,5 +1,4 @@ -const path = require('node:path'); -const logger = require(path.resolve('./src/services/logger.js')); +const logger = require('../../services/logger'); module.exports = { name: 'error', diff --git a/src/events/player/playerError.js b/src/events/player/playerError.js index 2755514..0393e37 100644 --- a/src/events/player/playerError.js +++ b/src/events/player/playerError.js @@ -1,5 +1,4 @@ -const path = require('node:path'); -const logger = require(path.resolve('./src/services/logger.js')); +const logger = require('../../services/logger'); module.exports = { name: 'error', diff --git a/src/events/player/playerSkip.js b/src/events/player/playerSkip.js index b593e8a..096057d 100644 --- a/src/events/player/playerSkip.js +++ b/src/events/player/playerSkip.js @@ -1,6 +1,4 @@ -const path = require('node:path'); -const logger = require(path.resolve('./src/services/logger.js')); -require('dotenv').config(); +const logger = require('../../services/logger'); module.exports = { name: 'playerSkip', diff --git a/src/events/player/playerStart.js b/src/events/player/playerStart.js index a49ffa9..11bec27 100644 --- a/src/events/player/playerStart.js +++ b/src/events/player/playerStart.js @@ -1,6 +1,4 @@ -const path = require('node:path'); -const logger = require(path.resolve('./src/services/logger.js')); -require('dotenv').config(); +const logger = require('../../services/logger'); module.exports = { name: 'playerStart', diff --git a/src/events/process/uncaughtException.js b/src/events/process/uncaughtException.js index aacf9a5..0612b84 100644 --- a/src/events/process/uncaughtException.js +++ b/src/events/process/uncaughtException.js @@ -1,6 +1,4 @@ -const path = require('node:path'); -const logger = require(path.resolve('./src/services/logger.js')); -require('dotenv').config(); +const logger = require('../../services/logger'); module.exports = { name: 'uncaughtException', diff --git a/src/events/process/unhandledRejection.js b/src/events/process/unhandledRejection.js index 69e30d7..b7a95fb 100644 --- a/src/events/process/unhandledRejection.js +++ b/src/events/process/unhandledRejection.js @@ -1,6 +1,4 @@ -const path = require('node:path'); -const logger = require(path.resolve('./src/services/logger.js')); -require('dotenv').config(); +const logger = require('../../services/logger'); module.exports = { name: 'unhandledRejection', diff --git a/src/index.js b/src/index.js index e7b02c1..f0051d8 100644 --- a/src/index.js +++ b/src/index.js @@ -1,11 +1,10 @@ +require('dotenv').config(); const fs = require('node:fs'); -const path = require('node:path'); const Discord = require('discord.js'); -const logger = require(path.resolve('./src/services/logger.js')); +const logger = require('./services/logger'); const { Player, onBeforeCreateStream } = require('discord-player'); const { stream } = require('yt-stream'); -const { registerEventListeners } = require(path.resolve('./src/utils/registerEventListeners.js')); -require('dotenv').config(); +const { registerEventListeners } = require('./utils/registerEventListeners.js'); const client = new Discord.Client({ intents: [Discord.GatewayIntentBits.Guilds, Discord.GatewayIntentBits.GuildVoiceStates], @@ -62,14 +61,12 @@ onBeforeCreateStream(async (track) => { }); client.commands = new Discord.Collection(); -const commandFolders = fs.readdirSync(path.resolve('./src/commands')); +const commandFolders = fs.readdirSync('./src/commands'); for (const folder of commandFolders) { - const commandFiles = fs - .readdirSync(path.resolve(`./src/commands/${folder}`)) - .filter((file) => file.endsWith('.js')); + const commandFiles = fs.readdirSync(`./src/commands/${folder}`).filter((file) => file.endsWith('.js')); for (const file of commandFiles) { - const command = require(path.resolve(`./src/commands/${folder}/${file}`)); + const command = require(`./commands/${folder}/${file}`); client.commands.set(command.data.name, command); } } diff --git a/src/services/logger.js b/src/services/logger.js index b79ae01..2d81ede 100644 --- a/src/services/logger.js +++ b/src/services/logger.js @@ -1,11 +1,11 @@ const pino = require('pino'); -require('dotenv').config(); +const { loggerOptions } = require('../config'); const transport = pino.transport({ targets: [ { target: 'pino/file', - level: process.env.MINIMUM_LOG_LEVEL, + level: loggerOptions.minimumLogLevel, options: { destination: './logs/app-all.log', mkdir: true, @@ -34,7 +34,7 @@ const transport = pino.transport({ }, { target: 'pino/file', - level: process.env.MINIMUM_LOG_LEVEL_CONSOLE, + level: loggerOptions.minimumLogLevelConsole, options: { colorize: true, sync: false @@ -45,7 +45,7 @@ const transport = pino.transport({ module.exports = pino( { - level: process.env.MINIMUM_LOG_LEVEL, + level: loggerOptions.minimumLogLevel, timestamp: () => `,"timestamp":"${new Date(Date.now()).toISOString()}"`, base: undefined }, diff --git a/src/utils/deploySlashCommands.js b/src/utils/deploySlashCommands.js index c5831c9..7b18160 100644 --- a/src/utils/deploySlashCommands.js +++ b/src/utils/deploySlashCommands.js @@ -1,20 +1,17 @@ -const path = require('node:path'); -const fs = require('node:fs'); -const logger = require(path.resolve('./src/services/logger.js')); -const { REST, Routes } = require('discord.js'); -const { systemServerGuildIds } = require(path.resolve('./config.json')); require('dotenv').config(); +const logger = require('../services/logger'); +const fs = require('node:fs'); +const { REST, Routes } = require('discord.js'); +const { systemOptions } = require('../config'); const slashCommands = []; const systemCommands = []; -const commandFolders = fs.readdirSync(path.resolve('./src/commands')); +const commandFolders = fs.readdirSync('./src/commands'); for (const folder of commandFolders) { - const commandFiles = fs - .readdirSync(path.resolve(`./src/commands/${folder}`)) - .filter((file) => file.endsWith('.js')); + const commandFiles = fs.readdirSync(`./src/commands/${folder}`).filter((file) => file.endsWith('.js')); for (const file of commandFiles) { - const command = require(path.resolve(`./src/commands/${folder}/${file}`)); + const command = require(`../commands/${folder}/${file}`); command.isSystemCommand ? systemCommands.push(command.data.toJSON()) : slashCommands.push(command.data.toJSON()); @@ -34,7 +31,7 @@ const rest = new REST({ version: '10' }).setToken(process.env.DISCORD_BOT_TOKEN) ); logger.info('Started refreshing application (/) bot commands.'); - await rest.put(Routes.applicationCommands(process.env.DISCORD_CLIENT_ID), { + await rest.put(Routes.applicationCommands(process.env.DISCORD_APPLICATION_ID), { body: slashCommands }); @@ -53,9 +50,9 @@ const rest = new REST({ version: '10' }).setToken(process.env.DISCORD_BOT_TOKEN) ); logger.info('Started refreshing application (/) system commands.'); - for (const systemServerGuildId of systemServerGuildIds) { - logger.info(`Refreshing system commands for guild id ${systemServerGuildId}.`); - await rest.put(Routes.applicationGuildCommands(process.env.DISCORD_CLIENT_ID, systemServerGuildId), { + for (const systemGuildId of systemOptions.systemGuildIds) { + logger.info(`Refreshing system commands for guild id ${systemGuildId}.`); + await rest.put(Routes.applicationGuildCommands(process.env.DISCORD_APPLICATION_ID, systemGuildId), { body: systemCommands }); } diff --git a/src/utils/postBotStats.js b/src/utils/postBotStats.js index 348bf95..7d40435 100644 --- a/src/utils/postBotStats.js +++ b/src/utils/postBotStats.js @@ -1,7 +1,5 @@ -const path = require('node:path'); -const logger = require(path.resolve('./src/services/logger.js')); +const logger = require('../services/logger'); const https = require('node:https'); -require('dotenv').config(); exports.postBotStats = (client) => { try { @@ -11,42 +9,42 @@ exports.postBotStats = (client) => { const sites = [ { hostname: 'top.gg', - path: `/api/bots/${process.env.DISCORD_CLIENT_ID}/stats`, + path: `/api/bots/${process.env.DISCORD_APPLICATION_ID}/stats`, method: 'POST', body: { server_count: guildCount }, token: process.env.BOTLIST_TOP_GG_API_TOKEN }, { hostname: 'discordbotlist.com', - path: `/api/v1/bots/${process.env.DISCORD_CLIENT_ID}/stats`, + path: `/api/v1/bots/${process.env.DISCORD_APPLICATION_ID}/stats`, method: 'POST', body: { guilds: guildCount }, token: process.env.BOTLIST_DISCORD_BOT_LIST_COM_API_TOKEN }, { hostname: 'discords.com', - path: `/bots/api/bot/${process.env.DISCORD_CLIENT_ID}`, + path: `/bots/api/bot/${process.env.DISCORD_APPLICATION_ID}`, method: 'POST', body: { server_count: guildCount }, token: process.env.BOTLIST_DISCORDS_COM_API_TOKEN }, { hostname: 'discord.bots.gg', - path: `/api/v1/bots/${process.env.DISCORD_CLIENT_ID}/stats`, + path: `/api/v1/bots/${process.env.DISCORD_APPLICATION_ID}/stats`, method: 'POST', body: { guildCount: guildCount }, token: process.env.BOTLIST_DISCORD_BOTS_GG_API_TOKEN }, { hostname: 'api.botlist.me', - path: `/api/v1/bots/${process.env.DISCORD_CLIENT_ID}/stats`, + path: `/api/v1/bots/${process.env.DISCORD_APPLICATION_ID}/stats`, method: 'POST', body: { server_count: guildCount }, token: process.env.BOTLIST_BOTLIST_ME_API_TOKEN }, { hostname: 'api.discordlist.gg', - path: `/v0/bots/${process.env.DISCORD_CLIENT_ID}/guilds?count=${guildCount}`, + path: `/v0/bots/${process.env.DISCORD_APPLICATION_ID}/guilds?count=${guildCount}`, method: 'PUT', body: {}, token: `Bearer ${process.env.BOTLIST_DISCORDLIST_GG_API_TOKEN}` diff --git a/src/utils/registerEventListeners.js b/src/utils/registerEventListeners.js index 72f8770..3fa6346 100644 --- a/src/utils/registerEventListeners.js +++ b/src/utils/registerEventListeners.js @@ -1,17 +1,13 @@ +const logger = require('../services/logger'); const fs = require('node:fs'); -const path = require('node:path'); -const logger = require(path.resolve('./src/services/logger.js')); -require('dotenv').config(); exports.registerEventListeners = (client, player) => { - const eventFolders = fs.readdirSync(path.resolve('./src/events')); + const eventFolders = fs.readdirSync('./src/events'); for (const folder of eventFolders) { - const eventFiles = fs - .readdirSync(path.resolve(`./src/events/${folder}`)) - .filter((file) => file.endsWith('.js')); + const eventFiles = fs.readdirSync(`./src/events/${folder}`).filter((file) => file.endsWith('.js')); for (const file of eventFiles) { - const event = require(path.resolve(`./src/events/${folder}/${file}`)); + const event = require(`../events/${folder}/${file}`); switch (folder) { case 'client': if (event.once) {