44 type EmojiIdentifierResolvable ,
55 InteractionType ,
66 type Message ,
7- type MessageInteraction ,
7+ type MessageInteractionMetadata ,
88 type PartialTextBasedChannelFields ,
99} from "discord.js" ;
1010import { config } from "../../Config.js" ;
@@ -16,6 +16,7 @@ import {
1616 getAllBumps ,
1717 getBumpStreak ,
1818 getStreaks ,
19+ type Streak ,
1920} from "../../store/models/bumps.js" ;
2021import { type DDUser , getOrCreateUserById } from "../../store/models/DDUser.js" ;
2122import { fakeMention , mentionIfPingable } from "../../util/users.js" ;
@@ -42,10 +43,9 @@ export function setLastBumpNotificationTime(date: Date) {
4243 lastBumpNotificationTime = date ;
4344}
4445
45- // noinspection JSDeprecatedSymbols
4646export async function handleBumpStreak (
4747 bumper : DDUser ,
48- interactionOld : MessageInteraction ,
48+ interactionOld : MessageInteractionMetadata ,
4949 message : Message & {
5050 channel : PartialTextBasedChannelFields ;
5151 } ,
@@ -69,15 +69,14 @@ export async function handleBumpStreak(
6969 streak . current === 1 // just started a new streak
7070 ) {
7171 // allStreaks[-1] will be the current streak
72- const mostRecent = allStreaks [ allStreaks . length - 2 ] ; // so check the one before that
72+ const mostRecent = allStreaks . at ( - 2 ) as {
73+ userId : bigint ;
74+ } & Streak ; // so check the one before that
7375 logger . debug ( `Most recent streak:` , mostRecent ) ;
74- logger . debug (
75- "Most recent streaks:" ,
76- allStreaks . slice ( allStreaks . length - 5 ) ,
77- ) ;
76+ logger . debug ( "Most recent streaks:" , allStreaks . slice ( - 5 ) ) ;
7877 if ( mostRecent . userId !== bumper . id && mostRecent . current > 2 ) {
7978 const user = await client . users . fetch ( mostRecent . userId . toString ( ) ) ;
80- message . channel . send (
79+ await message . channel . send (
8180 `☠️ ${ mentionIfPingable ( interactionOld . user ) } ended ${ fakeMention ( user ) } 's bump streak of ${ mostRecent . current } !` ,
8281 ) ;
8382 }
@@ -88,7 +87,7 @@ export async function handleBumpStreak(
8887 const timeSinceLastBump = Date . now ( ) - lastBumpNotificationTime . getTime ( ) ;
8988 if ( timeSinceLastBump < 30000 ) {
9089 // this might seem generous, but in reality when you factor in the discord delay, even if you react instantaneously on your screen you can still be too slow
91- message . channel . send (
90+ await message . channel . send (
9291 `⚡⚡⚡ ${ fakeMention ( interactionOld . user ) } bumped in just **${ timeSinceLastBump / 1000 } s**!` ,
9392 ) ;
9493 } else {
@@ -104,12 +103,14 @@ export async function handleBumpStreak(
104103
105104 if ( streak . current === streak . highest ) {
106105 // new high score!
107- message . channel . send (
106+ await message . channel . send (
108107 `${ mentionIfPingable ( interactionOld . user ) } , you beat your max bump streak and are now on a streak of ${ streak . current } ! Keep it up!` ,
109108 ) ;
110109 }
111110
112- const highestStreakEver = allStreaks . sort ( ( a , b ) => b . highest - a . highest ) [ 0 ] ;
111+ const highestStreakEver = allStreaks . toSorted (
112+ ( a , b ) => b . highest - a . highest ,
113+ ) [ 0 ] ;
113114 logger . debug ( "Highest streak ever: %O" , highestStreakEver ) ;
114115 logger . debug ( "This streak: %O" , streak ) ;
115116 if (
@@ -121,17 +122,16 @@ export async function handleBumpStreak(
121122 ) {
122123 // if they currently have the highest streak
123124 logger . debug ( "User has the highest streak" ) ;
124- message . channel . send (
125+ await message . channel . send (
125126 `🔥🔥🔥🔥🔥 ${ mentionIfPingable ( interactionOld . user ) } , you have the highest EVER bump streak in the server of ${ highestStreakEver . highest } ! Keep it up!` ,
126127 ) ;
127128 }
128129}
129130
130- // noinspection JSDeprecatedSymbols
131131export async function handleBump (
132132 client : Client ,
133133 bumper : DDUser ,
134- interactionOld : MessageInteraction ,
134+ interactionOld : MessageInteractionMetadata ,
135135 message : Message & {
136136 channel : PartialTextBasedChannelFields ;
137137 } ,
@@ -144,37 +144,34 @@ export async function handleBump(
144144}
145145
146146export const BumpListener : EventListener = {
147- ready : async ( client ) => {
147+ clientReady : async ( client ) => {
148148 scheduleBumpReminder ( client ) ;
149149 } ,
150150 messageCreate : async ( client , message ) => {
151151 const interaction = message . interactionMetadata ;
152152
153- if (
154- ! interaction ||
155- ! ( interaction . type === InteractionType . ApplicationCommand )
156- )
153+ if ( ! interaction || interaction . type !== InteractionType . ApplicationCommand )
157154 return ;
158155 if ( message . author . id !== "302050872383242240" ) return ; // /disboard user id
159- // noinspection JSDeprecatedSymbols don't think there's another way of doing this
156+
157+ // noinspection JSDeprecatedSymbols don't think there's another way of doing this ( yes there is )
160158 const interactionOld = message . interaction ;
161159 if ( interactionOld ?. commandName !== "bump" ) return ;
162-
163160 // since the bump failed message is ephemeral, we know if we can see the message then the bump succeeded!
164- const ddUser = await getOrCreateUserById ( BigInt ( interactionOld . user . id ) ) ;
161+ const ddUser = await getOrCreateUserById ( BigInt ( interaction . user . id ) ) ;
165162
166163 // Bump
167164 await Bump . create ( {
168165 messageId : BigInt ( message . id ) ,
169- userId : BigInt ( interactionOld . user . id ) ,
166+ userId : BigInt ( interaction . user . id ) ,
170167 timestamp : new Date ( ) ,
171168 } ) ;
172169 logger . info (
173- `User ${ interactionOld . user . id } bumped! Total bumps: ${ await ddUser . countBumps ( ) } ` ,
170+ `User ${ interaction . user . id } bumped! Total bumps: ${ await ddUser . countBumps ( ) } ` ,
174171 ) ;
175172 clearBumpsCache ( ) ;
176173 await ddUser . save ( ) ;
177- await handleBump ( client , ddUser , interactionOld , message ) ;
174+ await handleBump ( client , ddUser , interaction , message ) ;
178175 } ,
179176} ;
180177const streakReacts : EmojiIdentifierResolvable [ ] = [
0 commit comments