Browse Source

Greatly improve logging by fixing missing fields through fetching messages by ID

master
Abheek Dhawan 4 years ago
parent
commit
57788e15a9
  1. 129
      bot.js

129
bot.js

@ -43,36 +43,6 @@ client.on("ready", () => {
});
client.on("message", async message => {
const filter = reaction => {
return reaction.emoji.name === '😎';
};
const collector = message.createReactionCollector(filter);
collector.on('collect', (reaction, user) => {
if (reaction.count === 1) {
const kulboardEmbed = new Discord.MessageEmbed()
.setTitle("Very kül message")
.setURL(message.url)
.setAuthor(message.author ? message.author.tag : "Unknown: click on the link to find out", message.author ? message.author.avatarURL() : client.user.defaultAvatarURL)
.addField("Message", message.content)
.addField("Channel", message.channel)
.setFooter("Message ID: " + message.id)
.setColor("00c5ff")
.setTimestamp();
collection.findOne({ guild_id: message.guild.id }, (error, result) => {
if (error) {
console.error;
}
if (result.kulboard_id) {
kulboardChannel = result.kulboard_id;
if (message.guild.channels.cache.get(kulboardChannel)) {
message.guild.channels.cache.get(kulboardChannel).send(kulboardEmbed).catch(console.error);
}
}
});
}
});
if (!message.content.startsWith(prefix) || message.author.bot) {
return;j
}
@ -687,28 +657,17 @@ async function bulkDelete(message) {
}).catch(console.error);
}
client.on('messageDelete', message => {
let messageContent = message.content;
let messageAvatar;
const messageID = message.id;
let messageAuthor;
if (message.author) {
messageAuthor = message.author.tag;
messageAvatar = message.author.avatarURL();
} else {
messageAuthor = "Message was not cached";
messageAvatar = client.user.defaultAvatarURL;
}
if (!messageContent) {
messageContent = "[NONE]";
}
client.on('messageDelete', msg => {
msg.channel.messages.fetch(msg.id)
.then(message => {
const deleteEmbed = new Discord.MessageEmbed()
.setTitle('Message Deleted')
.setAuthor(message.author.tag, message.author.avatarURL())
.setURL(message.url)
.addField('Author', messageAuthor)
.addField('Message', messageContent)
.setThumbnail(messageAvatar)
.setFooter("ID: " + messageID)
.addField('Author', message.author.tag)
.addField('Message', message.content)
.setThumbnail(message.author.avatarURL())
.setFooter("ID: " + message.id)
.setTimestamp()
.setColor('e7778b');
@ -724,6 +683,7 @@ client.on('messageDelete', message => {
}
});
});
});
client.on('messageDeleteBulk', messages => {
const numMessages = messages.array().length;
@ -807,49 +767,63 @@ client.on('channelCreate', channel => {
});
client.on('messageReactionAdd', (messageReaction, user) => {
const userTag = user.tag;
messageReaction.message.channel.messages.fetch(messageReaction.message.id)
.then(message => {
const emoji = messageReaction.emoji.name;
const numEmoji = messageReaction.count;
let messageContent = messageReaction.message.content;
if (!messageContent) {
messageContent = "[NONE]";
}
let channelCategory;
const numEmoji = message.reactions.cache.get(emoji).count;
const messageReactionAddEmbed = new Discord.MessageEmbed()
.setTitle("Reaction Added")
.setURL(messageReaction.message.url)
.addField("Message", messageContent)
.addField("Reactions", `${userTag} reacted with ${emoji}, along with ${numEmoji - 1} other people in ${messageReaction.message.channel}.`)
.setURL(message.url)
.addField("Message", message.content)
.addField("Reactions", `\`${user.tag}\` reacted with \`${emoji}\`, along with ${numEmoji - 1} other people in ${messageReaction.message.channel}.`)
.setFooter("Message ID: " + messageReaction.message.id)
.setThumbnail(message.author.avatarURL())
.setTimestamp()
.setColor('00aaff');
const kulboardEmbed = new Discord.MessageEmbed()
.setTitle("Very kül message")
.setURL(message.url)
.setAuthor(message.author, message.author.avatarURL())
.addField("Message", message.content)
.addField("Channel", message.channel)
.setThumbnail(message.author.avatarURL())
.setFooter("Message ID: " + message.id)
.setColor("00c5ff")
.setTimestamp();
collection.findOne({ guild_id: messageReaction.message.guild.id }, (error, result) => {
if (error) {
console.error;
}
if (result.bot_logs_id) {
botLogsChannel = result.bot_logs_id;
if (messageReaction.message.guild.channels.cache.get(botLogsChannel)) {
messageReaction.message.guild.channels.cache.get(botLogsChannel).send(messageReactionAddEmbed).catch(console.error);
if (message.guild.channels.cache.get(botLogsChannel)) {
message.guild.channels.cache.get(botLogsChannel).send(messageReactionAddEmbed).catch(console.error);
}
if (result.kulboard_id) {
kulboardChannel = result.kulboard_id;
if (message.guild.channels.cache.get(kulboardChannel)) {
message.guild.channels.cache.get(kulboardChannel).send(kulboardEmbed).catch(console.error);
}
}
}
});
});
});
client.on('messageReactionRemove', (messageReaction, user) => {
const userTag = user.tag;
messageReaction.message.channel.messages.fetch(messageReaction.message.id)
.then(message => {
const emoji = messageReaction.emoji.name;
let messageContent = messageReaction.message.content;
if (!messageContent) {
messageContent = "[NONE]";
}
let channelCategory;
const messageReactionRemoveEmbed = new Discord.MessageEmbed()
.setTitle("Reaction Removed")
.setURL(messageReaction.message.url)
.addField("Message", messageContent)
.addField("Reactions", `${userTag} removed their reaction ${emoji} in ${messageReaction.message.channel}.`)
.setURL(message.url)
.addField("Message", message.content)
.addField("Reactions", `\`${user.tag}\` removed their reaction \`${emoji}\` in ${messageReaction.message.channel}.`)
.setFooter("Message ID: " + messageReaction.message.id)
.setThumbnail(message.author.avatarURL())
.setTimestamp()
.setColor('e7778b');
collection.findOne({ guild_id: messageReaction.message.guild.id }, (error, result) => {
@ -864,6 +838,7 @@ client.on('messageReactionRemove', (messageReaction, user) => {
}
});
});
});
client.on('roleCreate', role => {
const roleCreateEmbed = new Discord.MessageEmbed()
@ -910,8 +885,8 @@ client.on('roleDelete', role => {
});
client.on('roleUpdate', (oldRole, newRole) => {
/*const removedPerms = oldRole.permissions.filter(perm => !newRole.hasPermission(perm));
const addedPerms = newRole.permissions.filter(perm => !oldRole.hasPermission(perm));*/
const removedPerms = oldRole.permissions.toArray().filter(perm => !newRole.permissions.has(perm));
const addedPerms = newRole.permissions.toArray().filter(perm => !oldRole.permissions.has(perm));
const roleUpdateEmbed = new Discord.MessageEmbed()
.setTitle("Role Updated")
.addField("Name", `${oldRole.name} >> ${newRole.name}`)
@ -920,12 +895,12 @@ client.on('roleUpdate', (oldRole, newRole) => {
.setFooter("Role ID: " + newRole.id)
.setTimestamp()
.setColor('c9ff00');
/*if (removedPerms.array().length > 0) {
roleUpdateEmbed.addField("Permissions Removed", removedPerms.map(p => `${p}`).join(' • '));
if (removedPerms.length > 0) {
roleUpdateEmbed.addField("Permissions Removed", removedPerms.map(p => `\`${p}\``.toLowerCase()).join(' • '));
}
if (addedPerms.length > 0) {
roleUpdateEmbed.addField("Permissions Added", addedPerms.map(p => `\`${p}\``.toLowerCase()).join(' • '));
}
if (addedPerms.array().length > 0) {
roleUpdateEmbed.addField("Permissions Added", addedPerms.map(p => `${p}`).join(' • '));
}*/
collection.findOne({ guild_id: newRole.guild.id }, (error, result) => {
if (error) {
console.error;

Loading…
Cancel
Save