/[sudobot]/trunk/src/commands/settings/RestartCommand.ts
ViewVC logotype

Diff of /trunk/src/commands/settings/RestartCommand.ts

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 58 by rakin, Mon Jul 29 17:28:25 2024 UTC revision 64 by rakin, Mon Jul 29 17:28:27 2024 UTC
# Line 1  Line 1 
1  import { CommandInteraction, GuildMember, Interaction, Message, MessageActionRow, MessageButton } from 'discord.js';  import { CommandInteraction, GuildMember, Interaction, InteractionCollector, Message, MessageActionRow, MessageButton, MessageCollector } from 'discord.js';
2  import BaseCommand from '../../utils/structures/BaseCommand';  import BaseCommand from '../../utils/structures/BaseCommand';
3  import DiscordClient from '../../client/Client';  import DiscordClient from '../../client/Client';
4  import CommandOptions from '../../types/CommandOptions';  import CommandOptions from '../../types/CommandOptions';
# Line 57  export default class RestartCommand exte Line 57  export default class RestartCommand exte
57    
58          const reply = <Message> await interaction.fetchReply();          const reply = <Message> await interaction.fetchReply();
59    
60          reply.awaitMessageComponent({          const collector = new InteractionCollector(client, {
61                channel: reply.channel,
62                message: reply,
63              componentType: 'BUTTON',              componentType: 'BUTTON',
64              filter(interaction) {              interactionType: 'MESSAGE_COMPONENT',
65                  return interaction.customId.startsWith('restart');              filter(i) {
66                    return i.isButton() && i.customId.startsWith('restart');
67              },              },
68              time: 15000              time: 15000
69          })          });
70          .then(async i => {  
71            collector.on('collect', async i => {
72                if (!i.isButton())
73                    return;
74                
75                if (i.member!.user.id !== interaction.member!.user.id) {
76                    await i.reply({
77                        content: 'That\'s not your button.',
78                        ephemeral: true
79                    });
80    
81                    return;
82                }
83    
84              if (i.customId === 'restart:true') {              if (i.customId === 'restart:true') {
85                  await i.update({                  await i.update({
86                      embeds: [                      embeds: [
# Line 96  export default class RestartCommand exte Line 112  export default class RestartCommand exte
112                      components: [disabledRow]                      components: [disabledRow]
113                  });                  });
114              }              }
         })  
         .catch(async e => {  
             console.log(e);  
             
             await reply.edit({  
                 embeds: [  
                     new MessageEmbed()  
                     .setColor('GREY')  
                     .setTitle('System Restart')  
                     .setDescription('This action has been canceled due to inactivity.')  
                 ],  
                 components: [disabledRow]  
             });  
115          });          });
116    
117            collector.on('end', async i => {
118                if (reply.embeds[0].hexColor === '#007bff') {
119                    await reply.edit({
120                        embeds: [
121                            new MessageEmbed()
122                            .setColor('GREY')
123                            .setTitle('System Restart')
124                            .setDescription('This action has been canceled due to inactivity.')
125                        ],
126                        components: [disabledRow]
127                    });
128                }
129            });
130    
131            // reply.awaitMessageComponent({
132            //     componentType: 'BUTTON',
133            //     filter(i) {
134            //         return i.customId.startsWith('restart') && i.member!.user.id === interaction.member!.user.id;
135            //     },
136            //     time: 15000
137            // })
138            // .then(async i => {
139            //     if (i.customId === 'restart:true') {
140            //         await i.update({
141            //             embeds: [
142            //                 new MessageEmbed()
143            //                 .setColor('#007bff')
144            //                 .setTitle('System Restart')
145            //                 .setDescription((await fetchEmoji('loading'))!.toString() + ' Restarting...')
146            //             ],
147            //             components: [disabledRow]
148            //         });
149    
150            //         await client.startupManager.createLockFile({
151            //             date: new Date().toISOString(),
152            //             guild_id: i.guild!.id,
153            //             channel_id: i.channel!.id,
154            //             message_id: reply.id
155            //         });
156    
157            //         await process.exit(0);
158            //     }
159            //     else {
160            //         await i.update({
161            //             embeds: [
162            //                 new MessageEmbed()
163            //                 .setColor('GREY')
164            //                 .setTitle('System Restart')
165            //                 .setDescription('This action has been canceled.')
166            //             ],
167            //             components: [disabledRow]
168            //         });
169            //     }
170            // })
171            // .catch(async e => {
172            //     console.log(e);
173              
174            //     await reply.edit({
175            //         embeds: [
176            //             new MessageEmbed()
177            //             .setColor('GREY')
178            //             .setTitle('System Restart')
179            //             .setDescription('This action has been canceled due to inactivity.')
180            //         ],
181            //         components: [disabledRow]
182            //     });
183            // });
184      }      }
185  }  }

Legend:
Removed from v.58  
changed lines
  Added in v.64

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26