Merge pull request #32 from mariusbegby/improvements-environment-variables-logging-linting

Improvements environment variables logging linting
This commit is contained in:
Marius Begby authored and GitHub committed 2023-07-13 11:50:41 +02:00
commit 0160174e6c
26 files changed
+1704 -87

No files matched your search

+8
View File
@@ -0,0 +1,8 @@
# top-most EditorConfig file
root = true
[*]
end_of_line = crlf
insert_final_newline = true
indent_style = space
indent_size = 4
+5
View File
@@ -0,0 +1,5 @@
NODE_ENV=development
MINIMUM_LOG_LEVEL=debug
MINIMUM_LOG_LEVEL_CONSOLE=info
DISCORD_BOT_TOKEN=YOUR_DISCORD_BOT_TOKEN
DISCORD_CLIENT_ID=YOUR_DISCOR_BOT_CLIENT_ID
+40
View File
@@ -0,0 +1,40 @@
{
"env": {
"node": true,
"es2021": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": "latest"
},
"rules": {
"indent": ["error", 4],
"linebreak-style": ["error", "windows"],
"quotes": ["error", "single"],
"semi": ["error", "always"],
"camelcase": [
"error",
{
"properties": "always"
}
],
"array-bracket-spacing": ["error", "never"],
"object-curly-spacing": ["error", "always"],
"jsx-quotes": ["error", "prefer-single"],
"key-spacing": [
"error",
{
"afterColon": true,
"mode": "minimum"
}
],
"no-trailing-spaces": [
"error",
{
"skipBlankLines": true,
"ignoreComments": true
}
],
"curly": ["error", "all"]
}
}
+1
View File
@@ -0,0 +1 @@
* text=auto eol=crlf
+1
View File
@@ -27,3 +27,4 @@ jobs:
cache: 'npm'
- run: npm install -g npm@latest
- run: npm ci
- run: npm run eslint
+1
View File
@@ -1,3 +1,4 @@
/node_modules
/config.json
/.env
/app-*.log
+11
View File
@@ -0,0 +1,11 @@
{
"singleQuote": true,
"semi": true,
"useTabs": false,
"bracketSpacing": true,
"bracketSameLine": true,
"trailingComma": "none",
"arrowParens": "always",
"endOfLine": "auto",
"tabWidth": 4
}
+5 -5
View File
@@ -1,5 +1,5 @@
const { SlashCommandBuilder } = require('@discordjs/builders');
const { useMainPlayer, useQueue } = require('discord-player');
const { useQueue } = require('discord-player');
const {
EmbedBuilder,
StringSelectMenuBuilder,
@@ -23,7 +23,7 @@ module.exports = {
embeds: [
new EmbedBuilder()
.setDescription(
`**Failed**\nYou need to be in a voice channel to use this command.`
'**Failed**\nYou need to be in a voice channel to use this command.'
)
.setColor(embedColors.colorWarning)
]
@@ -37,7 +37,7 @@ module.exports = {
embeds: [
new EmbedBuilder()
.setDescription(
`**Failed**\nThere are no tracks in the queue. Add tracks with \`/play\`!`
'**Failed**\nThere are no tracks in the queue. Add tracks with `/play`!'
)
.setColor(embedColors.colorWarning)
]
@@ -85,7 +85,7 @@ module.exports = {
embeds: [
new EmbedBuilder()
.setDescription(
`**Toggle filters** (beta)\nToggle or disable audio filters for playback.`
'**Toggle filters** (beta)\nToggle or disable audio filters for playback.'
)
.setColor(embedColors.colorInfo)
],
@@ -130,7 +130,7 @@ module.exports = {
iconURL: interaction.user.avatarURL()
})
.setDescription(
`**Disabled filters**\nDisabled all audio filters.`
'**Disabled filters**\nDisabled all audio filters.'
)
.setColor(embedColors.colorSuccess)
],
+11 -12
View File
@@ -1,5 +1,4 @@
const { SlashCommandBuilder } = require('@discordjs/builders');
const { useMainPlayer, useQueue } = require('discord-player');
const { EmbedBuilder } = require('discord.js');
const { embedColors } = require('../config.json');
@@ -12,17 +11,17 @@ module.exports = {
embeds: [
new EmbedBuilder()
.setDescription(
`**List of commands**\n` +
`\`/help\` - Show this menu.\n` +
`\`/play\` \`query\` - Add a track or playlist to the queue by searching or url.\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` +
`\`/filters\` - Toggle various audio filters during playback.\n` +
`\`/volume\` \`[percentage]\` - Show or set the playback volume for tracks.\n` +
`\`/skip\` \`[trackNumber]\` - Skip the current track.\n` +
`\`/remove\` \`trackNumber\` - Remove a specific track from the queue.\n` +
`\`/leave\` - Remove bot from voice channel and clear the queue.\n`
'**List of commands**\n' +
'`/help` - Show this menu.\n' +
'`/play` `query` - Add a track or playlist to the queue by searching or url.\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' +
'`/filters` - Toggle various audio filters during playback.\n' +
'`/volume` `[percentage]` - Show or set the playback volume for tracks.\n' +
'`/skip` `[trackNumber]` - Skip the current track.\n' +
'`/remove` `trackNumber` - Remove a specific track from the queue.\n' +
'`/leave` - Remove bot from voice channel and clear the queue.\n'
)
.setColor(embedColors.colorInfo)
]
+4 -4
View File
@@ -1,5 +1,5 @@
const { SlashCommandBuilder } = require('@discordjs/builders');
const { useMainPlayer, useQueue } = require('discord-player');
const { useQueue } = require('discord-player');
const { EmbedBuilder } = require('discord.js');
const { embedColors } = require('../config.json');
@@ -17,7 +17,7 @@ module.exports = {
embeds: [
new EmbedBuilder()
.setDescription(
`**Failed**\nYou need to be in a voice channel to use this command.`
'**Failed**\nYou need to be in a voice channel to use this command.'
)
.setColor(embedColors.colorWarning)
]
@@ -31,7 +31,7 @@ module.exports = {
embeds: [
new EmbedBuilder()
.setDescription(
`**Failed**\nNo tracks are currently playing, and the queue is empty. Use the \`/play\` command to play some music!`
'**Failed**\nNo tracks are currently playing, and the queue is empty. Use the `/play` command to play some music!'
)
.setColor(embedColors.colorWarning)
]
@@ -45,7 +45,7 @@ module.exports = {
embeds: [
new EmbedBuilder()
.setDescription(
`**Leaving**\nCleared the track queue and left voice channel. To play more music, use the \`/play\` command!`
'**Leaving**\nCleared the track queue and left voice channel. To play more music, use the `/play` command!'
)
.setColor(embedColors.colorSuccess)
]
+16 -16
View File
@@ -13,7 +13,7 @@ module.exports = {
embeds: [
new EmbedBuilder()
.setDescription(
`**Failed**\nYou need to be in a voice channel to use this command.`
'**Failed**\nYou need to be in a voice channel to use this command.'
)
.setColor(embedColors.colorWarning)
]
@@ -27,7 +27,7 @@ module.exports = {
embeds: [
new EmbedBuilder()
.setDescription(
`**Failed**\nThere are no tracks in the queue. Add tracks with \`/play\`!`
'**Failed**\nThere are no tracks in the queue. Add tracks with `/play`!'
)
.setColor(embedColors.colorWarning)
]
@@ -39,29 +39,29 @@ module.exports = {
embeds: [
new EmbedBuilder()
.setDescription(
`**Failed**\nThere are no tracks in the queue or currently playing.`
'**Failed**\nThere are no tracks in the queue or currently playing.'
)
.setColor(embedColors.colorWarning)
]
});
}
const sourceStringsFormatted = {
youtube: 'YouTube',
soundcloud: 'SoundCloud',
spotify: 'Spotify',
apple_music: 'Apple Music',
arbitrary: 'Direct source'
};
const sourceStringsFormatted = new Map([
['youtube', 'YouTube'],
['soundcloud', 'SoundCloud'],
['spotify', 'Spotify'],
['apple_music', 'Apple Music'],
['arbitrary', 'Direct source']
]);
const currentTrack = queue.currentTrack;
const author = currentTrack.author ? currentTrack.author : 'Unknown';
let author = currentTrack.author ? currentTrack.author : 'Unknown';
if (author === 'cdn.discordapp.com') {
author = 'Unknown';
}
const plays = currentTrack.views !== 0 ? currentTrack.views : 'Unknown';
const source =
sourceStringsFormatted[currentTrack.raw.source] ?? 'Unknown';
sourceStringsFormatted.get(currentTrack.raw.source) ?? 'Unknown';
const queueLength = queue.tracks.data.length;
const timestamp = queue.node.getTimestamp();
let bar = `\`${
@@ -98,8 +98,8 @@ module.exports = {
})
.setDescription(
(queue.node.isPaused()
? `**Currently Paused**\n`
: `**Now Playing**\n`) +
? '**Currently Paused**\n'
: '**Now Playing**\n') +
(currentTrack
? `**[${currentTrack.title}](${currentTrack.url})**`
: 'None') +
@@ -152,7 +152,7 @@ module.exports = {
embeds: [
new EmbedBuilder()
.setDescription(
`**Failed**\nThere are no tracks in the queue and nothing currently playing.`
'**Failed**\nThere are no tracks in the queue and nothing currently playing.'
)
.setColor(embedColors.colorWarning)
],
@@ -165,7 +165,7 @@ module.exports = {
embeds: [
new EmbedBuilder()
.setDescription(
`**Failed to skip**\nThis track has already been skipped, or is no longer playing.`
'**Failed to skip**\nThis track has already been skipped, or is no longer playing.'
)
.setColor(embedColors.colorWarning)
],
+4 -4
View File
@@ -1,5 +1,5 @@
const { SlashCommandBuilder } = require('@discordjs/builders');
const { useMainPlayer, useQueue } = require('discord-player');
const { useQueue } = require('discord-player');
const { EmbedBuilder } = require('discord.js');
const { embedColors } = require('../config.json');
@@ -13,7 +13,7 @@ module.exports = {
embeds: [
new EmbedBuilder()
.setDescription(
`**Failed**\nYou need to be in a voice channel to use this command.`
'**Failed**\nYou need to be in a voice channel to use this command.'
)
.setColor(embedColors.colorWarning)
]
@@ -27,7 +27,7 @@ module.exports = {
embeds: [
new EmbedBuilder()
.setDescription(
`**Failed**\nThere are no tracks in the queue. Add tracks with \`/play\`!`
'**Failed**\nThere are no tracks in the queue. Add tracks with `/play`!'
)
.setColor(embedColors.colorWarning)
]
@@ -39,7 +39,7 @@ module.exports = {
embeds: [
new EmbedBuilder()
.setDescription(
`**Failed**\nThere are no tracks in the queue or currently playing.`
'**Failed**\nThere are no tracks in the queue or currently playing.'
)
.setColor(embedColors.colorWarning)
]
+6 -4
View File
@@ -6,7 +6,9 @@ const { embedColors, playerOptions } = require('../config.json');
module.exports = {
data: new SlashCommandBuilder()
.setName('play')
.setDescription('Add a track or playlist to the queue by searching or url.')
.setDescription(
'Add a track or playlist to the queue by searching or url.'
)
.addStringOption((option) =>
option
.setName('query')
@@ -19,7 +21,7 @@ module.exports = {
embeds: [
new EmbedBuilder()
.setDescription(
`**Failed**\nYou need to be in a voice channel to use this command.`
'**Failed**\nYou need to be in a voice channel to use this command.'
)
.setColor(embedColors.colorWarning)
]
@@ -54,7 +56,7 @@ module.exports = {
embeds: [
new EmbedBuilder()
.setDescription(
`**Unsupported Source**\nThis audio source is a YouTube live stream, which is currently not a supported format.\n\n_If you think that this is incorrect, please submit a bug report in the bot [support server](https://discord.gg/t6Bm8wPpXB)._`
'**Unsupported Source**\nThis audio source is a YouTube live stream, which is currently not a supported format.\n\n_If you think that this is incorrect, please submit a bug report in the bot [support server](https://discord.gg/t6Bm8wPpXB)._'
)
.setColor(embedColors.colorWarning)
]
@@ -90,7 +92,7 @@ module.exports = {
embeds: [
new EmbedBuilder()
.setDescription(
`**Failed**\nFailed to add track to queue. Please try again.`
'**Failed**\nFailed to add track to queue. Please try again.'
)
.setColor(embedColors.colorError)
]
+5 -4
View File
@@ -19,7 +19,7 @@ module.exports = {
embeds: [
new EmbedBuilder()
.setDescription(
`**Failed**\nYou need to be in a voice channel to use this command.`
'**Failed**\nYou need to be in a voice channel to use this command.'
)
.setColor(embedColors.colorWarning)
]
@@ -30,7 +30,8 @@ module.exports = {
let queueString = '';
if (!queue) {
queueString = `There are no tracks in the queue. Add tracks with \`/play\`!`;
queueString =
'There are no tracks in the queue. Add tracks with `/play`!';
return await interaction.editReply({
embeds: [
new EmbedBuilder()
@@ -41,7 +42,7 @@ module.exports = {
.setDescription(`**Queue**\n${queueString}`)
.setColor(embedColors.colorInfo)
.setFooter({
text: `Page 1 of 1`
text: 'Page 1 of 1'
})
]
});
@@ -125,7 +126,7 @@ module.exports = {
iconURL: interaction.guild.iconURL()
})
.setDescription(
`**Currently playing**\n` +
'**Currently playing**\n' +
(currentTrack
? `**[${currentTrack.title}](${currentTrack.url})**`
: 'None') +
+3 -3
View File
@@ -1,5 +1,5 @@
const { SlashCommandBuilder } = require('@discordjs/builders');
const { useMainPlayer, useQueue } = require('discord-player');
const { useQueue } = require('discord-player');
const { EmbedBuilder } = require('discord.js');
const { embedColors } = require('../config.json');
@@ -20,7 +20,7 @@ module.exports = {
embeds: [
new EmbedBuilder()
.setDescription(
`**Failed**\nYou need to be in a voice channel to use this command.`
'**Failed**\nYou need to be in a voice channel to use this command.'
)
.setColor(embedColors.colorWarning)
]
@@ -34,7 +34,7 @@ module.exports = {
embeds: [
new EmbedBuilder()
.setDescription(
`**Failed**\nThere are no tracks in the queue. Add tracks with \`/play\`!`
'**Failed**\nThere are no tracks in the queue. Add tracks with `/play`!'
)
.setColor(embedColors.colorWarning)
]
+3 -3
View File
@@ -19,7 +19,7 @@ module.exports = {
embeds: [
new EmbedBuilder()
.setDescription(
`**Failed**\nYou need to be in a voice channel to use this command.`
'**Failed**\nYou need to be in a voice channel to use this command.'
)
.setColor(embedColors.colorWarning)
]
@@ -33,7 +33,7 @@ module.exports = {
embeds: [
new EmbedBuilder()
.setDescription(
`**Failed**\nThere are no tracks in the queue. Add tracks with \`/play\`!`
'**Failed**\nThere are no tracks in the queue. Add tracks with `/play`!'
)
.setColor(embedColors.colorWarning)
]
@@ -83,7 +83,7 @@ module.exports = {
embeds: [
new EmbedBuilder()
.setDescription(
`**Failed**\nThere are no tracks in the queue and nothing currently playing.`
'**Failed**\nThere are no tracks in the queue and nothing currently playing.'
)
.setColor(embedColors.colorWarning)
]
+4 -4
View File
@@ -1,5 +1,5 @@
const { SlashCommandBuilder } = require('@discordjs/builders');
const { useMainPlayer, useQueue } = require('discord-player');
const { useQueue } = require('discord-player');
const { EmbedBuilder } = require('discord.js');
const { embedColors } = require('../config.json');
@@ -20,7 +20,7 @@ module.exports = {
embeds: [
new EmbedBuilder()
.setDescription(
`**Failed**\nYou need to be in a voice channel to use this command.`
'**Failed**\nYou need to be in a voice channel to use this command.'
)
.setColor(embedColors.colorWarning)
]
@@ -34,7 +34,7 @@ module.exports = {
embeds: [
new EmbedBuilder()
.setDescription(
`**Failed**\nThere are no tracks playing or in the queue. Add tracks with \`/play\`!`
'**Failed**\nThere are no tracks playing or in the queue. Add tracks with `/play`!'
)
.setColor(embedColors.colorWarning)
]
@@ -58,7 +58,7 @@ module.exports = {
embeds: [
new EmbedBuilder()
.setDescription(
`**Error**\nYou need to pick a number between \`1\` and \`100\`.`
'**Error**\nYou need to pick a number between `1` and `100`.'
)
.setColor(embedColors.colorError)
]
+5 -6
View File
@@ -1,7 +1,8 @@
{
"clientId": "Your bot Application ID here.",
"token": "Your bot auth token here.",
"systemServerGuildIds": ["Server id where system commands can be used", "Another server id where system commands can be used"],
"systemServerGuildIds": [
"Server id where system commands can be used",
"Another server id where system commands can be used"
],
"embedColors": {
"colorSuccess": "#23A55A",
"colorWarning": "#F0B232",
@@ -28,9 +29,7 @@
"leftChar": "▬",
"rightChar": "▬"
},
"minimumLogLevel": "debug",
"minimumLogLevelConsole": "info",
"filterThreadAmount": "4",
"filterThreadAmount": "2",
"filterList": [
{
"label": "Bass boost",
+10 -5
View File
@@ -1,7 +1,7 @@
const fs = require('node:fs');
const logger = require('./services/logger.js');
const { REST, Routes } = require('discord.js');
const { token, clientId } = require('./config.json');
require('dotenv').config();
const commands = [];
const commandFiles = fs
@@ -13,7 +13,9 @@ for (const file of commandFiles) {
commands.push(command.data.toJSON());
}
const rest = new REST({ version: '10' }).setToken(token);
const rest = new REST({ version: '10' }).setToken(
process.env.DISCORD_BOT_TOKEN
);
(async () => {
try {
@@ -27,9 +29,12 @@ const rest = new REST({ version: '10' }).setToken(token);
logger.info('Started refreshing application (/) bot commands.');
await rest.put(Routes.applicationCommands(clientId), {
body: commands
});
await rest.put(
Routes.applicationCommands(process.env.DISCORD_CLIENT_ID),
{
body: commands
}
);
logger.info('Successfully refreshed application (/) bot commands.');
} catch (error) {
+9 -3
View File
@@ -1,7 +1,8 @@
const fs = require('node:fs');
const logger = require('./services/logger.js');
const { REST, Routes } = require('discord.js');
const { token, clientId, systemServerGuildIds } = require('./config.json');
const { systemServerGuildIds } = require('./config.json');
require('dotenv').config();
const systemCommands = [];
const systemCommandFiles = fs
@@ -13,7 +14,9 @@ for (const file of systemCommandFiles) {
systemCommands.push(systemCommand.data.toJSON());
}
const rest = new REST({ version: '10' }).setToken(token);
const rest = new REST({ version: '10' }).setToken(
process.env.DISCORD_BOT_TOKEN
);
(async () => {
try {
@@ -29,7 +32,10 @@ const rest = new REST({ version: '10' }).setToken(token);
for (const systemServerGuildId of systemServerGuildIds) {
await rest.put(
Routes.applicationGuildCommands(clientId, systemServerGuildId),
Routes.applicationGuildCommands(
process.env.DISCORD_CLIENT_ID,
systemServerGuildId
),
{
body: systemCommands
}
+17 -4
View File
@@ -4,7 +4,8 @@ const logger = require('./services/logger.js');
const { EmbedBuilder } = require('discord.js');
const { Player, onBeforeCreateStream } = require('discord-player');
const { stream } = require('yt-stream');
const { token, embedColors } = require('./config.json');
const { embedColors } = require('./config.json');
require('dotenv').config();
// Setup required permissions for the bot to work
const client = new Discord.Client({
@@ -51,6 +52,16 @@ onBeforeCreateStream(async (track) => {
return null;
});
if (process.env.NODE_ENV === 'development') {
player.on('debug', (message) => {
logger.debug(message);
});
player.events.on('debug', (message) => {
logger.trace(message);
});
}
player.events.on('error', (queue, error) => {
// Emitted when the player queue encounters error
logger.error(error, 'Player queue error event');
@@ -114,7 +125,9 @@ client.on('interactionCreate', async (interaction) => {
}
const command = client.commands.get(interaction.commandName);
if (!command) return;
if (!command) {
return;
}
try {
const inputTime = new Date();
@@ -172,7 +185,7 @@ client.on('interactionCreate', async (interaction) => {
embeds: [
new EmbedBuilder()
.setDescription(
`**Unexpected Error**\nThere was an error while executing this command! Please try again.\n\n_If this issue persists, please submit a bug report in the bot [support server](https://discord.gg/t6Bm8wPpXB)._`
'**Unexpected Error**\nThere was an error while executing this command! Please try again.\n\n_If this issue persists, please submit a bug report in the bot [support server](https://discord.gg/t6Bm8wPpXB)._'
)
.setColor(embedColors.colorError)
]
@@ -180,4 +193,4 @@ client.on('interactionCreate', async (interaction) => {
}
});
client.login(token);
client.login(process.env.DISCORD_BOT_TOKEN);
+1514
View File
File diff suppressed because it is too large. Load diff
+7 -1
View File
@@ -20,7 +20,8 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node ./index.js",
"deploy": "node ./deploy-commands.js && node ./deploy-system-commands.js"
"deploy": "node ./deploy-commands.js && node ./deploy-system-commands.js",
"eslint": "eslint ./"
},
"dependencies": {
"@discord-player/extractor": "^4.4.0",
@@ -29,8 +30,13 @@
"@discordjs/voice": "^0.16.0",
"discord-player": "^6.6.1",
"discord.js": "^14.11.0",
"dotenv": "^16.3.1",
"pino": "^8.14.1",
"pino-pretty": "^10.0.1",
"yt-stream": "^1.4.8"
},
"devDependencies": {
"eslint": "^8.44.0",
"prettier-eslint": "^15.0.1"
}
}
+11 -6
View File
@@ -1,25 +1,30 @@
const pino = require('pino');
const { minimumLogLevel, minimumLogLevelConsole } = require('../config.json');
require('dotenv').config();
const transport = pino.transport({
targets: [
{
target: 'pino/file',
level: process.env.MINIMUM_LOG_LEVEL,
options: { destination: './app-all.log' }
},
{
target: 'pino/file',
level: 'debug',
options: { destination: `./app-debug.log` }
options: { destination: './app-debug.log' }
},
{
target: 'pino/file',
level: 'info',
options: { destination: `./app-info.log` }
options: { destination: './app-info.log' }
},
{
target: 'pino/file',
level: 'error',
options: { destination: `./app-error.log` }
options: { destination: './app-error.log' }
},
{
level: minimumLogLevelConsole,
level: process.env.MINIMUM_LOG_LEVEL_CONSOLE,
target: 'pino-pretty'
}
]
@@ -27,7 +32,7 @@ const transport = pino.transport({
module.exports = pino(
{
level: minimumLogLevel,
level: process.env.MINIMUM_LOG_LEVEL,
timestamp: () => `,"timestamp":"${new Date(Date.now()).toISOString()}"`,
base: undefined
},
+1 -1
View File
@@ -12,7 +12,7 @@ module.exports = {
embeds: [
new EmbedBuilder()
.setDescription(
`**No permission**\nYou do not have permission to use this command.`
'**No permission**\nYou do not have permission to use this command.'
)
.setColor(embedColors.colorError)
]
+2 -2
View File
@@ -13,7 +13,7 @@ module.exports = {
embeds: [
new EmbedBuilder()
.setDescription(
`**No permission**\nYou do not have permission to use this command.`
'**No permission**\nYou do not have permission to use this command.'
)
.setColor(embedColors.colorError)
]
@@ -39,7 +39,7 @@ module.exports = {
embeds: [
new EmbedBuilder()
.setDescription(
`**Bot Status**\n` +
'**Bot Status**\n' +
`Uptime: \`${uptimeString}\`\n` +
`Memory Usage: \`${(
process.memoryUsage().heapUsed /