Skip to content
This repository has been archived by the owner on Dec 19, 2018. It is now read-only.

Commit

Permalink
Convert Event Logs to Webhooks
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Ray committed Oct 23, 2018
1 parent 9cc0ca2 commit 0336964
Show file tree
Hide file tree
Showing 13 changed files with 97 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ data/
test.js
musicsettings.json
sentry.json
webhooks.json


# Runtime data
Expand Down
14 changes: 11 additions & 3 deletions commands/racd.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const fs = require('fs');
const Discord = require('discord.js');
const web = require('../webhooks.json');
exports.run = (client, message, args) => {
fs.readFile('./allowedGuildDB.json', 'utf8', async (err, data) => { // readFile method basically allows us to read the data in that file
if (err !== null) { // Just an error checker
Expand All @@ -12,6 +13,12 @@ exports.run = (client, message, args) => {
const index = requiredData.allowedGuildIDs.indexOf(guildID);
if (index !== -1) {
requiredData.allowedGuildIDs.splice(index, 1);
/*const guilds = client.activatedServers.get(args[1]);
if (guilds > 1) {
client.activatedServers.delete(args[1]);
} else {
client.activatedServers.remove(`${args[1]}`, `${guildID}`);
}*/
// And now we write the final data again
const json = JSON.stringify(requiredData);
fs.writeFile('./allowedGuildDB.json', json, 'utf8', (err) => {
Expand All @@ -24,15 +31,16 @@ exports.run = (client, message, args) => {
(guild !== undefined) ? guild.leave() : null;
message.channel.send(`✅ ***Deactivated Moonglow on ${args[0]}***`);
//const acUser = client.users.get(args[1]).tag;

const hook = new Discord.WebhookClient(web.activationLogID, web.activationLogToken);
const embed = new Discord.RichEmbed()
.setTitle('SERVER ACTIVATION')
.setTitle('SERVER DEACTIVATION')
.addField('Staff', `${message.author.tag} \`(${message.author.id})\``, true)
.addField('Guild', guildID, true)
//.addField('User', `${acUser} \`(${args[1]})\``)
.setFooter(client.user.username, client.user.avatarURL)
.setTimestamp();
client.channels.get('503491110149160961').send(embed);
//client.channels.get('503491110149160961').send(embed);
hook.send(embed);
}
else {
message.channel.send('Specified guild was never activated.');
Expand Down
18 changes: 16 additions & 2 deletions commands/racr.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const fs = require('fs');
const Discord = require('discord.js');
const web = require('../webhooks.json');
exports.run = async (client, message, args) => {

fs.readFile('./allowedGuildDB.json', 'utf8', async (err, data) => { // readFile method basically allows us to read the data in that file
Expand Down Expand Up @@ -28,6 +29,12 @@ exports.run = async (client, message, args) => {
else { // this case would mean that the file isn't empty
const requiredData = JSON.parse(data);
requiredData.allowedGuildIDs.push(guildID);
/*const find = client.activatedServers.get(args[1]);
if (find === undefined) {
client.activatedServers.set(args[1], [`${guildID}`]);
} else {
client.activatedServers.push(args[1], `${guildID}`);
}*/
// And now we write the final data again
const json = JSON.stringify(requiredData);
fs.writeFile('./allowedGuildDB.json', json, 'utf8', (err) => {
Expand All @@ -40,15 +47,22 @@ exports.run = async (client, message, args) => {
message.delete();
message.channel.send(`✅ ***Moonglow has been activated on ${guildID} for <@!${args[1]}>***`);
const acUser = client.users.get(args[1]).tag;
//const filter = (reaction) => reaction.emoji.name === '✅';

const hook = new Discord.WebhookClient(web.activationLogID, web.activationLogToken);
const embed = new Discord.RichEmbed()
.setTitle('SERVER ACTIVATION')
.addField('Staff', `${message.author.tag} \`(${message.author.id})\``, true)
.addField('Guild', guildID, true)
.addField('User', `${acUser} \`(${args[1]})\``)
.addField('User', `${acUser} \`(${args[1]})\``, true)
.setFooter(client.user.username, client.user.avatarURL)
.setTimestamp();
client.channels.get('503491110149160961').send(embed);
//const messageEmbed = await client.channels.get('503491110149160961').send(embed);
const messageEmbed = await hook.send(embed);
//console.log(messageEmbed)
await messageEmbed.react('✅');
//same tbh


}
}
Expand Down
5 changes: 4 additions & 1 deletion events/channelCreate.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const Discord = require('discord.js');
const web = require('../webhooks.json')
module.exports = async (client, channel, guild) => { //eslint-disable-line no-unused-vars
const channelName = await channel.name;
const channelID = await channel.id;
Expand All @@ -7,12 +8,14 @@ module.exports = async (client, channel, guild) => { //eslint-disable-line no-un
const guildIcon = await channel.guild.iconURL;

const embed = new Discord.RichEmbed();
const hook = new Discord.WebhookClient(web.channelCreateID, web.channelCreateToken);
embed.setTitle('Channel Create Event');
embed.setThumbnail(guildIcon)
embed.addField('Channel', `${channelName} \`(${channelID})\``);
embed.addField('Guild', `${guildName} \`(${guildID})\``);
embed.setFooter(client.user.username, client.user.avatarURL);
embed.setTimestamp();

client.channels.get('503431040451215360').send(embed);
//client.channels.get('503431040451215360').send(embed);
hook.send(embed);
};
19 changes: 19 additions & 0 deletions events/guildBanAdd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const Discord = require('discord.js');
const web = require('../webhooks.json');

module.exports = async (client, guild, user) => {
const guildName = guild.name;
const guildID = guild.id;
const userName = user.tag;
const userID = user.id;

const hook = new Discord.WebhookClient(web.guildBanAddID, web.guildBanAddToken);
const embed = new Discord.RichEmbed()
.setTitle('Guild Ban Add Event')
.setThumbnail(guild.iconURL)
.addField('Guild', `${guildName} \`(${guildID})\``)
.addField('User', `${userName} \`(${userID})\``)
.setTimestamp()
.setFooter(client.user.username, client.user.avatarURL);
hook.send(embed);
};
9 changes: 7 additions & 2 deletions events/guildCreate.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// This event executes when a new guild (server) is joined.
const Discord = require('discord.js');
const fs = require('fs');
const web = require('../webhooks.json');
module.exports = (client, guild) => {
/* this code checks to make sure that the bot is in the authorized list of servers below in the "activatedServers"
If it's not in this list, then the bot will leave the server and then will return a DEBUG message to the console. */
Expand All @@ -13,6 +14,7 @@ module.exports = (client, guild) => {
const allowedGuild = JSON.parse(data);
if (allowedGuild.allowedGuildIDs.includes(guild.id)) {
client.logger.debug(`[GUILD AUTHORIZED] ${guild.name}`);
const hook1 = new Discord.WebhookClient(web.guildCreateID, web.guildCreateToken);
const successEmbed = new Discord.RichEmbed()
.setTitle('Guild Create Event')
.setThumbnail(guild.iconURl)
Expand All @@ -22,12 +24,14 @@ module.exports = (client, guild) => {
.setFooter(client.user.username, client.user.avatarURL)
.setTimestamp();

client.channels.get('503374601892397060').send(successEmbed);
//client.channels.get('503374601892397060').send(successEmbed);
hook1.send(successEmbed);

return;
}
else {
client.logger.debug(`[GUILD UNAUTHORIZED] ${guild.name} (${guild.id}) added the bot. Owner: ${guild.owner.user.tag} (${guild.owner.user.id})`);
const hook2 = new Discord.WebhookClient(web.guildCreateID, web.guildCreateToken);
const errorEmbed = new Discord.RichEmbed()
.setTitle('Guild Create Event')
.setThumbnail(guild.iconURl)
Expand All @@ -36,7 +40,8 @@ module.exports = (client, guild) => {
.addField('Owner', `${guild.owner.user.tag} \`\`(${guild.owner.user.id})\`\``)
.setFooter(client.user.username, client.user.avatarURL)
.setTimestamp();
client.channels.get('503374601892397060').send(errorEmbed);
//client.channels.get('503374601892397060').send(errorEmbed);
hook2.send(errorEmbed);
return guild.leave(guild.id);
}
}
Expand Down
5 changes: 4 additions & 1 deletion events/guildDelete.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
// This event executes when a new guild (server) is left.
const Discord = require('discord.js');
const fs = require('fs');
const web = require('../webhooks.json');
module.exports = (client, guild) => {
client.logger.cmd(`[GUILD LEAVE] ${guild.name} (${guild.id}) removed the bot.`);
const hook = new Discord.WebhookClient(web.guildDeleteID, web.guildDeleteToken);
const successEmbed = new Discord.RichEmbed()
.setTitle('Guild Delete Event')
.setThumbnail(guild.iconURl)
.addField('Guild', `${guild.name} \`\`(${guild.id})\`\``, true)
.addField('Owner', `${guild.owner.user.tag} \`\`(${guild.owner.user.id})\`\``)
.setFooter(client.user.username, client.user.avatarURL)
.setTimestamp();
client.channels.get('503374615154786324').send(successEmbed);
//client.channels.get('503374615154786324').send(successEmbed);
hook.send(successEmbed);

fs.readFile('./allowedGuildDB.json', 'utf8', async (err, data) => { // readFile method basically allows us to read the data in that file
if (err !== null) { // Just an error checker
Expand Down
12 changes: 11 additions & 1 deletion events/guildUnavailable.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
const Discord = require('discord.js');
const web = require('../webhooks.json');
module.exports = (client, guild) => {
const guildName = guild.name;
const guildID = guild.id;
client.channels.get('503374691046653963').send(`Guild ${guildName} with ID ${guildID} has become unavailable to the client.`);
const guildOwner = guild.owner;
//client.channels.get('503374691046653963').send(`Guild ${guildName} with ID ${guildID} has become unavailable to the client.`);
const hook = new Discord.WebhookClient(web.guildUnavailableID, web.guildUnavailableToken);
const embed = new Discord.RichEmbed()
.setTitle('Guild Unavailable Event')
.addField('Guild', `${guildName} \`(${guildID})\` by ${guildOwner}`)
.setTimestamp()
.setFooter(client.user.username, client.user.avatarURL);
hook.send(embed);
};
8 changes: 6 additions & 2 deletions events/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Note that due to the binding of client to every event, every event
// goes `client, other, args` when this function is run.
const Discord = require('discord.js');
const web = require('../webhooks.json');
module.exports = async (client, message) => {
// It's good practice to ignore other bots. This also makes your bot ignore itself
// and not get into a spam loop (we call that "botception").
Expand Down Expand Up @@ -66,7 +67,8 @@ module.exports = async (client, message) => {
}
// If the command exists, **AND** the user has permission, run it.
client.logger.cmd(`[CMD] ${client.config.permLevels.find(l => l.level === level).name} ${message.author.username} (${message.author.id}) ran command ${cmd.help.name}`);


const hook = new Discord.WebhookClient(web.commandLogID, web.commandLogToken);
const embed = new Discord.RichEmbed();
embed.setTitle('COMMAND EXECUTED');
embed.addField('User', `${message.author.username} \`(${message.author.id})\``, true);
Expand All @@ -82,6 +84,8 @@ module.exports = async (client, message) => {
}
embed.setFooter(client.user.username, client.user.avatarURL);
embed.setTimestamp();
client.channels.get('503391943452000257').send(embed);
//client.channels.get('503391943452000257').send(embed);
hook.send(embed);

cmd.run(client, message, args, level);
};
5 changes: 4 additions & 1 deletion events/messageDelete.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const Discord = require('discord.js');
const web = require('../webhooks.json');
module.exports = async (client, message, member, guild) => { //eslint-disable-line no-unused-vars
const memberName = message.member.user.tag;
const memberID = message.member.id;
Expand All @@ -10,6 +11,7 @@ module.exports = async (client, message, member, guild) => { //eslint-disable-li
const channelName = message.channel.name;
const channelID = message.channel.id;

const hook = new Discord.WebhookClient(web.messageDeleteID, web.messageDeleteToken);
const embed = new Discord.RichEmbed()
.setTitle('Message Deletion Event')
.setThumbnail(guildIcon)
Expand All @@ -20,7 +22,8 @@ module.exports = async (client, message, member, guild) => { //eslint-disable-li
.addField('Created At', createdAt, true)
.setFooter(client.user.username, client.user.avatarURL)
.setTimestamp();
client.channels.get('503373884251308042').send(embed);
//client.channels.get('503373884251308042').send(embed);
hook.send(embed);


};
7 changes: 5 additions & 2 deletions events/messageUpdate.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const Discord = require('discord.js');
const web = require('../webhooks.json')
module.exports = async (client, message, oldMessage) => { //eslint-disable-line no-unused-vars
const memberName = message.member.user.tag;
const memberID = message.member.id;
Expand All @@ -11,7 +12,8 @@ module.exports = async (client, message, oldMessage) => { //eslint-disable-line
const oldContent = message.content;
const newContent = oldMessage.content;
if (oldContent === newContent) return;


const hook = new Discord.WebhookClient(web.messageUpdateID, web.messageUpdateToken);
const embed = new Discord.RichEmbed()
.setTitle('Message Edited Event')
.setThumbnail(guildIcon)
Expand All @@ -23,5 +25,6 @@ module.exports = async (client, message, oldMessage) => { //eslint-disable-line
.addField('Created At', createdAt, true)
.setFooter(client.user.username, client.user.avatarURL)
.setTimestamp();
client.channels.get('503387318162292736').send(embed);
//client.channels.get('503387318162292736').send(embed);
hook.send(embed);
};
6 changes: 4 additions & 2 deletions events/ready.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
const Discord = require('discord.js');
const web = require('../webhooks.json');
module.exports = async client => {
// Log that the bot is online.
client.logger.log(`${client.user.tag}, ready to serve ${client.users.size} users in ${client.guilds.size} servers.`, 'ready');

// Make the bot "play the game" which is the help command with default prefix.
client.user.setActivity(`${client.config.defaultSettings.prefix}help | ${client.users.size} users`, {type: 'PLAYING'});
//client.channels.get('503384677227429888').send(`\`\`\`js\n\n${client.user.tag} is now online in ${client.guilds.size} servers with ${client.users.size} users.\`\`\``);

const hook = new Discord.WebhookClient(web.mainLogID, web.mainLogToken);
const embed = new Discord.RichEmbed()
.setTitle('Ready Event')
.setThumbnail(client.user.avatarURL)
Expand All @@ -18,7 +19,8 @@ module.exports = async client => {
.setFooter(client.user.username, client.user.avatarURL)
.setTimestamp();

client.channels.get('503384677227429888').send(embed);
//client.channels.get('503384677227429888').send(embed);
hook.send(embed);


};
7 changes: 5 additions & 2 deletions events/roleCreate.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const Discord = require('discord.js');
const web = require('../webhooks.json');

module.exports = async (client, role) => {
const roleName = role.name;
Expand All @@ -9,7 +10,8 @@ module.exports = async (client, role) => {
const guildName = role.guild.name;
const guildID = role.guild.id;
const guildIcon = role.guild.iconURL;


const hook = new Discord.WebhookClient(web.roleCreateID, web.roleCreateToken);
const embed = new Discord.RichEmbed()
.setTitle('Role Create Event')
.setThumbnail(guildIcon)
Expand All @@ -20,6 +22,7 @@ module.exports = async (client, role) => {
.addField('Guild', `${guildName} \`(${guildID})\``)
.setFooter(client.user.username, client.user.avatarURL)
.setTimestamp();
client.channels.get('503828179241271306').send(embed);
//client.channels.get('503828179241271306').send(embed);
hook.send(embed);

};

0 comments on commit 0336964

Please sign in to comment.