From cb1eb0a5bdf15db36d6e672338a9eab67abf8a13 Mon Sep 17 00:00:00 2001 From: IDeletedSystem64 Date: Tue, 2 Aug 2022 23:53:10 -0500 Subject: [PATCH] Migrate bot-token and ownerid to dotenv --- .env.example | 3 +++ commands/eval.js | 2 +- commands/info.js | 2 +- commands/reload.js | 4 ++-- commands/restart.js | 6 +++--- commands/stop.js | 2 +- config-example.json | 2 -- start.js | 7 +++++-- 8 files changed, 16 insertions(+), 12 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..54a5a11 --- /dev/null +++ b/.env.example @@ -0,0 +1,3 @@ +TOKEN="EVERYTHINGS SO FCKED AND IM TIRED OF BEING SCARED" +OWNERID="SO LETS GET OUT AND FCK UP EQUESTRIA" +# Do !!NOT!! share this file once filled out with anybody, Doing so can leak your Bot Token which will give anyone access to your bot! diff --git a/commands/eval.js b/commands/eval.js index c7a88bc..20b82d5 100644 --- a/commands/eval.js +++ b/commands/eval.js @@ -21,7 +21,7 @@ module.exports = { }, handle (client, config, user, code) { - if (user.id === config.ownerID) { + if (user.id === process.env.OWNERID) { try { const evaled = inspect(eval(code)); // await message.channel.send(evaled, { code: 'xl' }); diff --git a/commands/info.js b/commands/info.js index 6906ecb..c87efd7 100644 --- a/commands/info.js +++ b/commands/info.js @@ -32,7 +32,7 @@ module.exports = { { name: '<:anitrox:831193012699791361> Bot Information', value: '** **' }, { name: 'Bot Name', value: `${client.user.tag}`, inline: true }, { name: 'Bot ID', value: `${client.user.id}`, inline: true }, - { name: 'Bot Owner', value: isNaN(config.ownerID) ? "Owner didn't set an OwnerID :(" : client.users.cache.get(config.ownerID).username, inline: true }, + { name: 'Bot Owner', value: isNaN(process.env.OWNERID) ? "Owner didn't set an OwnerID :(" : client.users.cache.get(process.env.OWNERID).username, inline: true }, { name: 'Release Type', value: config.release, inline: true }, { name: 'Version', value: config.build, inline: true }, { name: ':gear: Bot Process Information', value: '** **' }, diff --git a/commands/reload.js b/commands/reload.js index 5684d5a..9f89ac1 100644 --- a/commands/reload.js +++ b/commands/reload.js @@ -5,7 +5,7 @@ module.exports = { name: require('path').parse(__filename).name, description: 'Reloads a command', options: [...Array(10).keys()].map(i => ({ - name: `option${i + 1}`, + name: `option${i + 0}`, description: 'Another option', required: i === 0, type: Constants.ApplicationCommandOptionTypes.STRING @@ -20,7 +20,7 @@ module.exports = { }, handle (client, config, user, args) { - if (user.id === config.ownerID) { + if (user.id === process.env.OWNERID) { if (!args.length) return client.generateErrorMessage('You forgot to provide anything to reload, you pillock', user.displayAvatarURL()); let returnMessage = ''; diff --git a/commands/restart.js b/commands/restart.js index 8ef1f9d..51c91a2 100644 --- a/commands/restart.js +++ b/commands/restart.js @@ -13,7 +13,7 @@ module.exports = { }, async handle (client, config, user, channel) { - if (user.id === config.ownerID) { + if (user.id === process.env.OWNERID) { const embeds = [{ title: ' Restart Bot', description: 'Restarting Anitrox...', @@ -27,11 +27,11 @@ module.exports = { const response = await channel.send({ embeds }); try { client.destroy(); - await client.login(config.token); + await client.login(process.env.TOKEN); console.log('[SYSTEM] [INFO] Restarted successfully!'); await response.edit({ embeds: [{ - title: ' Restart Bot', + title: ':white_check_mark: Restart Bot', description: 'Restarted!', color: 9442302, footer: { diff --git a/commands/stop.js b/commands/stop.js index a9c8e0e..9035530 100644 --- a/commands/stop.js +++ b/commands/stop.js @@ -13,7 +13,7 @@ module.exports = { }, async handle (client, config, user, channel) { - if (user.id === config.ownerID) { + if (user.id === process.env.OWNERID) { console.log('[SYSTEM] [INFO] ' + `The bot is going down for shut down. \nShutdown requested by ${user.username}`); await channel.send({ embeds: [{ diff --git a/config-example.json b/config-example.json index 92ac10e..56e1a1d 100644 --- a/config-example.json +++ b/config-example.json @@ -1,7 +1,5 @@ { "prefix": "n!", - "token": "IM SO EXCITED ABOUT BURGER", - "ownerID": "MY FAVORITE COLOR IS TWELVE", "release": "Stable Release", "build": "1.3", "footerTxt": "Anitrox, made with <3 by IDeletedSystem64 | 2018-2022", diff --git a/start.js b/start.js index 6d2403b..3c37ded 100755 --- a/start.js +++ b/start.js @@ -3,7 +3,7 @@ const fs = require('fs'); const Discord = require('discord.js'); const config = require('./config.json'); - +require('dotenv').config(); console.log('Starting!'); const client = new Discord.Client({ intents: config.intents.map(intent => eval(`Discord.Intents.FLAGS.${intent}`)) }); @@ -14,6 +14,7 @@ fs.readdirSync('./commands') const command = require(`./commands/${file}`); client.commands.set(command.name, command); }); +// Create a collection using those command files fs.readdirSync('./events') .filter(file => file.endsWith('.js')) @@ -21,6 +22,7 @@ fs.readdirSync('./events') .forEach(({ once, event, listener }) => { client[once ? 'once' : 'on'](event, listener(client, config)); }); +// Create listeners from the event files. client.generateErrorMessage = (errorMsg, avatarURL) => ({ embeds: [{ @@ -39,4 +41,5 @@ client.generateErrorMessage = (errorMsg, avatarURL) => ({ }] }); -client.login(config.token); +client.login(process.env.TOKEN); +// Login to Discord!