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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26