@@ -6,6 +6,7 @@ import { Events } from "@framework/types/ClientEvents";
6
6
import { fetchMember , fetchUser } from "@framework/utils/entities" ;
7
7
import { Colors } from "@main/constants/Colors" ;
8
8
import { env } from "@main/env/env" ;
9
+ import VerificationExpiredQueue from "@main/queues/VerificationExpiredQueue" ;
9
10
import type ConfigurationManager from "@main/services/ConfigurationManager" ;
10
11
import type ModerationActionService from "@main/services/ModerationActionService" ;
11
12
import { VerificationEntry , VerificationMethod } from "@prisma/client" ;
@@ -64,6 +65,8 @@ class VerificationService extends Service {
64
65
guildId : member . guild . id
65
66
}
66
67
} ) ;
68
+
69
+ await this . clearVerificationQueues ( member . guild . id , member . id ) ;
67
70
}
68
71
69
72
public async startVerification ( member : GuildMember , reason ?: string ) {
@@ -99,9 +102,29 @@ class VerificationService extends Service {
99
102
}
100
103
} ) ;
101
104
105
+ await this . application
106
+ . service ( "queueService" )
107
+ . create ( VerificationExpiredQueue , {
108
+ data : {
109
+ guildId : member . guild . id ,
110
+ memberId : member . id
111
+ } ,
112
+ guildId : member . guild . id ,
113
+ runsAt : entry . expiresAt
114
+ } )
115
+ . schedule ( ) ;
116
+
102
117
await this . sendVerificationMessage ( member , entry . code ) . catch ( this . application . logger . error ) ;
103
118
}
104
119
120
+ private async clearVerificationQueues ( guildId : Snowflake , userId : Snowflake ) {
121
+ await this . application
122
+ . service ( "queueService" )
123
+ . bulkCancel ( VerificationExpiredQueue , queue => {
124
+ return queue . data . guildId === guildId && queue . data . memberId === userId ;
125
+ } ) ;
126
+ }
127
+
105
128
private async sendVerificationMessage ( member : GuildMember , code : string ) {
106
129
const config = this . configFor ( member . guild . id ) ;
107
130
@@ -139,6 +162,32 @@ class VerificationService extends Service {
139
162
} ) ;
140
163
}
141
164
165
+ public async onVerificationExpire ( guildId : Snowflake , userId : Snowflake ) {
166
+ const { count } = await this . application . prisma . verificationEntry . deleteMany ( {
167
+ where : {
168
+ userId,
169
+ guildId
170
+ }
171
+ } ) ;
172
+
173
+ if ( count === 0 ) {
174
+ return ;
175
+ }
176
+
177
+ const actions = this . configFor ( guildId ) ?. expired_actions ;
178
+ const guild = this . application . client . guilds . cache . get ( guildId ) ;
179
+
180
+ if ( actions ?. length && guild ) {
181
+ const memberOrUser =
182
+ ( await fetchMember ( guild , userId ) ) ??
183
+ ( await fetchUser ( this . application . client , userId ) ) ;
184
+
185
+ if ( memberOrUser ) {
186
+ await this . moderationActionService . takeActions ( guild , memberOrUser , actions ) ;
187
+ }
188
+ }
189
+ }
190
+
142
191
public async getVerificationEntry ( code : string ) {
143
192
const entry = await this . application . prisma . verificationEntry . findUnique ( {
144
193
where : {
@@ -151,25 +200,8 @@ class VerificationService extends Service {
151
200
}
152
201
153
202
if ( entry . expiresAt . getTime ( ) < Date . now ( ) ) {
154
- await this . application . prisma . verificationEntry . delete ( {
155
- where : {
156
- id : entry . id
157
- }
158
- } ) ;
159
-
160
- const actions = this . configFor ( entry . guildId ) ?. expired_actions ;
161
- const guild = this . application . client . guilds . cache . get ( entry . guildId ) ;
162
-
163
- if ( actions ?. length && guild ) {
164
- const memberOrUser =
165
- ( await fetchMember ( guild , entry . userId ) ) ??
166
- ( await fetchUser ( this . application . client , entry . userId ) ) ;
167
-
168
- if ( memberOrUser ) {
169
- await this . moderationActionService . takeActions ( guild , memberOrUser , actions ) ;
170
- }
171
- }
172
-
203
+ await this . onVerificationExpire ( entry . guildId , entry . userId ) ;
204
+ await this . clearVerificationQueues ( entry . guildId , entry . userId ) ;
173
205
return null ;
174
206
}
175
207
@@ -262,6 +294,7 @@ class VerificationService extends Service {
262
294
}
263
295
} ) ;
264
296
297
+ await this . clearVerificationQueues ( entry . guildId , entry . userId ) ;
265
298
await member
266
299
. send ( {
267
300
embeds : [
0 commit comments