Skip to content
This repository was archived by the owner on Oct 15, 2020. It is now read-only.
Merged
2 changes: 2 additions & 0 deletions 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 Down
58 changes: 38 additions & 20 deletions src/processes/antiraidListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Comment thread
austinmccalley marked this conversation as resolved.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No else! return -> end of function

const {
users: { size: mentionedUsers },
roles: { size: mentionedRoles }
} = message.mentions

if (
mentionedRoles > maxMentionedRoles ||
mentionedUsers > maxMentionedMemebers ||
mentionedUsers + mentionedRoles > maxMentionedEverything
) {
lastKnownTimestamp

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specific comparison like === null

? checkOffender(message, lastKnownTimestamp)
: addOffenderToList(message)
}
}
})

Expand All @@ -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}>)`
)
}
}
Expand Down
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/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
2 changes: 2 additions & 0 deletions 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 Down