1
- import { ApplyOptions } from '@sapphire/decorators' ;
2
- import { container , Listener } from '@sapphire/framework' ;
3
- import { Message } from 'discord.js' ;
1
+ import { ILogger } from '@sapphire/framework' ;
2
+ import { Client , Message } from 'discord.js' ;
4
3
import { applyBonusByUserId } from '../components/coin' ;
5
4
import { vars } from '../config' ;
6
5
import { sendKickEmbed } from '../utils/embeds' ;
@@ -43,8 +42,7 @@ const detectSpammersAndTrolls = (message: Message): boolean => {
43
42
* Punish spammers/trolls/people who got hacked
44
43
* Return true if someone of this kind is detected, false otherwise
45
44
*/
46
- const punishSpammersAndTrolls = async ( message : Message ) : Promise < boolean > => {
47
- const { logger } = container ;
45
+ const punishSpammersAndTrolls = async ( client : Client , logger : ILogger , message : Message ) : Promise < boolean > => {
48
46
if ( detectSpammersAndTrolls ( message ) ) {
49
47
// Delete the message, and if the user is still in the server, then kick them and log it
50
48
await message . delete ( ) ;
@@ -61,7 +59,7 @@ const punishSpammersAndTrolls = async (message: Message): Promise<boolean> => {
61
59
error : ( err as Error ) . toString ( )
62
60
} ) ;
63
61
}
64
- await sendKickEmbed ( message , user , reason , isSuccessful ) ;
62
+ await sendKickEmbed ( client , message , user , reason , isSuccessful ) ;
65
63
}
66
64
return true ;
67
65
}
@@ -97,34 +95,23 @@ const convertResumePdfsIntoImages = async (message: Message): Promise<Message<bo
97
95
} ) ;
98
96
} ;
99
97
100
- @ApplyOptions < Listener . Options > ( {
101
- event : 'messageCreate'
102
- } )
103
- export class MessageCreateListener extends Listener {
104
- async run ( message : Message ) : Promise < void > {
105
- const { client } = container ;
106
-
107
- if ( ! client . user ) {
108
- return ;
109
- }
110
-
111
- // Ignore all bots including self but not IRC
112
- if ( message . author . bot && message . author . id !== IRC_USER_ID ) {
113
- return ;
114
- }
98
+ export const initMessageCreate = async ( client : Client , logger : ILogger , message : Message ) : Promise < void > => {
99
+ // Ignore all bots including self but not IRC
100
+ if ( message . author . bot && message . author . id !== IRC_USER_ID ) {
101
+ return ;
102
+ }
115
103
116
- if ( await punishSpammersAndTrolls ( message ) ) {
117
- return ;
118
- }
104
+ if ( await punishSpammersAndTrolls ( client , logger , message ) ) {
105
+ return ;
106
+ }
119
107
120
- // If channel is in resumes, convert the message attachment to an image
121
- if ( message . channelId === RESUME_CHANNEL_ID ) {
122
- await convertResumePdfsIntoImages ( message ) ;
123
- }
108
+ // If channel is in resumes, convert the message attachment to an image
109
+ if ( message . channelId === RESUME_CHANNEL_ID ) {
110
+ await convertResumePdfsIntoImages ( message ) ;
111
+ }
124
112
125
- // Ignore DMs; include announcements, thread, and regular text channels
126
- if ( message . channel . type !== 'DM' ) {
127
- await applyBonusByUserId ( message . author . id ) ;
128
- }
113
+ // Ignore DMs; include announcements, thread, and regular text channels
114
+ if ( message . channel . type !== 'DM' ) {
115
+ await applyBonusByUserId ( message . author . id ) ;
129
116
}
130
- }
117
+ } ;
0 commit comments