Skip to content

✨add antiRaid #23

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 37 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
afde924
Added logErrorToChannel check
AndresSweeneyRios Mar 30, 2020
2e41b28
Merge branch 'master' of https://github.com/redxtech/devmod-core
AndresSweeneyRios Mar 30, 2020
0225287
Added optional usage property to CommandInterface
AndresSweeneyRios Mar 30, 2020
50ec2a0
Merge branch 'master' of https://github.com/Andr3wRiv3rs/devmod-core;…
AndresSweeneyRios Mar 30, 2020
d100260
Merge branch 'master' of https://github.com/redxtech/devmod-core
AndresSweeneyRios Mar 30, 2020
b57d360
Added config.ts to .gitignore
AndresSweeneyRios Mar 30, 2020
bb5311d
Fixed null role giving wrong message
AndresSweeneyRios Mar 30, 2020
a6b2483
Imported config
AndresSweeneyRios Mar 30, 2020
19d9dae
Merge from redxtech/devmod-core
AndresSweeneyRios Mar 30, 2020
f343c2e
Missing config check
AndresSweeneyRios Mar 30, 2020
99b4141
Switched config to export default
AndresSweeneyRios Mar 30, 2020
43e0d52
✨add antiRaid
lostdesign Apr 16, 2020
9851c5b
♻️lowers mention threshold, fixes staff pings
lostdesign Apr 16, 2020
0f91c55
:art: Get senior and staff role
Apr 16, 2020
7099c56
:poop: Senior bypass
Apr 16, 2020
0aa52f2
:art: Senior Bypass Anti-Raid
Apr 16, 2020
43b28ae
:twisted_rightwards_arrows: Merge
austinmccalley Apr 16, 2020
b9db873
:art: Staff and Seniors are exempt
austinmccalley Apr 17, 2020
1434bcb
Merge pull request #1 from austinmccalley/anti-raid-senior-staff-fix
austinmccalley Apr 17, 2020
2e0ee95
:art: Updated logic for if statement and var names
austinmccalley Apr 17, 2020
5a55729
:twisted_rightwards_arrows: Merge, forgot to switch branches
austinmccalley Apr 17, 2020
1f0bdcb
:art: Reset Timer and Dynamic Member & Role Count
austinmccalley Apr 17, 2020
d94318c
Update src/processes/antiraidListener.ts
austinmccalley Apr 17, 2020
c464bab
Update config.example.ts
austinmccalley Apr 17, 2020
f64fff1
:art: Removed comment
austinmccalley Apr 17, 2020
6a7a55f
Merge pull request #1 from austinmccalley/master
lostdesign Apr 17, 2020
b92f548
:ambulance: Bot hotfix
austinmccalley Apr 17, 2020
0e4fabf
Merge pull request #2 from austinmccalley/master
lostdesign Apr 17, 2020
3823479
:bug: Spam in DM causes errors
austinmccalley Apr 20, 2020
ebce47c
:recycle: Forgot debug statement
austinmccalley Apr 20, 2020
b331b9d
Merge pull request #3 from austinmccalley/antiraid-fix
lostdesign Apr 20, 2020
7c2667e
Updating anti raid -- removing seniors
redxtech Jul 26, 2020
28fbdfe
Finished anti senior update
austinmccalley Jul 26, 2020
d3ecf78
Merge branch 'master' of https://github.com/redxtech/devmod-core into…
AndresSweeneyRios Aug 17, 2020
89b93a8
Merge branch 'master' of github.com:devcord/devmod-core into config
AndresSweeneyRios Aug 17, 2020
4a1abff
add start command
AndresSweeneyRios Aug 17, 2020
d2d342f
Merge pull request #67 from devcord/Andr3wRiv3rs
AndresSweeneyRios Aug 17, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion config.example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export default <UserConfigInterface>{
dbFile: '',
autoBan: true,
autoBanThreshold: 3,
antiRaidMembers: 3,
antiRaidRoles: 2,
repTriggers: [],
repEmote: '',
activities: ['Serving NaN users!'],
Expand All @@ -24,6 +26,9 @@ export default <UserConfigInterface>{
},
roleIDs: {
muted: '',
verified: ''
verified: '',
staff: '',
senior: '',
mvp: ''
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions src/Devmod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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
]

Expand Down
86 changes: 86 additions & 0 deletions src/processes/antiraidListener.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* 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

// NOTE: Pull from config, same role is achieved
const staffRoleId = config.roleIDs.staff

// NOTE: Get role from config
// Deprecated
// 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) => {
if (message.author.bot || message.channel.type === 'dm') return

const lastKnownTimestamp = mentions.get(message.author.id) ?? null

const userRoleIds = message.member.roles.cache.map(r => r.id)

const isStaff = userRoleIds.find(r => r === staffRoleId)

if (isStaff) {
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)
}
}
})

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)
addOffenderToList(message)

// TODO: Send message to #mod-log
message.channel.send(
`<@${message.author.id}> messed with the honk, so he got the bonk. (<@&${staffRoleId}>)`
)
}
}
}
2 changes: 2 additions & 0 deletions src/types/interfaces/ConfigInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export interface ConfigInterface {
dbFile: string
autoBan: boolean
autoBanThreshold: number
antiRaidMembers: number
antiRaidRoles: number
repTriggers: string[]
repEmote: string
activities: string[]
Expand Down
2 changes: 2 additions & 0 deletions src/types/interfaces/ConfigRolesInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import { Role, RoleResolvable } from 'discord.js'
export interface ConfigRoleInterface {
muted: RoleResolvable
verified: RoleResolvable
staff: RoleResolvable
}

export interface LiveConfigRoleInterface {
muted?: Role
verified?: Role
staff?: Role
}
2 changes: 2 additions & 0 deletions src/types/interfaces/UserConfigInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export interface UserConfigInterface {
dbFile?: string
autoBan?: boolean
autoBanThreshold?: number
antiRaidMembers?: number
antiRaidRoles?: number
repTriggers?: string[]
repEmote?: string
activities?: string[]
Expand Down
5 changes: 4 additions & 1 deletion src/utils/config/mergeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -35,7 +37,8 @@ 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.
}
}
}