/[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 393 by rakin, Mon Jul 29 17:29:59 2024 UTC
# Line 1  Line 1 
1  import { CommandInteraction, GuildMember, Interaction, Message, MessageActionRow, MessageButton } from 'discord.js';  /**
2    * This file is part of SudoBot.
3    *
4    * Copyright (C) 2021-2022 OSN Inc.
5    *
6    * SudoBot is free software; you can redistribute it and/or modify it
7    * under the terms of the GNU Affero General Public License as published by
8    * the Free Software Foundation, either version 3 of the License, or
9    * (at your option) any later version.
10    *
11    * SudoBot is distributed in the hope that it will be useful, but
12    * WITHOUT ANY WARRANTY; without even the implied warranty of
13    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14    * GNU Affero General Public License for more details.
15    *
16    * You should have received a copy of the GNU Affero General Public License
17    * along with SudoBot. If not, see <https://www.gnu.org/licenses/>.
18    */
19    
20    import { CommandInteraction, InteractionCollector, Message, MessageActionRow, MessageButton } from 'discord.js';
21  import BaseCommand from '../../utils/structures/BaseCommand';  import BaseCommand from '../../utils/structures/BaseCommand';
22  import DiscordClient from '../../client/Client';  import DiscordClient from '../../client/Client';
 import CommandOptions from '../../types/CommandOptions';  
23  import InteractionOptions from '../../types/InteractionOptions';  import InteractionOptions from '../../types/InteractionOptions';
24  import MessageEmbed from '../../client/MessageEmbed';  import MessageEmbed from '../../client/MessageEmbed';
 import Help from '../../utils/help';  
25  import { MessageButtonStyles } from 'discord.js/typings/enums';  import { MessageButtonStyles } from 'discord.js/typings/enums';
26  import { fetchEmoji } from '../../utils/Emoji';  import { fetchEmoji } from '../../utils/Emoji';
27    
# Line 57  export default class RestartCommand exte Line 74  export default class RestartCommand exte
74    
75          const reply = <Message> await interaction.fetchReply();          const reply = <Message> await interaction.fetchReply();
76    
77          reply.awaitMessageComponent({          const collector = new InteractionCollector(client, {
78                channel: reply.channel,
79                message: reply,
80              componentType: 'BUTTON',              componentType: 'BUTTON',
81              filter(interaction) {              interactionType: 'MESSAGE_COMPONENT',
82                  return interaction.customId.startsWith('restart');              filter(i) {
83                    return i.isButton() && i.customId.startsWith('restart');
84              },              },
85              time: 15000              time: 15000
86          })          });
87          .then(async i => {  
88            collector.on('collect', async i => {
89                if (!i.isButton())
90                    return;
91                
92                if (i.member!.user.id !== interaction.member!.user.id) {
93                    await i.reply({
94                        content: 'That\'s not your button.',
95                        ephemeral: true
96                    });
97    
98                    return;
99                }
100    
101              if (i.customId === 'restart:true') {              if (i.customId === 'restart:true') {
102                  await i.update({                  await i.update({
103                      embeds: [                      embeds: [
# Line 96  export default class RestartCommand exte Line 129  export default class RestartCommand exte
129                      components: [disabledRow]                      components: [disabledRow]
130                  });                  });
131              }              }
         })  
         .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]  
             });  
132          });          });
133    
134            collector.on('end', async i => {
135                if (reply.embeds[0].hexColor === '#007bff') {
136                    await reply.edit({
137                        embeds: [
138                            new MessageEmbed()
139                            .setColor('GREY')
140                            .setTitle('System Restart')
141                            .setDescription('This action has been canceled due to inactivity.')
142                        ],
143                        components: [disabledRow]
144                    });
145                }
146            });
147    
148            // reply.awaitMessageComponent({
149            //     componentType: 'BUTTON',
150            //     filter(i) {
151            //         return i.customId.startsWith('restart') && i.member!.user.id === interaction.member!.user.id;
152            //     },
153            //     time: 15000
154            // })
155            // .then(async i => {
156            //     if (i.customId === 'restart:true') {
157            //         await i.update({
158            //             embeds: [
159            //                 new MessageEmbed()
160            //                 .setColor('#007bff')
161            //                 .setTitle('System Restart')
162            //                 .setDescription((await fetchEmoji('loading'))!.toString() + ' Restarting...')
163            //             ],
164            //             components: [disabledRow]
165            //         });
166    
167            //         await client.startupManager.createLockFile({
168            //             date: new Date().toISOString(),
169            //             guild_id: i.guild!.id,
170            //             channel_id: i.channel!.id,
171            //             message_id: reply.id
172            //         });
173    
174            //         await process.exit(0);
175            //     }
176            //     else {
177            //         await i.update({
178            //             embeds: [
179            //                 new MessageEmbed()
180            //                 .setColor('GREY')
181            //                 .setTitle('System Restart')
182            //                 .setDescription('This action has been canceled.')
183            //             ],
184            //             components: [disabledRow]
185            //         });
186            //     }
187            // })
188            // .catch(async e => {
189            //     console.log(e);
190              
191            //     await reply.edit({
192            //         embeds: [
193            //             new MessageEmbed()
194            //             .setColor('GREY')
195            //             .setTitle('System Restart')
196            //             .setDescription('This action has been canceled due to inactivity.')
197            //         ],
198            //         components: [disabledRow]
199            //     });
200            // });
201      }      }
202  }  }

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26