Rework IgnoreChannel logic

This commit is contained in:
CaptV0rt3x 2019-08-12 13:14:22 +05:30
parent 8e6891efab
commit e9828eb969

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,7 +72,8 @@ 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) {
if (message.content && message.content.startsWith('.') == false && message.author.bot == false) {
const deletionEmbed = new discord.RichEmbed() const deletionEmbed = new discord.RichEmbed()
.setAuthor(message.author.tag, message.author.displayAvatarURL) .setAuthor(message.author.tag, message.author.displayAvatarURL)
.setDescription(`Message deleted in ${message.channel}`) .setDescription(`Message deleted in ${message.channel}`)
@ -78,13 +84,15 @@ client.on('messageDelete', message => {
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) => {
if (IsIgnoredChannel(oldMessage.channel.name) == false) {
const oldM = oldMessage.cleanContent; const oldM = oldMessage.cleanContent;
const newM = newMessage.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})`)
@ -96,6 +104,7 @@ client.on('messageUpdate', (oldMessage, newMessage) => {
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}.`);
} }
}
}); });
client.on('message', message => { client.on('message', message => {