diff --git a/README.md b/README.md index 0970d819..210cc8e9 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ APIs that require API Keys: > Note: If you do self-host, you will need to go into the file `index.js` and remove the entries for requests to Discord Bots and Carbon. -You will also need a Discord App and Token. You can get those [here](https://discordapp.com/developers/applications). No support is provided for self-hosting, if you self-host, you should know how to do so. All API Keys and the Token should be placed in the file `config.json` in the appropriate area. +You will also need a Discord App and Token. You can get those [here](https://discordapp.com/developers/applications). No support is provided for self-hosting, if you self-host, you should know how to do so. All API Keys and the Token should be placed in environment variables. ## Licensing The bot is licensed under an [ISC license](https://opensource.org/licenses/ISC). See the file `LICENSE.md` for more information. diff --git a/commands/botinfo/contact.js b/commands/botinfo/contact.js index 50fcdd63..839c7522 100644 --- a/commands/botinfo/contact.js +++ b/commands/botinfo/contact.js @@ -1,5 +1,4 @@ const commando = require('discord.js-commando'); -const config = require('../../config.json'); module.exports = class ContactCommand extends commando.Command { constructor(Client) { @@ -28,7 +27,7 @@ module.exports = class ContactCommand extends commando.Command { } console.log(`[Command] ${message.content}`); const messageToReport = args.report; - const reportedMsg = await this.client.users.get(config.owner).send(`**${message.author.username}#${message.author.discriminator} (${message.author.id}):**\n${messageToReport}`); + const reportedMsg = await this.client.users.get(process.env.OWNER_ID).send(`**${message.author.username}#${message.author.discriminator} (${message.author.id}):**\n${messageToReport}`); const successMsg = await message.say('Message Sent! Thanks for your support!'); return [reportedMsg, successMsg]; } diff --git a/commands/botinfo/info.js b/commands/botinfo/info.js index 343429d1..50906d02 100644 --- a/commands/botinfo/info.js +++ b/commands/botinfo/info.js @@ -1,6 +1,5 @@ const commando = require('discord.js-commando'); const Discord = require('discord.js'); -const config = require('../../config.json'); const pkg = require('../../package.json'); const moment = require('moment'); require('moment-duration-format'); @@ -34,7 +33,7 @@ module.exports = class InfoCommand extends commando.Command { .addField('Shards', this.client.options.shardCount, true) .addField('Commands', - config.commandCount, true) + '113', true) .addField('Owner', 'dragonfire535#8081', true) .addField('Source Code', diff --git a/commands/search/botinfo.js b/commands/search/botinfo.js index 00c1c95d..f03b7947 100644 --- a/commands/search/botinfo.js +++ b/commands/search/botinfo.js @@ -1,7 +1,6 @@ const commando = require('discord.js-commando'); const Discord = require('discord.js'); const request = require('superagent'); -const config = require('../../config.json'); module.exports = class BotSearchCommand extends commando.Command { constructor(Client) { @@ -33,7 +32,7 @@ module.exports = class BotSearchCommand extends commando.Command { const response = await request .get(`https://bots.discord.pw/api/bots/${botToFind}`) .set({ - 'Authorization': config.botskey + 'Authorization': process.env.DISCORD_BOTS_KEY }); const data = response.body; const embed = new Discord.RichEmbed() diff --git a/commands/search/define.js b/commands/search/define.js index 7272ec7f..ea616725 100644 --- a/commands/search/define.js +++ b/commands/search/define.js @@ -1,7 +1,6 @@ const commando = require('discord.js-commando'); const Discord = require('discord.js'); const request = require('superagent'); -const config = require('../../config.json'); module.exports = class DefineCommand extends commando.Command { constructor(Client) { @@ -39,7 +38,7 @@ module.exports = class DefineCommand extends commando.Command { includeRelated: false, useCanonical: false, includeTags: false, - api_key: config.wordnikkey + api_key: process.env.WORDNIK_KEY }); const data = response.body[0]; const embed = new Discord.RichEmbed() diff --git a/commands/search/osu.js b/commands/search/osu.js index fb17f10c..3f7e7d8f 100644 --- a/commands/search/osu.js +++ b/commands/search/osu.js @@ -1,6 +1,5 @@ const commando = require('discord.js-commando'); const Discord = require('discord.js'); -const config = require('../../config.json'); const request = require('superagent'); module.exports = class OsuCommand extends commando.Command { @@ -34,7 +33,7 @@ module.exports = class OsuCommand extends commando.Command { const response = await request .get('https://osu.ppy.sh/api/get_user') .query({ - k: config.osukey, + k: process.env.OSU_KEY, u: usernameToSearch, type: 'string' }); diff --git a/commands/search/wattpad.js b/commands/search/wattpad.js index 70b19c34..fb1bd697 100644 --- a/commands/search/wattpad.js +++ b/commands/search/wattpad.js @@ -1,7 +1,6 @@ const commando = require('discord.js-commando'); const Discord = require('discord.js'); const request = require('superagent'); -const config = require('../../config.json'); module.exports = class WattpadCommand extends commando.Command { constructor(Client) { @@ -29,7 +28,7 @@ module.exports = class WattpadCommand extends commando.Command { const response = await request .get('https://api.wattpad.com:443/v4/stories') .set({ - 'Authorization': `Basic ${config.wattpadkey}` + 'Authorization': `Basic ${process.env.WATTPAD_KEY}` }) .query({ query: queryBook, diff --git a/commands/search/youtube.js b/commands/search/youtube.js index 59537292..442efb9a 100644 --- a/commands/search/youtube.js +++ b/commands/search/youtube.js @@ -1,7 +1,6 @@ const commando = require('discord.js-commando'); const Discord = require('discord.js'); const request = require('superagent'); -const config = require('../../config.json'); module.exports = class YouTubeCommand extends commando.Command { constructor(Client) { @@ -36,7 +35,7 @@ module.exports = class YouTubeCommand extends commando.Command { type: 'video', maxResults: 1, q: videoToSearch, - key: config.youtubekey + key: process.env.YOUTUBE_KEY }); const data = response.body.items[0]; const embed = new Discord.RichEmbed() diff --git a/commands/textedit/webhook.js b/commands/textedit/webhook.js index 1d95fe7f..6c63c16b 100644 --- a/commands/textedit/webhook.js +++ b/commands/textedit/webhook.js @@ -1,6 +1,5 @@ const commando = require('discord.js-commando'); const request = require('superagent'); -const config = require('../../config.json'); module.exports = class WebhookCommand extends commando.Command { constructor(Client) { @@ -12,7 +11,7 @@ module.exports = class WebhookCommand extends commando.Command { ], group: 'textedit', memberName: 'webhook', - description: 'Posts a message to the webhook defined in config. (;webhook Hey guys!)', + description: 'Posts a message to the webhook defined in your `process.env`. (;webhook Hey guys!)', examples: [';webhook Hey guys!'], guildOnly: true, args: [{ @@ -35,7 +34,7 @@ module.exports = class WebhookCommand extends commando.Command { try { await message.delete(); await request - .post(config.webhook) + .post(process.env.WEBHOOK_URL) .send({ content: content }); diff --git a/commands/textedit/yoda.js b/commands/textedit/yoda.js index 788ca4df..da995fdb 100644 --- a/commands/textedit/yoda.js +++ b/commands/textedit/yoda.js @@ -1,6 +1,5 @@ const commando = require('discord.js-commando'); const request = require('superagent'); -const config = require('../../config.json'); module.exports = class YodaCommand extends commando.Command { constructor(Client) { @@ -28,7 +27,7 @@ module.exports = class YodaCommand extends commando.Command { const response = await request .get('https://yoda.p.mashape.com/yoda') .set({ - 'X-Mashape-Key': config.mashapekey, + 'X-Mashape-Key': process.env.MASHAPE_KEY, 'Accept': 'text/plain' }) .query({ diff --git a/index.js b/index.js index d8c343f8..e68cc45e 100644 --- a/index.js +++ b/index.js @@ -1,10 +1,9 @@ const commando = require('discord.js-commando'); const request = require('superagent'); -const config = require('./config.json'); const client = new commando.Client({ commandPrefix: ';', unknownCommandResponse: false, - owner: config.owner, + owner: process.env.OWNER_ID, disableEveryone: true }); const path = require('path'); @@ -34,14 +33,14 @@ client.registry client.on('guildCreate', async(guild) => { console.log(`[Guild] I have joined the guild: ${guild.name}, Owned by: ${guild.owner.user.username} (${guild.id})!`); - client.guilds.get(config.server).channels.get(config.announcementChannel).send(`I have joined the server: ${guild.name}, Owned by: ${guild.owner.user.username} (${guild.id})!`); + client.guilds.get(process.env.SERVER_ID).channels.get(process.env.ANNOUNCEMENT_CHANNEL_ID).send(`I have joined the server: ${guild.name}, Owned by: ${guild.owner.user.username} (${guild.id})!`); const results = await client.shard.fetchClientValues('guilds.size'); console.log(`[Guild Count] ${results.reduce((prev, val) => prev + val, 0)}`); try { const response = await request .post('https://www.carbonitex.net/discord/data/botdata.php') .send({ - key: config.carbonkey, + key: process.env.CARBON_KEY, servercount: results.reduce((prev, val) => prev + val, 0) }); console.log(`[Carbon] Successfully posted to Carbon. ${response.text}`); @@ -51,9 +50,9 @@ client.on('guildCreate', async(guild) => { } try { const response = await request - .post(`https://bots.discord.pw/api/bots/${config.botID}/stats`) + .post(`https://bots.discord.pw/api/bots/${process.env.BOT_ID}/stats`) .set({ - 'Authorization': config.botskey + 'Authorization': process.env.DISCORD_BOTS_KEY }) .send({ server_count: results.reduce((prev, val) => prev + val, 0) @@ -67,14 +66,14 @@ client.on('guildCreate', async(guild) => { client.on('guildDelete', async(guild) => { console.log(`[Guild] I have left the guild: ${guild.name}, Owned by: ${guild.owner.user.username} (${guild.id})...`); - client.guilds.get(config.server).channels.get(config.announcementChannel).send(`I have left the server: ${guild.name}, Owned by: ${guild.owner.user.username} (${guild.id})...`); + client.guilds.get(process.env.SERVER_ID).channels.get(process.env.ANNOUNCEMENT_CHANNEL_ID).send(`I have left the server: ${guild.name}, Owned by: ${guild.owner.user.username} (${guild.id})...`); const results = await client.shard.fetchClientValues('guilds.size'); console.log(`[Guild Count] ${results.reduce((prev, val) => prev + val, 0)}`); try { const response = await request .post('https://www.carbonitex.net/discord/data/botdata.php') .send({ - key: config.carbonkey, + key: process.env.CARBON_KEY, servercount: results.reduce((prev, val) => prev + val, 0) }); console.log(`[Carbon] Successfully posted to Carbon. ${response.text}`); @@ -84,9 +83,9 @@ client.on('guildDelete', async(guild) => { } try { const response = await request - .post(`https://bots.discord.pw/api/bots/${config.botID}/stats`) + .post(`https://bots.discord.pw/api/bots/${process.env.BOT_ID}/stats`) .set({ - 'Authorization': config.botskey + 'Authorization': process.env.DISCORD_BOTS_KEY }) .send({ server_count: results.reduce((prev, val) => prev + val, 0) @@ -109,4 +108,4 @@ client.once('ready', () => { process.on('unhandledRejection', console.error); -client.login(config.token); +client.login(process.env.TOKEN); diff --git a/package.json b/package.json index 8e0a2eec..85fd06cb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "19.1.0", + "version": "20.0.0", "description": "A Discord Bot", "main": "shardingmanager.js", "repository": { diff --git a/shardingmanager.js b/shardingmanager.js index 194427cf..10a0420f 100644 --- a/shardingmanager.js +++ b/shardingmanager.js @@ -1,7 +1,6 @@ const Discord = require('discord.js'); -const config = require('./config.json'); const Manager = new Discord.ShardingManager('./index.js', { - token: config.token + token: process.env.TOKEN }); Manager.spawn();