99import moment from "moment-timezone" ;
1010import { v4 as uuidv4 } from "uuid" ;
1111import { GenericCommandSource , isContextInteraction , sendContextResponse } from "../pluginUtils.js" ;
12- import { noop } from "../utils.js" ;
12+ import { noop , createDisabledButtonRow } from "../utils.js" ;
1313
1414export async function waitForButtonConfirm (
1515 context : GenericCommandSource ,
@@ -24,34 +24,42 @@ export async function waitForButtonConfirm(
2424 . setStyle ( ButtonStyle . Success )
2525 . setLabel ( options ?. confirmText || "Confirm" )
2626 . setCustomId ( `confirmButton:${ idMod } :${ uuidv4 ( ) } ` ) ,
27-
2827 new ButtonBuilder ( )
2928 . setStyle ( ButtonStyle . Danger )
3029 . setLabel ( options ?. cancelText || "Cancel" )
3130 . setCustomId ( `cancelButton:${ idMod } :${ uuidv4 ( ) } ` ) ,
3231 ] ) ;
3332 const message = await sendContextResponse ( context , { ...toPost , components : [ row ] } , true ) ;
34-
3533 const collector = message . createMessageComponentCollector ( { time : 10000 } ) ;
3634
3735 collector . on ( "collect" , ( interaction : MessageComponentInteraction ) => {
3836 if ( options ?. restrictToId && options . restrictToId !== interaction . user . id ) {
3937 interaction
4038 . reply ( { content : `You are not permitted to use these buttons.` , ephemeral : true } )
41- // tslint:disable-next-line no-console
42- . catch ( ( err ) => console . trace ( err . message ) ) ;
43- } else {
44- if ( interaction . customId . startsWith ( `confirmButton:${ idMod } :` ) ) {
45- if ( ! contextIsInteraction ) message . delete ( ) ;
46- resolve ( true ) ;
47- } else if ( interaction . customId . startsWith ( `cancelButton:${ idMod } :` ) ) {
48- if ( ! contextIsInteraction ) message . delete ( ) ;
49- resolve ( false ) ;
39+ . catch ( noop ) ;
40+ } else if ( interaction . customId . startsWith ( `confirmButton:${ idMod } :` ) ) {
41+ if ( ! contextIsInteraction ) {
42+ message . delete ( ) . catch ( noop ) ;
43+ } else {
44+ interaction . update ( { components : [ createDisabledButtonRow ( row ) ] } ) . catch ( noop ) ;
45+ }
46+ resolve ( true ) ;
47+ } else if ( interaction . customId . startsWith ( `cancelButton:${ idMod } :` ) ) {
48+ if ( ! contextIsInteraction ) {
49+ message . delete ( ) . catch ( noop ) ;
50+ } else {
51+ interaction . update ( { components : [ createDisabledButtonRow ( row ) ] } ) . catch ( noop ) ;
5052 }
53+ resolve ( false ) ;
5154 }
5255 } ) ;
56+
5357 collector . on ( "end" , ( ) => {
54- if ( ! contextIsInteraction && message . deletable ) message . delete ( ) . catch ( noop ) ;
58+ if ( ! contextIsInteraction ) {
59+ if ( message . deletable ) message . delete ( ) . catch ( noop ) ;
60+ } else {
61+ message . edit ( { components : [ createDisabledButtonRow ( row ) ] } ) . catch ( noop ) ;
62+ }
5563 resolve ( false ) ;
5664 } ) ;
5765 } ) ;
0 commit comments