-
Notifications
You must be signed in to change notification settings - Fork 59
/
index.ts
35 lines (32 loc) · 1.15 KB
/
index.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
import { Events } from 'discord.js'
import { definePlugin } from '@/types/definePlugin'
import isOnlyEmoji from '@/utils/isOnlyEmoji'
import { isEmojiPreventionEnabled } from './isEmojiPreventionEnabled'
export default definePlugin({
name: 'preventEmojiSpam',
setup: (pluginContext) => {
pluginContext.addEventHandler({
eventName: Events.MessageCreate,
once: false,
execute: async (botContext, message) => {
const { runtimeConfiguration, log } = botContext
const config = runtimeConfiguration.data.preventEmojiSpam
// if has only emoji -> delete message
if (isOnlyEmoji(message.content) && message.member) {
try {
const { id, channel, member } = message
const enabled = isEmojiPreventionEnabled(config, channel, member)
log.info(
`channel=${channel.id} message=${id} author=${member.id} (${member.user.tag}) enabled=${enabled}`,
)
if (enabled) {
await message.delete()
}
} catch (error) {
log.error('Unable to process message', error)
}
}
},
})
},
})