Rework IgnoreChannel logic

This commit is contained in:
CaptV0rt3x 2019-08-12 13:14:22 +05:30
parent 8e6891efab
commit e9828eb969
1 changed files with 30 additions and 21 deletions

View File

@ -35,6 +35,11 @@ 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);
@ -67,34 +72,38 @@ client.on('guildMemberAdd', (member) => {
}); });
client.on('messageDelete', message => { client.on('messageDelete', message => {
if (Boolean(message.content) && !message.content.startsWith('.')) { if (IsIgnoredChannel(message.channel.name) == false) {
const deletionEmbed = new discord.RichEmbed() if (message.content && message.content.startsWith('.') == false && message.author.bot == false) {
.setAuthor(message.author.tag, message.author.displayAvatarURL) const deletionEmbed = new discord.RichEmbed()
.setDescription(`Message deleted in ${message.channel}`) .setAuthor(message.author.tag, message.author.displayAvatarURL)
.addField('Content', message.cleanContent, false) .setDescription(`Message deleted in ${message.channel}`)
.setTimestamp() .addField('Content', message.cleanContent, false)
.setColor('RED'); .setTimestamp()
.setColor('RED');
state.msglogChannel.send(deletionEmbed); state.msglogChannel.send(deletionEmbed);
logger.info(`${message.author.username} ${message.author} deleted message: ${message.cleanContent}.`); logger.info(`${message.author.username} ${message.author} deleted message: ${message.cleanContent}.`);
}
} }
}); });
client.on('messageUpdate', (oldMessage, newMessage) => { client.on('messageUpdate', (oldMessage, newMessage) => {
const oldM = oldMessage.cleanContent; if (IsIgnoredChannel(oldMessage.channel.name) == false) {
const newM = newMessage.cleanContent; const oldM = oldMessage.cleanContent;
const newM = newMessage.cleanContent;
if (Boolean(oldM) && Boolean(newM)) { if (oldM && newM) {
const editedEmbed = new discord.RichEmbed() const editedEmbed = new discord.RichEmbed()
.setAuthor(oldMessage.author.tag, oldMessage.author.displayAvatarURL) .setAuthor(oldMessage.author.tag, oldMessage.author.displayAvatarURL)
.setDescription(`Message edited in ${oldMessage.channel} [Jump To Message](${newMessage.url})`) .setDescription(`Message edited in ${oldMessage.channel} [Jump To Message](${newMessage.url})`)
.addField('Before', oldM, false) .addField('Before', oldM, false)
.addField('After', newM, false) .addField('After', newM, false)
.setTimestamp() .setTimestamp()
.setColor('GREEN'); .setColor('GREEN');
state.msglogChannel.send(editedEmbed); state.msglogChannel.send(editedEmbed);
logger.info(`${oldMessage.author.username} ${oldMessage.author} edited message from: ${oldM} to: ${newM}.`); logger.info(`${oldMessage.author.username} ${oldMessage.author} edited message from: ${oldM} to: ${newM}.`);
}
} }
}); });