diff --git a/index.js b/index.js index ae459e78..5cc91f84 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,5 @@ const { CommandoClient } = require('discord.js-commando'); -const { discordBots, carbon } = require('./poststats.js'); +const { discordBots, carbon, webhook } = require('./poststats.js'); const path = require('path'); const client = new CommandoClient({ commandPrefix: 'x;', @@ -33,6 +33,7 @@ client.on('guildCreate', async(guild) => { const guilds = await client.shard.fetchClientValues('guilds.size'); const count = guilds.reduce((prev, val) => prev + val, 0); console.log(`[Count] ${count}`); + webhook(`Joined ${guild.name}!`, `Shard ${client.shard.id}`, 0x33CC33); try { const carbonStats = await carbon(count); console.log(`[Carbon] Successfully posted to Carbon. ${carbonStats}`); @@ -52,6 +53,7 @@ client.on('guildDelete', async(guild) => { const guilds = await client.shard.fetchClientValues('guilds.size'); const count = guilds.reduce((prev, val) => prev + val, 0); console.log(`[Count] ${count}`); + webhook(`Left ${guild.name}...`, `Shard ${client.shard.id}`, 0xFF3300); try { const carbonStats = await carbon(count); console.log(`[Carbon] Successfully posted to Carbon. ${carbonStats}`); @@ -67,7 +69,8 @@ client.on('guildDelete', async(guild) => { }); client.on('disconnect', (event) => { - console.log(`[Disconnect] The Shard ${client.shard.id} disconnected with Code ${event.code}.`); + console.log(`[Disconnect] Shard ${client.shard.id} disconnected with Code ${event.code}.`); + webhook(`Disconnected...`, `Shard ${client.shard.id}`, 0xFF3300); process.exit(0); }); diff --git a/poststats.js b/poststats.js index e80ff764..86c42002 100644 --- a/poststats.js +++ b/poststats.js @@ -21,3 +21,19 @@ module.exports.carbon = async(count) => { }); return text; }; + +module.exports.webhook = async(description, author, color) => { + const embed = { + description: description, + author: { + name: author + }, + color: color + }; + await request + .post(process.env.LOGGER_URL) + .send({ + embeds: [embed] + }); + return null; +};