From 0f91c55462606ef2337cb196698dcae39745c3b5 Mon Sep 17 00:00:00 2001 From: Austin M Date: Thu, 16 Apr 2020 12:22:00 -0700 Subject: [PATCH 1/9] :art: Get senior and staff role Getting senior and staff role from config --- src/processes/antiraidListener.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/processes/antiraidListener.ts b/src/processes/antiraidListener.ts index b974a12..8aa2a01 100644 --- a/src/processes/antiraidListener.ts +++ b/src/processes/antiraidListener.ts @@ -17,14 +17,21 @@ export const antiraidListener: ProcessInterface = { const mutedRole = config.roleIDs.muted // TODO: fix staffRole to mention properly, cannot be string - //const staffRole = config.roleIDs.staff - const staffRole = 662405675107876864 + // NOTE: Pull from config, same role is achieved + const staffRole = config.roleIDs.staff + // const staffRole = 662405675107876864 + + // TODO: escape check if user is senior + // NOTE: Get role from config + const seniorRole = config.roleIDs.senior + + // DEBUG: Debug console log for role comparison + console.log(staffRole, seniorRole) client.on('message', async (message: Message) => { const lastKnownTimestamp = mentions.get(message.author.id) ?? null - // TODO: escape check if user is senior - //message.member.roles + // message.member.roles const { users: { size: mentionedUsers }, From 7099c56082c18bcec8d736c5e15f9e954bdcdefb Mon Sep 17 00:00:00 2001 From: Austin M Date: Thu, 16 Apr 2020 12:52:01 -0700 Subject: [PATCH 2/9] :poop: Senior bypass Senior now bypasses anti-raid --- src/processes/antiraidListener.ts | 40 ++++++++++++++++++------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/src/processes/antiraidListener.ts b/src/processes/antiraidListener.ts index 8aa2a01..ea13673 100644 --- a/src/processes/antiraidListener.ts +++ b/src/processes/antiraidListener.ts @@ -26,26 +26,34 @@ export const antiraidListener: ProcessInterface = { const seniorRole = config.roleIDs.senior // DEBUG: Debug console log for role comparison - console.log(staffRole, seniorRole) + // console.log(staffRole, seniorRole) client.on('message', async (message: Message) => { const lastKnownTimestamp = mentions.get(message.author.id) ?? null - // message.member.roles - - const { - users: { size: mentionedUsers }, - roles: { size: mentionedRoles } - } = message.mentions - - if ( - mentionedRoles > 1 || - mentionedUsers > 2 || - mentionedUsers + mentionedRoles > 2 - ) { - lastKnownTimestamp - ? checkOffender(message, lastKnownTimestamp) - : addOffenderToList(message) + const userRoles = message.member.roles.cache + + // Staff role is not used as of now + // const staff = userRoles.find(role => role.id === staffRole) != undefined + const senior = + userRoles.find(role => role.id === seniorRole) != undefined + + // TODO: Check if they are not staff + if (!senior) { + const { + users: { size: mentionedUsers }, + roles: { size: mentionedRoles } + } = message.mentions + + if ( + mentionedRoles > 1 || + mentionedUsers > 2 || + mentionedUsers + mentionedRoles > 2 + ) { + lastKnownTimestamp + ? checkOffender(message, lastKnownTimestamp) + : addOffenderToList(message) + } } }) From 0aa52f2a8dd228bd7a6558eba496de52dd469edd Mon Sep 17 00:00:00 2001 From: Austin M Date: Thu, 16 Apr 2020 12:52:01 -0700 Subject: [PATCH 3/9] :art: Senior Bypass Anti-Raid Senior's now bypass anti-raid features. Pls dont abuse --- src/processes/antiraidListener.ts | 40 ++++++++++++++++++------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/src/processes/antiraidListener.ts b/src/processes/antiraidListener.ts index 8aa2a01..ea13673 100644 --- a/src/processes/antiraidListener.ts +++ b/src/processes/antiraidListener.ts @@ -26,26 +26,34 @@ export const antiraidListener: ProcessInterface = { const seniorRole = config.roleIDs.senior // DEBUG: Debug console log for role comparison - console.log(staffRole, seniorRole) + // console.log(staffRole, seniorRole) client.on('message', async (message: Message) => { const lastKnownTimestamp = mentions.get(message.author.id) ?? null - // message.member.roles - - const { - users: { size: mentionedUsers }, - roles: { size: mentionedRoles } - } = message.mentions - - if ( - mentionedRoles > 1 || - mentionedUsers > 2 || - mentionedUsers + mentionedRoles > 2 - ) { - lastKnownTimestamp - ? checkOffender(message, lastKnownTimestamp) - : addOffenderToList(message) + const userRoles = message.member.roles.cache + + // Staff role is not used as of now + // const staff = userRoles.find(role => role.id === staffRole) != undefined + const senior = + userRoles.find(role => role.id === seniorRole) != undefined + + // TODO: Check if they are not staff + if (!senior) { + const { + users: { size: mentionedUsers }, + roles: { size: mentionedRoles } + } = message.mentions + + if ( + mentionedRoles > 1 || + mentionedUsers > 2 || + mentionedUsers + mentionedRoles > 2 + ) { + lastKnownTimestamp + ? checkOffender(message, lastKnownTimestamp) + : addOffenderToList(message) + } } }) From b9db8739c822925f8fe1a9224c1db002a0dc865e Mon Sep 17 00:00:00 2001 From: Austin M Date: Fri, 17 Apr 2020 10:44:21 -0700 Subject: [PATCH 4/9] :art: Staff and Seniors are exempt Staff and seniors are now exempt from the anti raid, added some notes as well on what needs to be done with the continuation of it. Need to add a message to send to #mod-log, yet it has not been implemented --- src/processes/antiraidListener.ts | 37 +++++++++++++++++-------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/processes/antiraidListener.ts b/src/processes/antiraidListener.ts index ea13673..9886fa5 100644 --- a/src/processes/antiraidListener.ts +++ b/src/processes/antiraidListener.ts @@ -16,12 +16,10 @@ export const antiraidListener: ProcessInterface = { const mentions = new Map() const mutedRole = config.roleIDs.muted - // TODO: fix staffRole to mention properly, cannot be string // NOTE: Pull from config, same role is achieved const staffRole = config.roleIDs.staff // const staffRole = 662405675107876864 - // TODO: escape check if user is senior // NOTE: Get role from config const seniorRole = config.roleIDs.senior @@ -34,25 +32,28 @@ export const antiraidListener: ProcessInterface = { const userRoles = message.member.roles.cache // Staff role is not used as of now - // const staff = userRoles.find(role => role.id === staffRole) != undefined + const staff = + userRoles.find(role => role.id === staffRole) != undefined const senior = userRoles.find(role => role.id === seniorRole) != undefined - // TODO: Check if they are not staff + // NOTE: Cant combine the two roles else theres weird operator logic if (!senior) { - const { - users: { size: mentionedUsers }, - roles: { size: mentionedRoles } - } = message.mentions - - if ( - mentionedRoles > 1 || - mentionedUsers > 2 || - mentionedUsers + mentionedRoles > 2 - ) { - lastKnownTimestamp - ? checkOffender(message, lastKnownTimestamp) - : addOffenderToList(message) + if (!staff) { + const { + users: { size: mentionedUsers }, + roles: { size: mentionedRoles } + } = message.mentions + + if ( + mentionedRoles > 1 || + mentionedUsers > 2 || + mentionedUsers + mentionedRoles > 2 + ) { + lastKnownTimestamp + ? checkOffender(message, lastKnownTimestamp) + : addOffenderToList(message) + } } } }) @@ -73,6 +74,8 @@ export const antiraidListener: ProcessInterface = { const triggerAntiraid = async message => { await message.delete() message.member.roles.add(mutedRole) + // NOTE: This worked in development, should work in production + // TODO: Send message to #mod-log message.channel.send( `<@${message.author.id}> messed with the honk, so he got the bonk. (<@&${staffRole}>)` ) From 2e0ee95f548d726141c50c7204b512b23682692a Mon Sep 17 00:00:00 2001 From: Austin M Date: Fri, 17 Apr 2020 11:42:55 -0700 Subject: [PATCH 5/9] :art: Updated logic for if statement and var names Thanks to wafflen for the suggestions on the logic and var names --- src/processes/antiraidListener.ts | 49 +++++++++++++++---------------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/src/processes/antiraidListener.ts b/src/processes/antiraidListener.ts index 9886fa5..25b93a8 100644 --- a/src/processes/antiraidListener.ts +++ b/src/processes/antiraidListener.ts @@ -17,11 +17,11 @@ export const antiraidListener: ProcessInterface = { const mutedRole = config.roleIDs.muted // NOTE: Pull from config, same role is achieved - const staffRole = config.roleIDs.staff + const staffRoleId = config.roleIDs.staff // const staffRole = 662405675107876864 // NOTE: Get role from config - const seniorRole = config.roleIDs.senior + const seniorRoleId = config.roleIDs.senior // DEBUG: Debug console log for role comparison // console.log(staffRole, seniorRole) @@ -29,31 +29,28 @@ export const antiraidListener: ProcessInterface = { client.on('message', async (message: Message) => { const lastKnownTimestamp = mentions.get(message.author.id) ?? null - const userRoles = message.member.roles.cache + const userRoleIds = message.member.roles.cache.map(r => r.id) // Staff role is not used as of now - const staff = - userRoles.find(role => role.id === staffRole) != undefined - const senior = - userRoles.find(role => role.id === seniorRole) != undefined - - // NOTE: Cant combine the two roles else theres weird operator logic - if (!senior) { - if (!staff) { - const { - users: { size: mentionedUsers }, - roles: { size: mentionedRoles } - } = message.mentions - - if ( - mentionedRoles > 1 || - mentionedUsers > 2 || - mentionedUsers + mentionedRoles > 2 - ) { - lastKnownTimestamp - ? checkOffender(message, lastKnownTimestamp) - : addOffenderToList(message) - } + const isStaff = userRoleIds.find(r => r === staffRoleId) + const isSenior = userRoleIds.find(r => r === seniorRoleId) + + if (isStaff || isSenior) { + return + } else { + const { + users: { size: mentionedUsers }, + roles: { size: mentionedRoles } + } = message.mentions + + if ( + mentionedRoles > 1 || + mentionedUsers > 2 || + mentionedUsers + mentionedRoles > 2 + ) { + lastKnownTimestamp + ? checkOffender(message, lastKnownTimestamp) + : addOffenderToList(message) } } }) @@ -77,7 +74,7 @@ export const antiraidListener: ProcessInterface = { // NOTE: This worked in development, should work in production // TODO: Send message to #mod-log message.channel.send( - `<@${message.author.id}> messed with the honk, so he got the bonk. (<@&${staffRole}>)` + `<@${message.author.id}> messed with the honk, so he got the bonk. (<@&${staffRoleId}>)` ) } } From 1f0bdcb0e3220794c2d6fc0ab0ab79d75d51d0bc Mon Sep 17 00:00:00 2001 From: Austin M Date: Fri, 17 Apr 2020 12:00:06 -0700 Subject: [PATCH 6/9] :art: Reset Timer and Dynamic Member & Role Count Reset time on new spam message, as well config defines the max amount of mentioned roles and members --- config.example.ts | 2 ++ src/processes/antiraidListener.ts | 13 +++++++++---- src/types/interfaces/ConfigInterface.ts | 2 ++ src/types/interfaces/UserConfigInterface.ts | 2 ++ src/utils/config/mergeConfig.ts | 2 ++ 5 files changed, 17 insertions(+), 4 deletions(-) diff --git a/config.example.ts b/config.example.ts index 4866cdc..566343a 100644 --- a/config.example.ts +++ b/config.example.ts @@ -9,6 +9,8 @@ export default { dbFile: '', autoBan: true, autoBanThreshold: 3, + antiRaidMembers: 2, + antiRaidRoles: 2, repTriggers: [], repEmote: '', activities: ['Serving NaN users!'], diff --git a/src/processes/antiraidListener.ts b/src/processes/antiraidListener.ts index 25b93a8..bb9002e 100644 --- a/src/processes/antiraidListener.ts +++ b/src/processes/antiraidListener.ts @@ -23,6 +23,10 @@ export const antiraidListener: ProcessInterface = { // NOTE: Get role from config const seniorRoleId = config.roleIDs.senior + const maxMentionedRoles = config.antiRaidRoles + const maxMentionedMemebers = config.antiRaidMembers + const maxMentionedEverything = maxMentionedRoles + maxMentionedMemebers + // DEBUG: Debug console log for role comparison // console.log(staffRole, seniorRole) @@ -44,9 +48,9 @@ export const antiraidListener: ProcessInterface = { } = message.mentions if ( - mentionedRoles > 1 || - mentionedUsers > 2 || - mentionedUsers + mentionedRoles > 2 + mentionedRoles > maxMentionedRoles || + mentionedUsers > maxMentionedMemebers || + mentionedUsers + mentionedRoles > maxMentionedEverything ) { lastKnownTimestamp ? checkOffender(message, lastKnownTimestamp) @@ -71,7 +75,8 @@ export const antiraidListener: ProcessInterface = { const triggerAntiraid = async message => { await message.delete() message.member.roles.add(mutedRole) - // NOTE: This worked in development, should work in production + addOffenderToList(message) + // TODO: Send message to #mod-log message.channel.send( `<@${message.author.id}> messed with the honk, so he got the bonk. (<@&${staffRoleId}>)` diff --git a/src/types/interfaces/ConfigInterface.ts b/src/types/interfaces/ConfigInterface.ts index ae8312f..8eb10a5 100644 --- a/src/types/interfaces/ConfigInterface.ts +++ b/src/types/interfaces/ConfigInterface.ts @@ -27,6 +27,8 @@ export interface ConfigInterface { dbFile: string autoBan: boolean autoBanThreshold: number + antiRaidMembers: number + antiRaidRoles: number repTriggers: string[] repEmote: string activities: string[] diff --git a/src/types/interfaces/UserConfigInterface.ts b/src/types/interfaces/UserConfigInterface.ts index a2b768f..4cdd369 100644 --- a/src/types/interfaces/UserConfigInterface.ts +++ b/src/types/interfaces/UserConfigInterface.ts @@ -18,6 +18,8 @@ export interface UserConfigInterface { dbFile?: string autoBan?: boolean autoBanThreshold?: number + antiRaidMembers?: number + antiRaidRoles?: number repTriggers?: string[] repEmote?: string activities?: string[] diff --git a/src/utils/config/mergeConfig.ts b/src/utils/config/mergeConfig.ts index 03d794b..0430027 100644 --- a/src/utils/config/mergeConfig.ts +++ b/src/utils/config/mergeConfig.ts @@ -20,6 +20,8 @@ export const mergeConfigs = (config: UserConfigInterface): ConfigInterface => { dbFile: config.dbFile || join(__dirname, '..', '..', '..', 'devmod.db'), // Absolute path for the database file. autoBan: config.autoBan || true, // Whether or not to enforce auto-banning after a specified number of warnings. autoBanThreshold: config.autoBanThreshold || 3, // Amount of warnings to warrant an auto-ban if enabled. + antiRaidMembers: config.antiRaidMembers || 1, // Amount of members that are allowed to be pinged in a message + antiRaidRoles: config.antiRaidRoles || 2, // Amount of roles that are allowed to be pinged in a message repTriggers: config.repTriggers || ['thanks', 'kudos'], // List of triggers for thanking users. repEmote: config.repEmote || '👍', // The emoji to prefix the thanks received message with. activities: config.activities || ['Serving NaN users!'], // List of activities for the bot to show as a status. From d94318cfab0268dac595dbfea0e39536845f2c64 Mon Sep 17 00:00:00 2001 From: Austin Date: Fri, 17 Apr 2020 12:08:41 -0700 Subject: [PATCH 7/9] Update src/processes/antiraidListener.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: wellá --- src/processes/antiraidListener.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/processes/antiraidListener.ts b/src/processes/antiraidListener.ts index bb9002e..2023a05 100644 --- a/src/processes/antiraidListener.ts +++ b/src/processes/antiraidListener.ts @@ -18,7 +18,6 @@ export const antiraidListener: ProcessInterface = { // NOTE: Pull from config, same role is achieved const staffRoleId = config.roleIDs.staff - // const staffRole = 662405675107876864 // NOTE: Get role from config const seniorRoleId = config.roleIDs.senior From c464babf867d130535b485ab0c804343154348b0 Mon Sep 17 00:00:00 2001 From: Austin Date: Fri, 17 Apr 2020 12:08:49 -0700 Subject: [PATCH 8/9] Update config.example.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: wellá --- config.example.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.example.ts b/config.example.ts index 566343a..a64e31f 100644 --- a/config.example.ts +++ b/config.example.ts @@ -9,7 +9,7 @@ export default { dbFile: '', autoBan: true, autoBanThreshold: 3, - antiRaidMembers: 2, + antiRaidMembers: 3, antiRaidRoles: 2, repTriggers: [], repEmote: '', From f64fff188000663779654e4dc51f981302b3bfeb Mon Sep 17 00:00:00 2001 From: Austin M Date: Fri, 17 Apr 2020 13:01:25 -0700 Subject: [PATCH 9/9] :art: Removed comment Removed old comment --- src/processes/antiraidListener.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/processes/antiraidListener.ts b/src/processes/antiraidListener.ts index 2023a05..ecc33e1 100644 --- a/src/processes/antiraidListener.ts +++ b/src/processes/antiraidListener.ts @@ -34,7 +34,6 @@ export const antiraidListener: ProcessInterface = { const userRoleIds = message.member.roles.cache.map(r => r.id) - // Staff role is not used as of now const isStaff = userRoleIds.find(r => r === staffRoleId) const isSenior = userRoleIds.find(r => r === seniorRoleId)