@@ -17,7 +17,7 @@ import {
1717 WebhookClient ,
1818 time ,
1919} from 'discord.js' ;
20- import { sortReactions } from '../utils/Utils.js' ;
20+ import { getEmojiId , sortReactions } from '../utils/Utils.js' ;
2121import { HubSettingsBitField } from '../utils/BitFields.js' ;
2222import BlacklistManager from '../managers/BlacklistManager.js' ;
2323import { CustomID } from '../utils/CustomID.js' ;
@@ -67,7 +67,7 @@ export default class ReactionUpdater extends Factory {
6767 if ( userBlacklisted || serverBlacklisted ) return ;
6868
6969 const reactedEmoji = reaction . emoji . toString ( ) ;
70- const dbReactions = originalMsg . reactions ?. valueOf ( ) as { [ key : string ] : string [ ] } ; // eg. { '👍': 1, '👎': 2 }
70+ const dbReactions = ( originalMsg . reactions ?. valueOf ( ) ?? { } ) as { [ key : string ] : string [ ] } ; // eg. { '👍': 1, '👎': 2 }
7171 const emojiAlreadyReacted = dbReactions [ reactedEmoji ] ?? [ user . id ] ;
7272
7373 // max 10 reactions
@@ -128,7 +128,7 @@ export default class ReactionUpdater extends Factory {
128128 // add user to cooldown list
129129 interaction . client . reactionCooldowns . set ( interaction . user . id , Date . now ( ) + 3000 ) ;
130130
131- const dbReactions = messageInDb . originalMsg . reactions ?. valueOf ( ) as {
131+ const dbReactions = ( messageInDb . originalMsg . reactions ?. valueOf ( ) ?? { } ) as {
132132 [ key : string ] : Snowflake [ ] ;
133133 } ;
134134
@@ -169,7 +169,7 @@ export default class ReactionUpdater extends Factory {
169169 reactionMenu . components [ 0 ] . addOptions ( {
170170 label : 'React/Unreact' ,
171171 value : r [ 0 ] ,
172- emoji : r [ 0 ] ,
172+ emoji : getEmojiId ( r [ 0 ] ) ,
173173 } ) ;
174174 totalReactions ++ ;
175175 reactionString += `- ${ r [ 0 ] } : ${ r [ 1 ] . length } \n` ;
@@ -287,13 +287,17 @@ export default class ReactionUpdater extends Factory {
287287 // sortedReactions[x] = emojiIds
288288 // sortedReactions[x][y] = arr of users
289289 const sortedReactions = sortReactions ( reactions ) ;
290+ console . log ( getEmojiId ( sortedReactions [ 0 ] [ 0 ] ) ) ;
290291 const reactionCount = sortedReactions [ 0 ] [ 1 ] . length ;
291292 const mostReaction = sortedReactions [ 0 ] [ 0 ] ;
293+ const mostReactionEmoji = getEmojiId ( mostReaction ) ;
294+
295+ if ( ! mostReactionEmoji ) return ;
292296
293297 const reactionBtn = new ActionRowBuilder < ButtonBuilder > ( ) . addComponents (
294298 new ButtonBuilder ( )
295299 . setCustomId ( new CustomID ( ) . setIdentifier ( 'reaction_' , mostReaction ) . toString ( ) )
296- . setEmoji ( mostReaction )
300+ . setEmoji ( mostReactionEmoji )
297301 . setStyle ( ButtonStyle . Secondary )
298302 . setLabel ( `${ reactionCount } ` ) ,
299303 ) ;
@@ -390,6 +394,11 @@ export default class ReactionUpdater extends Factory {
390394 userId : string ,
391395 emoji : string ,
392396 ) {
397+ // if (reactionArr[emoji].length <= 1) {
398+ // delete reactionArr[emoji];
399+ // return;
400+ // }
401+
393402 const userIndex = reactionArr [ emoji ] . indexOf ( userId ) ;
394403 reactionArr [ emoji ] . splice ( userIndex , 1 ) ;
395404 return reactionArr ;
0 commit comments