@@ -31,12 +31,12 @@ const HEIC_FILE_PATH = 'tmp/img.heic';
31
31
const CONVERTED_IMG_PATH = 'tmp/img.jpg' ;
32
32
33
33
// Variables and constants associated with the counting game
34
- const coinsPerMessage : number = 0.1 ; // Number of coins awarded = coinsPerMessage * highest counting number * messages sent by user
35
- const countingAuthorDelay : number = 1 ; // The minimum number of users that must count for someone to go again
34
+ const coinsPerMessage = 0.1 ; // Number of coins awarded = coinsPerMessage * highest counting number * messages sent by user
35
+ const countingAuthorDelay = 1 ; // The minimum number of users that must count for someone to go again
36
36
const previousCountingAuthors : Array < User > = [ ] ; // Stores the most recent counters
37
37
const authorMessageCounts : Map < User , number > = new Map ( ) ; // Stores how many messages each user sent
38
- const coinAwardNumberThreshold : number = 20 ; // The minimum number that must be reached for coins to be awarded
39
- let currentCountingNumber : number = 1 ;
38
+ const coinAwardNumberThreshold = 20 ; // The minimum number that must be reached for coins to be awarded
39
+ let currentCountingNumber = 1 ;
40
40
41
41
/*
42
42
* If honeypot is to exist again, then add HONEYPOT_CHANNEL_ID to the config
@@ -215,16 +215,16 @@ const countingGameLogic = async (
215
215
client : Client ,
216
216
message : Message ,
217
217
) : Promise < Message < boolean > | undefined > => {
218
-
219
218
// Check to see if game should end
220
219
let reasonForFailure = '' ;
221
- if ( isNaN ( Number ( message . content ) ) ) { // Message was not a number
220
+ if ( isNaN ( Number ( message . content ) ) ) {
221
+ // Message was not a number
222
222
reasonForFailure = `"${ message . content } " is not a number!` ;
223
- }
224
- else if ( previousCountingAuthors . find ( ( author ) => author === message . author ) ) { // Author is still on cooldown
223
+ } else if ( previousCountingAuthors . find ( ( author ) => author === message . author ) ) {
224
+ // Author is still on cooldown
225
225
reasonForFailure = `<@${ message . author . id } > counted too recently!` ;
226
- }
227
- else if ( Number ( message . content ) != currentCountingNumber ) { // Wrong number was sent
226
+ } else if ( Number ( message . content ) != currentCountingNumber ) {
227
+ // Wrong number was sent
228
228
reasonForFailure = `${ message . content } is not the next number! The next number was ${ currentCountingNumber } .` ;
229
229
}
230
230
@@ -243,48 +243,49 @@ const countingGameLogic = async (
243
243
authorMessageCounts . set ( message . author , currentAuthorCount ? currentAuthorCount + 1 : 1 ) ;
244
244
245
245
return ;
246
- }
246
+ } ;
247
247
248
248
const endCountingGame = async (
249
249
client : Client ,
250
250
message : Message ,
251
- reasonForFailure : string
251
+ reasonForFailure : string ,
252
252
) : Promise < Message < boolean > | undefined > => {
253
253
// Builds game over embed
254
254
const endGameEmbed = new EmbedBuilder ( )
255
255
. setColor ( DEFAULT_EMBED_COLOUR )
256
256
. setTitle ( 'Counting Game Over' )
257
257
. addFields ( [
258
- {
259
- name : 'Reason for Game Over' ,
260
- value : reasonForFailure ,
261
- } ,
262
- ] ) ;
258
+ {
259
+ name : 'Reason for Game Over' ,
260
+ value : reasonForFailure ,
261
+ } ,
262
+ ] ) ;
263
263
264
264
if ( currentCountingNumber < coinAwardNumberThreshold ) {
265
- endGameEmbed . setDescription ( `Coins will not be awarded because the threshold, ${ coinAwardNumberThreshold } , was not reached.` ) ;
266
- }
267
- else
268
- {
269
- const sortedAuthorMessageCounts : Array < [ User , number ] > = Array . from ( authorMessageCounts ) . sort ( ( a , b ) => b [ 1 ] - a [ 1 ] ) ; // Turns map into descending sorted array
270
- const coinsAwarded : Array < string > = [ '**Coins awarded:**' ] ;
271
- for ( let pair of sortedAuthorMessageCounts ) {
265
+ endGameEmbed . setDescription (
266
+ `Coins will not be awarded because the threshold, ${ coinAwardNumberThreshold } , was not reached.` ,
267
+ ) ;
268
+ } else {
269
+ const sortedAuthorMessageCounts : Array < [ User , number ] > = Array . from ( authorMessageCounts ) . sort (
270
+ ( a , b ) => b [ 1 ] - a [ 1 ] ,
271
+ ) ; // Turns map into descending sorted array
272
+ const coinsAwarded : Array < string > = [ '**Coins awarded:**' ] ;
273
+ for ( const pair of sortedAuthorMessageCounts ) {
272
274
pair [ 1 ] *= coinsPerMessage * currentCountingNumber ; // Changes number of messages sent to number of coins awarded
273
275
coinsAwarded . push ( `<@${ pair [ 0 ] . id } > - ${ pair [ 1 ] } ${ getCoinEmoji ( ) } ` ) ;
274
276
await adjustCoinBalanceByUserId ( message . author . id , pair [ 1 ] , UserCoinEvent . Counting ) ;
275
277
}
276
-
278
+
277
279
endGameEmbed . setDescription ( coinsAwarded . join ( '\n' ) ) ;
278
280
}
279
281
280
282
currentCountingNumber = 1 ;
281
283
message . react ( '❌' ) ;
282
284
previousCountingAuthors . length = 0 ;
283
285
authorMessageCounts . clear ( ) ;
284
-
285
- return await message . channel ?. send ( { embeds : [ endGameEmbed ] } ) ;
286
- } ;
287
286
287
+ return await message . channel ?. send ( { embeds : [ endGameEmbed ] } ) ;
288
+ } ;
288
289
289
290
export const initMessageCreate = async (
290
291
client : Client ,
0 commit comments