Useful packages

Installed the dotenv, chalk, and nodemon packages to the bot for a better development process.

Console messages now have colors, prefixes, and text formatting, to able them requires the console.js file, it has all the messages formatted with the chalk package.

Also moved the README.md and LICENSE to the .github folder.
This commit is contained in:
Guz
2021-08-27 13:28:12 -03:00
parent f6d253ec6d
commit 1ac159ebd7
12 changed files with 2043 additions and 54 deletions

View File

View File

2
.gitignore vendored
View File

@@ -1,3 +1,3 @@
node_modules
config.json
*.env
.vscode

View File

@@ -3,7 +3,7 @@ const { Routes } = require('discord-api-types/v9');
const fs = require('fs');
const config = require('../../config');
const console = require('../../functions/meta/console');
module.exports = {
data: new SlashCommandBuilder()
@@ -15,7 +15,7 @@ module.exports = {
.setRequired(true)),
permissions: [
{
id: config.ownerId,
id: process.env.OWNER,
type: 'USER',
permission: true,
},
@@ -41,7 +41,7 @@ module.exports = {
const oldCommand = commands[cmdIdx];
const oldCommandData = commandsData[cmdIdx];
const clientCommand = (await client.guilds.cache.get(config.devGuildId)?.commands.fetch()).find(c => c.name === cmdName);
const clientCommand = (await client.guilds.cache.get(process.env.DEV_GUILD)?.commands.fetch()).find(c => c.name === cmdName);
const commandFolder = fs.readdirSync('./commands').find(folder => fs.readdirSync(`./commands/${folder}`).includes(`${cmdName}.js`));
@@ -62,7 +62,7 @@ module.exports = {
commandsData[cmdIdx] = newCommand.data.toJSON();
await rest.put(
Routes.applicationGuildCommands(config.clientId, config.devGuildId), {
Routes.applicationGuildCommands(process.env.CLIENT, process.env.DEV_GUILD), {
body: commandsData,
},
);
@@ -87,7 +87,7 @@ module.exports = {
catch (error) {
console.error(error);
await interaction.reply({
content: `A error occur while trying to reload the \`${cmdName}\` command.\n\`\`\`${error}\`\`\``,
content: `A error occur while trying to reload the \`${cmdName}\` command.\n\`\`\`diff\n- ${error}\`\`\``,
ephemeral: true,
});
}

View File

@@ -13,7 +13,7 @@ module.exports = {
],
async execute(interaction) {
console.log('ping hello!');
console.log('ping');
interaction.reply({ content: 'Ping!', ephemeral: true });
// console.log(`Ping! ${interaction.options.get('input').value}`);
},

View File

@@ -1,5 +1,5 @@
const config = require('../../config.json');
const { commands } = require('../../index');
const console = require('../../functions/meta/console');
module.exports = {
name: 'ready',
@@ -9,7 +9,7 @@ module.exports = {
for (const command of commands) {
const clientCommand = (await client.guilds.cache.get(config.devGuildId)?.commands.fetch()).find(c => c.name === command.data.name);
const clientCommand = (await client.guilds.cache.get(process.env.DEV_GUILD)?.commands.fetch()).find(c => c.name === command.data.name);
await clientCommand.permissions.set({ id: clientCommand.id, permissions: command.permissions });
@@ -17,18 +17,16 @@ module.exports = {
command.name = clientCommand.name;
}
console.log('Guild commands totally registered');
console.log('\nGuild Commands:');
console.info('Guild Commands:');
console.table(commands);
console.log('\nBot configurations');
console.info('Bot configurations:');
console.table({
'Owner Id': config.ownerId,
'Development Guild Id': config.devGuildId,
'Client Id': config.clientId,
'Owner Id': process.env.OWNER,
'Development Guild Id': process.env.DEV_GUILD,
'Client Id': process.env.CLIENT,
});
console.log('\n\n-- BOT READY --\n\n');
console.info('BOT READY');
},
};

View File

@@ -1,21 +1,22 @@
const { commands } = require('../../index');
const console = require('../../functions/meta/console');
module.exports = {
name: 'interactionCreate',
async execute(interaction, client) {
console.log('NEW INTERACTION ################################');
console.time('Interaction time');
console.system('NEW INTERACTION ################################');
console.time('Interaction');
if(interaction.isCommand()) {
console.log(`\nCommand ${interaction.commandName} executing ----------------\n`);
console.system(`Command ${interaction.commandName} executing ----------------\n`);
const command = commands.find(c => c.data.name === interaction.commandName);
console.log('\nCommand data:\n');
console.debug('Command data:');
console.log(command);
console.log('\nCommand console:\n');
console.debug('Command console:');
if(!command) return;
@@ -25,17 +26,17 @@ module.exports = {
catch (error) {
console.error(error);
await interaction.reply({
content: `A error occur while trying to execute the command.\n\`\`\`${error}\`\`\``,
content: `A error occur while trying to execute the command.\n\`\`\`diff\n- ${error}\`\`\``,
ephemeral: true,
});
}
console.log(`\nCommand ${interaction.commandName} executed ----------------\n`);
console.system(`Command ${interaction.commandName} executed ----------------`);
}
console.timeEnd('Interaction time');
console.log('################################################\n');
console.timeEnd('Interaction');
console.system('################################################');
},
};

51
functions/meta/console.js Normal file
View File

@@ -0,0 +1,51 @@
const chalk = require('chalk');
module.exports = {
CONSOLE: require('console'),
log: (msg) => console.log(msg),
time: (label) => console.time(chalk.hex('#DF82FF').bold(`\n[ TIME LOG ] ${label}`)),
timeEnd: (label) => console.timeEnd(chalk.hex('#DF82FF').bold(`\n[ TIME LOG ] ${label}`)),
timeLog: (label) => console.timeLog(chalk.hex('#DF82FF').bold(`\n[ TIME LOG ] ${label}`)),
assert: (args) => console.assert(args),
table: (obj) => console.table(obj),
count: (n) => console.count(n),
clear: () => console.clear(),
error: (errorMsg) => {
console.log(
// chalk.bgHex('#D02525').hex('#ffffff').bold('\n ERROR ') +
chalk.hex('#D02525').bold(`\n[ ERROR ] ${errorMsg}`));
console.error(errorMsg);
},
warn: (warnMsg) => {
console.log(
// chalk.bgHex('#E5C10E').hex('#ffffff').bold('\n WARNING ') +
chalk.hex('#E5C10E').bold(`\n[ WARNING ] ${warnMsg}`));
},
system: (systemMsg) => {
console.log(
// chalk.bgHex('#0EB4E5').hex('#ffffff').bold('\n SYSTEM ') +
chalk.hex('#0EB4E5').bold(`\n[ SYSTEM ] ${systemMsg}`));
},
info: (infoMsg) => {
console.log(
// chalk.bgHex('#52C74F').hex('#ffffff').bold('\n INFO ') +
chalk.hex('#52C74F').bold(`\n[ INFO ] ${infoMsg}`));
},
debug: (debugMsg) => {
console.log(
chalk.bgHex('#252525').hex('#ffffff').bold('\n [ DEBUG ] ') + chalk.reset(` ${debugMsg}`));
},
};

View File

@@ -4,7 +4,7 @@ const { Routes } = require('discord-api-types/v9');
const fs = require('fs');
const { token, devGuildId, clientId } = require('./config.json');
const console = require('./functions/meta/console');
const client = new Client({
intents: [Intents.FLAGS.GUILDS],
@@ -35,7 +35,7 @@ for (const folder of commandFolders) {
const rest = new REST({
version: '9',
}).setToken(token);
}).setToken(process.env.TOKEN);
module.exports = { commands, commandsData, rest };
@@ -44,7 +44,7 @@ module.exports = { commands, commandsData, rest };
try {
await rest.put(
Routes.applicationGuildCommands(clientId, devGuildId), {
Routes.applicationGuildCommands(process.env.CLIENT, process.env.DEV_GUILD), {
body: commandsData,
},
);
@@ -77,4 +77,4 @@ for (const folder of eventFolders) {
}
client.login(token);
client.login(process.env.TOKEN);

13
nodemon.json Normal file
View File

@@ -0,0 +1,13 @@
{
"delay": 3500,
"ignore": [
".git", ".gitignore", ".gitattributes",
"node_modules/**/node_modules"
],
"watch": [
"commands/dev/*"
],
"env": {
"NODE_ENV": "development"
}
}

1964
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -4,7 +4,8 @@
"description": "",
"main": "index.js",
"scripts": {
"start": "node .",
"start": "node -r dotenv/config .",
"start-dev": "nodemon -r dotenv/config .",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
@@ -13,10 +14,13 @@
"dependencies": {
"@discordjs/builders": "^0.5.0",
"@discordjs/rest": "^0.1.0-canary.0",
"chalk": "^4.1.2",
"discord-api-types": "^0.22.0",
"discord.js": "^13.1.0"
"discord.js": "^13.1.0",
"dotenv": "^10.0.0"
},
"devDependencies": {
"eslint": "^7.31.0"
"eslint": "^7.31.0",
"nodemon": "^2.0.12"
}
}