diff --git a/config.example.ts b/config.example.ts index 4866cdc..a64e31f 100644 --- a/config.example.ts +++ b/config.example.ts @@ -9,6 +9,8 @@ export default { dbFile: '', autoBan: true, autoBanThreshold: 3, + antiRaidMembers: 3, + antiRaidRoles: 2, repTriggers: [], repEmote: '', activities: ['Serving NaN users!'], diff --git a/src/processes/antiraidListener.ts b/src/processes/antiraidListener.ts index b974a12..ecc33e1 100644 --- a/src/processes/antiraidListener.ts +++ b/src/processes/antiraidListener.ts @@ -16,29 +16,44 @@ export const antiraidListener: ProcessInterface = { const mentions = new Map() 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 staffRoleId = config.roleIDs.staff + + // 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) client.on('message', async (message: Message) => { const lastKnownTimestamp = mentions.get(message.author.id) ?? null - // TODO: escape check if user is senior - //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 userRoleIds = message.member.roles.cache.map(r => r.id) + + 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 > maxMentionedRoles || + mentionedUsers > maxMentionedMemebers || + mentionedUsers + mentionedRoles > maxMentionedEverything + ) { + lastKnownTimestamp + ? checkOffender(message, lastKnownTimestamp) + : addOffenderToList(message) + } } }) @@ -58,8 +73,11 @@ export const antiraidListener: ProcessInterface = { const triggerAntiraid = async message => { await message.delete() message.member.roles.add(mutedRole) + addOffenderToList(message) + + // 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}>)` ) } } 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.