-
Notifications
You must be signed in to change notification settings - Fork 59
/
checkName.ts
46 lines (39 loc) · 1.3 KB
/
checkName.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { GuildMember } from 'discord.js'
import { Environment } from '@/config'
import { BotContext } from '@/types/BotContext'
import { checkNameAgainstPatterns } from './checkNameAgainstPatterns'
export const compiled = new Map<string, RegExp>()
const seen = new Map<string, number>()
export async function checkName(member: GuildMember, botContext: BotContext) {
const { log, runtimeConfiguration } = botContext
const config = runtimeConfiguration.data.nameChecker
if (member.guild.id !== Environment.GUILD_ID) return
const { reportChannelId, patterns } = config
if (!patterns) {
return
}
const reportChannel = member.guild.channels.cache.get(reportChannelId)
if (!reportChannel) {
log.error('Unable to check name because report channel is missing')
return
}
if (!reportChannel.isTextBased()) {
log.error('Unable to check name because report channel is not text based')
return
}
const checkResult = checkNameAgainstPatterns(
member.displayName,
patterns,
log,
)
if (checkResult) {
const isNew = !seen.has(member.id)
seen.set(member.id, Date.now())
if (isNew) {
log.info(
`Name pattern match ${checkResult}: "${member.displayName}" (${member.id})`,
)
await reportChannel?.send(`Name pattern match: ${member}`)
}
}
}