From afde924932eec2dd8350bff4b145f34dd6e9ae37 Mon Sep 17 00:00:00 2001 From: Andr3wRiv3rs Date: Sun, 29 Mar 2020 20:28:17 -0700 Subject: [PATCH 01/24] Added logErrorToChannel check --- src/utils/log.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/utils/log.ts b/src/utils/log.ts index 22f2c0e..4115e30 100644 --- a/src/utils/log.ts +++ b/src/utils/log.ts @@ -29,5 +29,6 @@ export const logErrorToChannel = ( sub: SubmodulesInterface ): Promise => { logError(error) - return config.channels.errors.send(sub.create.errorMessage(error)) + if (config.channels) + return config.channels.errors.send(sub.create.errorMessage(error)) } From 0225287c07f065dd2c68d0cad89f25d99ab4eadb Mon Sep 17 00:00:00 2001 From: Andr3wRiv3rs Date: Sun, 29 Mar 2020 20:58:24 -0700 Subject: [PATCH 02/24] Added optional usage property to CommandInterface --- src/types/interfaces/CommandInterface.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/types/interfaces/CommandInterface.ts b/src/types/interfaces/CommandInterface.ts index c5a8b1d..d390f61 100644 --- a/src/types/interfaces/CommandInterface.ts +++ b/src/types/interfaces/CommandInterface.ts @@ -21,6 +21,7 @@ export interface CommandInterface { category: 'admin' | 'fun' | 'moderation' | 'utils' | 'info' description: string permissions: PermissionResolvable + usage?: string exec: ( message: Message | PartialMessage, args: string[], From b57d36060f551718f1200361d4a9bedb6d16115f Mon Sep 17 00:00:00 2001 From: Andr3wRiv3rs Date: Sun, 29 Mar 2020 21:22:42 -0700 Subject: [PATCH 03/24] Added config.ts to .gitignore --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index ca04740..b6df5e0 100644 --- a/.gitignore +++ b/.gitignore @@ -189,3 +189,7 @@ tmp/ temp/ # End of https://www.gitignore.io/api/node,jetbrains + + +# Devmod config +config.ts \ No newline at end of file From bb5311d2b47c3fcaace1567d7540aa04201ec46e Mon Sep 17 00:00:00 2001 From: Andr3wRiv3rs Date: Sun, 29 Mar 2020 21:35:28 -0700 Subject: [PATCH 04/24] Fixed null role giving wrong message --- src/utils/config/hydrateRoles.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/utils/config/hydrateRoles.ts b/src/utils/config/hydrateRoles.ts index 8e8fef0..3693c4f 100644 --- a/src/utils/config/hydrateRoles.ts +++ b/src/utils/config/hydrateRoles.ts @@ -4,16 +4,25 @@ */ import { Guild } from 'discord.js' -import { ConfigRoleInterface, LiveConfigRoleInterface } from '../../types/interfaces/ConfigRolesInterface' +import { + ConfigRoleInterface, + LiveConfigRoleInterface +} from '../../types/interfaces/ConfigRolesInterface' import { NullRoleError } from '../../types/errors/NullRoleError' -export const hydrateRoles = (guild: Guild, roles: ConfigRoleInterface): LiveConfigRoleInterface => { +export const hydrateRoles = ( + guild: Guild, + roles: ConfigRoleInterface +): LiveConfigRoleInterface => { const hydrated: LiveConfigRoleInterface = {} for (const role of Object.keys(roles)) { hydrated[role] = guild.roles.resolve(roles[role]) if (hydrated[role] == null) { - throw new NullRoleError('Hydration', `A channel is null (${role}:${roles[role]})`) + throw new NullRoleError( + 'Hydration', + `A role is null (${role}:${roles[role]})` + ) } } From a6b2483ac78f8b8c394d03bf22caa8f37a31e7f6 Mon Sep 17 00:00:00 2001 From: Andr3wRiv3rs Date: Sun, 29 Mar 2020 21:38:57 -0700 Subject: [PATCH 05/24] Imported config --- src/main.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main.ts b/src/main.ts index 755b5e1..aab372a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -6,13 +6,11 @@ import { Devmod } from './Devmod' import { config } from 'dotenv' import { UserConfigInterface } from './types/interfaces/UserConfigInterface' +import { config as userConfig } from '../config' config() const main = () => { - // TODO: pull config from the config file (in the root folder) - const userConfig = {} - const bot = new Devmod(userConfig as UserConfigInterface) } From f343c2ee5558d64279248739ac47b3cd0dae61bf Mon Sep 17 00:00:00 2001 From: Andr3wRiv3rs Date: Sun, 29 Mar 2020 22:08:35 -0700 Subject: [PATCH 06/24] Missing config check --- src/main.ts | 13 +++++++++++-- src/types/errors/MissingConfigError.ts | 8 ++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 src/types/errors/MissingConfigError.ts diff --git a/src/main.ts b/src/main.ts index aab372a..74503b8 100644 --- a/src/main.ts +++ b/src/main.ts @@ -6,12 +6,21 @@ import { Devmod } from './Devmod' import { config } from 'dotenv' import { UserConfigInterface } from './types/interfaces/UserConfigInterface' -import { config as userConfig } from '../config' +import { logError } from './utils/log' +import { MissingConfigError } from './types/errors/MissingConfigError' config() const main = () => { - const bot = new Devmod(userConfig as UserConfigInterface) + let userConfig + + try { + userConfig = require('../config').config as UserConfigInterface + } catch { + return logError(new MissingConfigError('Init', 'No config.ts file')) + } + + new Devmod(userConfig) } main() diff --git a/src/types/errors/MissingConfigError.ts b/src/types/errors/MissingConfigError.ts new file mode 100644 index 0000000..d78bc25 --- /dev/null +++ b/src/types/errors/MissingConfigError.ts @@ -0,0 +1,8 @@ +import { DevmodError } from './DevmodError' +import { Message } from 'discord.js' + +export class MissingConfigError extends DevmodError { + constructor(area: string, message: string) { + super('MissingConfigError', area, message, { deleted: true } as Message) + } +} From 99b4141e92f19ad4dfe6b27169d782efc61a1d21 Mon Sep 17 00:00:00 2001 From: Andr3wRiv3rs Date: Sun, 29 Mar 2020 22:10:32 -0700 Subject: [PATCH 07/24] Switched config to export default --- config.example.ts | 2 +- src/main.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config.example.ts b/config.example.ts index 2f82cca..75ccdb3 100644 --- a/config.example.ts +++ b/config.example.ts @@ -1,6 +1,6 @@ import { UserConfigInterface } from './src/types/interfaces/UserConfigInterface' -export const config: UserConfigInterface = { +export default { token: '', guildID: '', prefix: '.', diff --git a/src/main.ts b/src/main.ts index 74503b8..feb3989 100644 --- a/src/main.ts +++ b/src/main.ts @@ -15,7 +15,7 @@ const main = () => { let userConfig try { - userConfig = require('../config').config as UserConfigInterface + userConfig = require('../config').default as UserConfigInterface } catch { return logError(new MissingConfigError('Init', 'No config.ts file')) } From 43e0d52863b735ba92b15d66f9e3764d3ce2f6de Mon Sep 17 00:00:00 2001 From: lostdesign Date: Thu, 16 Apr 2020 10:27:58 +0200 Subject: [PATCH 08/24] =?UTF-8?q?=E2=9C=A8add=20antiRaid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.example.ts | 5 +- src/Devmod.ts | 4 +- src/processes/antiraidListener.ts | 66 ++++++++++++++++++++ src/types/interfaces/ConfigRolesInterface.ts | 4 ++ src/utils/config/mergeConfig.ts | 4 +- 5 files changed, 79 insertions(+), 4 deletions(-) create mode 100644 src/processes/antiraidListener.ts diff --git a/config.example.ts b/config.example.ts index 75ccdb3..4866cdc 100644 --- a/config.example.ts +++ b/config.example.ts @@ -24,6 +24,9 @@ export default { }, roleIDs: { muted: '', - verified: '' + verified: '', + staff: '', + senior: '', + mvp: '' } } diff --git a/src/Devmod.ts b/src/Devmod.ts index de5d9d9..6eb5be1 100644 --- a/src/Devmod.ts +++ b/src/Devmod.ts @@ -16,7 +16,7 @@ import { log } from './utils/log' import { Create } from './utils/submodules/Create' import { Moderation } from './utils/submodules/Moderation' import { Utils } from './utils/submodules/Utils' -import { commandListener } from './processes/commandListener' +import { antiraidListener } from './processes/antiraidListener' import { SubmodulesInterface } from './types/interfaces/SubmodulesInterface' import { DevmodError } from './types/errors/DevmodError' @@ -35,7 +35,7 @@ export class Devmod { // Create a list of processes to be run with the bot const processes: ProcessInterface[] = [ - commandListener + antiraidListener // other listeners to come ] diff --git a/src/processes/antiraidListener.ts b/src/processes/antiraidListener.ts new file mode 100644 index 0000000..9423c4c --- /dev/null +++ b/src/processes/antiraidListener.ts @@ -0,0 +1,66 @@ +/* + * André Weller 2020 + * Process file for the antiraid listener + */ + +import { Client, Message } from 'discord.js' +import { ConfigInterface } from '../types/interfaces/ConfigInterface' +import { ProcessInterface } from '../types/interfaces/ProcessInterface' +import { SubmodulesInterface } from '../types/interfaces/SubmodulesInterface' + +import * as moment from 'moment' + +export const antiraidListener: ProcessInterface = { + name: 'AntiraidListener', + init(client: Client, config: ConfigInterface, sub: SubmodulesInterface) { + 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 + + 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 > 5 || + mentionedUsers + mentionedRoles > 2 + ) { + lastKnownTimestamp + ? checkOffender(message, lastKnownTimestamp) + : addOffenderToList(message) + } + }) + + const addOffenderToList = message => { + mentions.set(message.author.id, [message.createdTimestamp]) + } + + const checkOffender = (message, lastKnownTimestamp) => { + const startDate = moment(message.createdTimestamp * 1000) + const endDate = moment(lastKnownTimestamp * 1000) + + const diff = startDate.diff(endDate) + + diff > 10 ? triggerAntiraid(message) : addOffenderToList(message) + } + + const triggerAntiraid = async message => { + await message.delete() + message.member.roles.add(mutedRole) + message.channel.send( + `<@${message.author.id}> messed with the honk, so he got the bonk. (<@${staffRole}>)` + ) + } + } +} diff --git a/src/types/interfaces/ConfigRolesInterface.ts b/src/types/interfaces/ConfigRolesInterface.ts index f54fce7..64225fb 100644 --- a/src/types/interfaces/ConfigRolesInterface.ts +++ b/src/types/interfaces/ConfigRolesInterface.ts @@ -8,9 +8,13 @@ import { Role, RoleResolvable } from 'discord.js' export interface ConfigRoleInterface { muted: RoleResolvable verified: RoleResolvable + staff: RoleResolvable + senior: RoleResolvable } export interface LiveConfigRoleInterface { muted?: Role verified?: Role + staff?: Role + senior?: Role } diff --git a/src/utils/config/mergeConfig.ts b/src/utils/config/mergeConfig.ts index 3d2f4d4..03d794b 100644 --- a/src/utils/config/mergeConfig.ts +++ b/src/utils/config/mergeConfig.ts @@ -35,7 +35,9 @@ export const mergeConfigs = (config: UserConfigInterface): ConfigInterface => { }, roleIDs: { muted: config.roleIDs.muted, // ID of the role to apply to muted users. - verified: config.roleIDs.verified // ID of the role to apply to verified users. + verified: config.roleIDs.verified, // ID of the role to apply to verified users. + staff: config.roleIDs.staff, // ID of the role for staff on the server. + senior: config.roleIDs.senior //ID of the role for senior members of the server } } } From 9851c5b3b07444bd80a5996225ddbeb000388fc5 Mon Sep 17 00:00:00 2001 From: lostdesign Date: Thu, 16 Apr 2020 11:19:24 +0200 Subject: [PATCH 09/24] =?UTF-8?q?=E2=99=BB=EF=B8=8Flowers=20mention=20thre?= =?UTF-8?q?shold,=20fixes=20staff=20pings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/processes/antiraidListener.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/processes/antiraidListener.ts b/src/processes/antiraidListener.ts index 9423c4c..b974a12 100644 --- a/src/processes/antiraidListener.ts +++ b/src/processes/antiraidListener.ts @@ -33,7 +33,7 @@ export const antiraidListener: ProcessInterface = { if ( mentionedRoles > 1 || - mentionedUsers > 5 || + mentionedUsers > 2 || mentionedUsers + mentionedRoles > 2 ) { lastKnownTimestamp @@ -59,7 +59,7 @@ export const antiraidListener: ProcessInterface = { await message.delete() message.member.roles.add(mutedRole) 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. (<@&${staffRole}>)` ) } } From 0f91c55462606ef2337cb196698dcae39745c3b5 Mon Sep 17 00:00:00 2001 From: Austin M Date: Thu, 16 Apr 2020 12:22:00 -0700 Subject: [PATCH 10/24] :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 11/24] :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 12/24] :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 13/24] :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 14/24] :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 15/24] :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 16/24] 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 17/24] 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 18/24] :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) From b92f548956b3a318b35b4593808a91eb54b458d8 Mon Sep 17 00:00:00 2001 From: Austin M Date: Fri, 17 Apr 2020 13:35:37 -0700 Subject: [PATCH 19/24] :ambulance: Bot hotfix Bot hotfix --- src/processes/antiraidListener.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/processes/antiraidListener.ts b/src/processes/antiraidListener.ts index ecc33e1..9165cf4 100644 --- a/src/processes/antiraidListener.ts +++ b/src/processes/antiraidListener.ts @@ -30,6 +30,7 @@ export const antiraidListener: ProcessInterface = { // console.log(staffRole, seniorRole) client.on('message', async (message: Message) => { + if (message.author.bot) return const lastKnownTimestamp = mentions.get(message.author.id) ?? null const userRoleIds = message.member.roles.cache.map(r => r.id) From 38234798921bfc4628bc7ff727ea335e2ded061c Mon Sep 17 00:00:00 2001 From: Austin M Date: Mon, 20 Apr 2020 13:33:26 -0700 Subject: [PATCH 20/24] :bug: Spam in DM causes errors Spam in DM's causes errors and could crash bot --- src/processes/antiraidListener.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/processes/antiraidListener.ts b/src/processes/antiraidListener.ts index 9165cf4..d352b35 100644 --- a/src/processes/antiraidListener.ts +++ b/src/processes/antiraidListener.ts @@ -30,7 +30,10 @@ export const antiraidListener: ProcessInterface = { // console.log(staffRole, seniorRole) client.on('message', async (message: Message) => { - if (message.author.bot) return + if (message.author.bot || message.channel.type === 'dm') return + console.log(message.channel.type) + console.log('HERE') + const lastKnownTimestamp = mentions.get(message.author.id) ?? null const userRoleIds = message.member.roles.cache.map(r => r.id) From ebce47c08e88bfa503dfa79c3aab288344cb19a2 Mon Sep 17 00:00:00 2001 From: Austin M Date: Mon, 20 Apr 2020 13:35:16 -0700 Subject: [PATCH 21/24] :recycle: Forgot debug statement Forgot to takeout debug statement --- src/processes/antiraidListener.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/processes/antiraidListener.ts b/src/processes/antiraidListener.ts index d352b35..f919620 100644 --- a/src/processes/antiraidListener.ts +++ b/src/processes/antiraidListener.ts @@ -31,8 +31,6 @@ export const antiraidListener: ProcessInterface = { client.on('message', async (message: Message) => { if (message.author.bot || message.channel.type === 'dm') return - console.log(message.channel.type) - console.log('HERE') const lastKnownTimestamp = mentions.get(message.author.id) ?? null From 7c2667e47b9721e2875f9c93a05ea34c9bcecd0f Mon Sep 17 00:00:00 2001 From: Gabe Dunn Date: Mon, 27 Jul 2020 00:02:38 +0200 Subject: [PATCH 22/24] Updating anti raid -- removing seniors --- src/processes/antiraidListener.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/processes/antiraidListener.ts b/src/processes/antiraidListener.ts index f919620..aaa2940 100644 --- a/src/processes/antiraidListener.ts +++ b/src/processes/antiraidListener.ts @@ -20,7 +20,8 @@ export const antiraidListener: ProcessInterface = { const staffRoleId = config.roleIDs.staff // NOTE: Get role from config - const seniorRoleId = config.roleIDs.senior + // Deprecated + // const seniorRoleId = config.roleIDs.senior const maxMentionedRoles = config.antiRaidRoles const maxMentionedMemebers = config.antiRaidMembers @@ -37,9 +38,8 @@ export const antiraidListener: ProcessInterface = { 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) { + if (isStaff) { return } else { const { From 28fbdfe1340dd7dce15cc855bafd4c3112c48710 Mon Sep 17 00:00:00 2001 From: Austin McCalley Date: Sun, 26 Jul 2020 15:10:26 -0700 Subject: [PATCH 23/24] Finished anti senior update --- src/types/interfaces/ConfigRolesInterface.ts | 2 -- src/utils/config/mergeConfig.ts | 3 +-- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/types/interfaces/ConfigRolesInterface.ts b/src/types/interfaces/ConfigRolesInterface.ts index 64225fb..dfee6ce 100644 --- a/src/types/interfaces/ConfigRolesInterface.ts +++ b/src/types/interfaces/ConfigRolesInterface.ts @@ -9,12 +9,10 @@ export interface ConfigRoleInterface { muted: RoleResolvable verified: RoleResolvable staff: RoleResolvable - senior: RoleResolvable } export interface LiveConfigRoleInterface { muted?: Role verified?: Role staff?: Role - senior?: Role } diff --git a/src/utils/config/mergeConfig.ts b/src/utils/config/mergeConfig.ts index 0430027..d0dd82a 100644 --- a/src/utils/config/mergeConfig.ts +++ b/src/utils/config/mergeConfig.ts @@ -38,8 +38,7 @@ export const mergeConfigs = (config: UserConfigInterface): ConfigInterface => { roleIDs: { muted: config.roleIDs.muted, // ID of the role to apply to muted users. verified: config.roleIDs.verified, // ID of the role to apply to verified users. - staff: config.roleIDs.staff, // ID of the role for staff on the server. - senior: config.roleIDs.senior //ID of the role for senior members of the server + staff: config.roleIDs.staff // ID of the role for staff on the server. } } } From 4a1abffd62faf999394f8cac43697b25885aebf6 Mon Sep 17 00:00:00 2001 From: Andr3wRiv3rs Date: Mon, 17 Aug 2020 12:22:05 -0700 Subject: [PATCH 24/24] add start command --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index b55502d..156fdc8 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "license": "MIT", "private": false, "scripts": { + "start": "ts-node ./src/main.ts --strict", "dev": "nodemon --exec ts-node ./src/main.ts --strict", "lint": "prettier --check ./src", "lint:fix": "prettier --write ./src"