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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26