mirror of
https://github.com/yuzu-emu/Command-fix.git
synced 2024-12-22 23:35:36 +00:00
Merge pull request #64 from CaptV0rt3x/logger
Add logging for message edits/deletions
This commit is contained in:
commit
5bfcbb3f62
3
env.json
3
env.json
|
@ -17,6 +17,9 @@
|
||||||
"DISCORD_LOG_CHANNEL": {
|
"DISCORD_LOG_CHANNEL": {
|
||||||
"description": "The unique ID for the channel the bot will output logs to."
|
"description": "The unique ID for the channel the bot will output logs to."
|
||||||
},
|
},
|
||||||
|
"DISCORD_MSGLOG_CHANNEL": {
|
||||||
|
"description": "The unique ID for the channel the bot will output message logs to."
|
||||||
|
},
|
||||||
"DISCORD_MEDIA_CHANNEL": {
|
"DISCORD_MEDIA_CHANNEL": {
|
||||||
"description": "The unique ID for the channel the bot will moderate images in."
|
"description": "The unique ID for the channel the bot will moderate images in."
|
||||||
},
|
},
|
||||||
|
|
|
@ -35,9 +35,15 @@ function findArray (haystack, arr) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function IsIgnoredChannel (channelName) {
|
||||||
|
const IgnoredChannels = ['welcome', 'announcements', 'media'];
|
||||||
|
return IgnoredChannels.includes(channelName);
|
||||||
|
}
|
||||||
|
|
||||||
client.on('ready', () => {
|
client.on('ready', () => {
|
||||||
// Initialize app channels.
|
// Initialize app channels.
|
||||||
state.logChannel = client.channels.get(process.env.DISCORD_LOG_CHANNEL);
|
state.logChannel = client.channels.get(process.env.DISCORD_LOG_CHANNEL);
|
||||||
|
state.msglogChannel = client.channels.get(process.env.DISCORD_MSGLOG_CHANNEL);
|
||||||
state.guild = state.logChannel.guild;
|
state.guild = state.logChannel.guild;
|
||||||
|
|
||||||
logger.info('Bot is now online and connected to server.');
|
logger.info('Bot is now online and connected to server.');
|
||||||
|
@ -65,6 +71,42 @@ client.on('guildMemberAdd', (member) => {
|
||||||
member.addRole(process.env.DISCORD_RULES_ROLE);
|
member.addRole(process.env.DISCORD_RULES_ROLE);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
client.on('messageDelete', message => {
|
||||||
|
if (IsIgnoredChannel(message.channel.name) == false) {
|
||||||
|
if (message.content && message.content.startsWith('.') == false && message.author.bot == false) {
|
||||||
|
const deletionEmbed = new discord.RichEmbed()
|
||||||
|
.setAuthor(message.author.tag, message.author.displayAvatarURL)
|
||||||
|
.setDescription(`Message deleted in ${message.channel}`)
|
||||||
|
.addField('Content', message.cleanContent, false)
|
||||||
|
.setTimestamp()
|
||||||
|
.setColor('RED');
|
||||||
|
|
||||||
|
state.msglogChannel.send(deletionEmbed);
|
||||||
|
logger.info(`${message.author.username} ${message.author} deleted message: ${message.cleanContent}.`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
client.on('messageUpdate', (oldMessage, newMessage) => {
|
||||||
|
if (IsIgnoredChannel(oldMessage.channel.name) == false) {
|
||||||
|
const oldM = oldMessage.cleanContent;
|
||||||
|
const newM = newMessage.cleanContent;
|
||||||
|
|
||||||
|
if (oldM && newM) {
|
||||||
|
const editedEmbed = new discord.RichEmbed()
|
||||||
|
.setAuthor(oldMessage.author.tag, oldMessage.author.displayAvatarURL)
|
||||||
|
.setDescription(`Message edited in ${oldMessage.channel} [Jump To Message](${newMessage.url})`)
|
||||||
|
.addField('Before', oldM, false)
|
||||||
|
.addField('After', newM, false)
|
||||||
|
.setTimestamp()
|
||||||
|
.setColor('GREEN');
|
||||||
|
|
||||||
|
state.msglogChannel.send(editedEmbed);
|
||||||
|
logger.info(`${oldMessage.author.username} ${oldMessage.author} edited message from: ${oldM} to: ${newM}.`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
client.on('message', message => {
|
client.on('message', message => {
|
||||||
if (message.author.bot && message.content.startsWith('.ban') === false) { return; }
|
if (message.author.bot && message.content.startsWith('.ban') === false) { return; }
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
const State = function () {
|
const State = function () {
|
||||||
this.guild = null;
|
this.guild = null;
|
||||||
this.logChannel = null;
|
this.logChannel = null;
|
||||||
|
this.msglogChannel = null;
|
||||||
this.warnings = [];
|
this.warnings = [];
|
||||||
this.responses = null;
|
this.responses = null;
|
||||||
this.bans = [];
|
this.bans = [];
|
||||||
|
|
Loading…
Reference in a new issue