@@ -16,47 +16,53 @@ export default withContext(on, 'ready', async ({ config, discord, logger }, clie
1616 `Channel ${ channelId } in guild ${ guildId } is not a text channel, sticky messages will not be sent` ,
1717 )
1818
19- const send = async ( ) => {
20- const store = discord . stickyMessages [ guildId ] ! [ channelId ]
21- if ( ! store ) return
22-
23- try {
24- const oldMsg = store . currentMessage
25-
26- store . currentMessage = await channel . send ( {
27- ...message ,
28- embeds : message . embeds ?. map ( it => applyCommonEmbedStyles ( it , true , true , true ) ) ,
29- } )
30-
31- await oldMsg ?. delete ( )
32- } catch ( e ) {
33- logger . error (
34- `Error while sending sticky message to channel ${ channelId } in guild ${ guildId } :` ,
35- e ,
36- )
37- } finally {
38- // Clear any remaining timers
39- clearTimeout ( store . timer )
40- clearTimeout ( store . forceTimer )
41- store . forceTimerActive = store . timerActive = false
42-
43- logger . debug ( `Sent sticky message to channel ${ channelId } in guild ${ guildId } ` )
44- }
45- }
46-
4719 // Set up the store
48- discord . stickyMessages [ guildId ] ! [ channelId ] = {
20+ // biome-ignore lint/suspicious/noAssignInExpressions: don't care
21+ const store = ( discord . stickyMessages [ guildId ] ! [ channelId ] = {
4922 forceTimerActive : false ,
5023 timerActive : false ,
5124 forceTimerMs : forceSendTimeout ,
5225 timerMs : timeout ,
53- send,
26+ async send ( ) {
27+ try {
28+ await Promise . all ( [
29+ channel
30+ . send ( {
31+ ...message ,
32+ embeds : message . embeds ?. map ( it => applyCommonEmbedStyles ( it , true , true , true ) ) ,
33+ } )
34+ . then ( msg => {
35+ this . currentMessage = msg
36+ logger . debug ( `Sent sticky message to channel ${ channelId } in guild ${ guildId } ` )
37+ } ) ,
38+ this . currentMessage
39+ ?. delete ( )
40+ ?. then ( ( ) =>
41+ logger . debug (
42+ `Deleted old sticky message from channel ${ channelId } in guild ${ guildId } ` ,
43+ ) ,
44+ ) ,
45+ ] )
46+ } catch ( e ) {
47+ logger . error (
48+ `Error while managing sticky message of channel ${ channelId } in guild ${ guildId } :` ,
49+ e ,
50+ )
51+ } finally {
52+ // Clear any remaining timers
53+ clearTimeout ( this . timer )
54+ clearTimeout ( this . forceTimer )
55+ this . forceTimerActive = this . timerActive = false
56+
57+ logger . debug ( `Cleared sticky message timer for channel ${ channelId } in guild ${ guildId } ` )
58+ }
59+ } ,
5460 // If the store exists before the configuration refresh, take its current message
5561 currentMessage : oldStore ?. [ channelId ] ?. currentMessage ,
56- }
62+ } )
5763
5864 // Send a new sticky message immediately, as well as deleting the old/outdated message, if it exists
59- await send ( )
65+ await store . send ( )
6066 }
6167 }
6268} )
0 commit comments