mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Switch to environment variables
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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'
|
||||
});
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
});
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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);
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiaobot",
|
||||
"version": "19.1.0",
|
||||
"version": "20.0.0",
|
||||
"description": "A Discord Bot",
|
||||
"main": "shardingmanager.js",
|
||||
"repository": {
|
||||
|
||||
+1
-2
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user