From bffc1873002259127176f0ed76348cfd2f878af4 Mon Sep 17 00:00:00 2001 From: Vamsi Krishna Date: Thu, 8 Jul 2021 08:24:44 +0530 Subject: [PATCH] Fix broken role & channel exemptions (#115) * Fix broken role & channel exemptions * fix for citra * Fix long broken logging exemption * Typo * Typo2 --- src/server.ts | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/src/server.ts b/src/server.ts index f7fe473..8f918b0 100644 --- a/src/server.ts +++ b/src/server.ts @@ -39,7 +39,7 @@ function findArray(haystack: string | any[], arr: any[]) { } function IsIgnoredCategory(categoryName: string) { - const IgnoredCategory = ['internal-development', 'internal-general', 'internal-casual', 'website']; + const IgnoredCategory = ['internal', 'team', 'development']; return IgnoredCategory.includes(categoryName); } @@ -79,30 +79,38 @@ client.on('guildMemberAdd', (member) => { }); client.on('messageDelete', message => { - let parent = (message.channel as discord.TextChannel).parent; - if (parent && IsIgnoredCategory(parent.name) === false) { - if (((message.content && message.content.startsWith('.') === false) || (message.attachments.array().length > 0)) && message.author?.bot === false) { - let messageAttachment = message.attachments.array()[0]?.proxyURL + const AllowedRoles = ['Administrators', 'Moderators', 'Team', 'Developer', 'Support', 'VIP']; + let authorRoles = message.member?.roles?.cache?.map(x => x.name); + if (!authorRoles) { + logger.error(`Unable to get the roles for ${message.author}`); + return; + } + if (!findArray(authorRoles, AllowedRoles)) { + let parent = (message.channel as discord.TextChannel).parent; + if (parent && IsIgnoredCategory(parent.name) === false) { + if (((message.content && message.content.startsWith('.') === false) || (message.attachments.array().length > 0)) && message.author?.bot === false) { + let messageAttachment = message.attachments.array()[0]?.proxyURL - const deletionEmbed = new discord.MessageEmbed() - .setAuthor(message.author?.tag, message.author?.displayAvatarURL()) - .setDescription(`Message deleted in ${message.channel.toString()}`) - .addField('Content', message.cleanContent || '', false) - .setTimestamp() - .setColor('RED'); + const deletionEmbed = new discord.MessageEmbed() + .setAuthor(message.author?.tag, message.author?.displayAvatarURL()) + .setDescription(`Message deleted in ${message.channel.toString()}`) + .addField('Content', message.cleanContent || '', false) + .setTimestamp() + .setColor('RED'); - if (messageAttachment) deletionEmbed.setImage(messageAttachment) + if (messageAttachment) deletionEmbed.setImage(messageAttachment) - let userInfo = `${message.author?.toString()} (${message.author?.username}) (${message.author})` + let userInfo = `${message.author?.toString()} (${message.author?.username}) (${message.author})` - state.msglogChannel.send(userInfo, { embed: deletionEmbed }); - logger.info(`${message.author?.username} ${message.author} deleted message: ${message.cleanContent}.`); + state.msglogChannel.send(userInfo, { embed: deletionEmbed }); + logger.info(`${message.author?.username} ${message.author} deleted message: ${message.cleanContent}.`); + } } } }); client.on('messageUpdate', (oldMessage, newMessage) => { - const AllowedRoles = ['Administrators', 'Moderators', 'Team', 'VIP']; + const AllowedRoles = ['Administrators', 'Moderators', 'Team', 'Developer', 'Support', 'VIP']; let authorRoles = oldMessage.member?.roles?.cache?.map(x => x.name); if (!authorRoles) { logger.error(`Unable to get the roles for ${oldMessage.author}`);