1 |
rakin |
58 |
import { CommandInteraction, GuildMember, Interaction, Message, MessageActionRow, MessageButton } from 'discord.js'; |
2 |
|
|
import BaseCommand from '../../utils/structures/BaseCommand'; |
3 |
|
|
import DiscordClient from '../../client/Client'; |
4 |
|
|
import CommandOptions from '../../types/CommandOptions'; |
5 |
|
|
import InteractionOptions from '../../types/InteractionOptions'; |
6 |
|
|
import MessageEmbed from '../../client/MessageEmbed'; |
7 |
|
|
import Help from '../../utils/help'; |
8 |
|
|
import { MessageButtonStyles } from 'discord.js/typings/enums'; |
9 |
|
|
import { fetchEmoji } from '../../utils/Emoji'; |
10 |
|
|
|
11 |
|
|
export default class RestartCommand extends BaseCommand { |
12 |
|
|
supportsInteractions: boolean = true; |
13 |
|
|
supportsLegacy = false; |
14 |
|
|
ownerOnly = true; |
15 |
|
|
|
16 |
|
|
constructor() { |
17 |
|
|
super('restart', 'settings', []); |
18 |
|
|
} |
19 |
|
|
|
20 |
|
|
async run(client: DiscordClient, interaction: CommandInteraction, options: InteractionOptions) { |
21 |
|
|
const row = new MessageActionRow(); |
22 |
|
|
|
23 |
|
|
row.addComponents([ |
24 |
|
|
new MessageButton() |
25 |
|
|
.setCustomId('restart:true') |
26 |
|
|
.setLabel('Yes') |
27 |
|
|
.setStyle(MessageButtonStyles.SUCCESS), |
28 |
|
|
new MessageButton() |
29 |
|
|
.setCustomId('restart:false') |
30 |
|
|
.setLabel('No') |
31 |
|
|
.setStyle(MessageButtonStyles.DANGER) |
32 |
|
|
]); |
33 |
|
|
|
34 |
|
|
const disabledRow = new MessageActionRow(); |
35 |
|
|
|
36 |
|
|
await disabledRow.addComponents([ |
37 |
|
|
new MessageButton() |
38 |
|
|
.setCustomId('restart:true') |
39 |
|
|
.setLabel('Restart') |
40 |
|
|
.setStyle(MessageButtonStyles.SUCCESS) |
41 |
|
|
.setDisabled(true), |
42 |
|
|
new MessageButton() |
43 |
|
|
.setCustomId('restart:false') |
44 |
|
|
.setLabel('Cancel') |
45 |
|
|
.setStyle(MessageButtonStyles.DANGER) |
46 |
|
|
.setDisabled(true) |
47 |
|
|
]); |
48 |
|
|
|
49 |
|
|
await interaction.reply({ |
50 |
|
|
embeds: [ |
51 |
|
|
new MessageEmbed() |
52 |
|
|
.setTitle('System Restart') |
53 |
|
|
.setDescription('Are you sure to restart the system? This will restart the whole bot system including the backend API and might take up to a minute.') |
54 |
|
|
], |
55 |
|
|
components: [row] |
56 |
|
|
}); |
57 |
|
|
|
58 |
|
|
const reply = <Message> await interaction.fetchReply(); |
59 |
|
|
|
60 |
|
|
reply.awaitMessageComponent({ |
61 |
|
|
componentType: 'BUTTON', |
62 |
|
|
filter(interaction) { |
63 |
|
|
return interaction.customId.startsWith('restart'); |
64 |
|
|
}, |
65 |
|
|
time: 15000 |
66 |
|
|
}) |
67 |
|
|
.then(async i => { |
68 |
|
|
if (i.customId === 'restart:true') { |
69 |
|
|
await i.update({ |
70 |
|
|
embeds: [ |
71 |
|
|
new MessageEmbed() |
72 |
|
|
.setColor('#007bff') |
73 |
|
|
.setTitle('System Restart') |
74 |
|
|
.setDescription((await fetchEmoji('loading'))!.toString() + ' Restarting...') |
75 |
|
|
], |
76 |
|
|
components: [disabledRow] |
77 |
|
|
}); |
78 |
|
|
|
79 |
|
|
await client.startupManager.createLockFile({ |
80 |
|
|
date: new Date().toISOString(), |
81 |
|
|
guild_id: i.guild!.id, |
82 |
|
|
channel_id: i.channel!.id, |
83 |
|
|
message_id: reply.id |
84 |
|
|
}); |
85 |
|
|
|
86 |
|
|
await process.exit(0); |
87 |
|
|
} |
88 |
|
|
else { |
89 |
|
|
await i.update({ |
90 |
|
|
embeds: [ |
91 |
|
|
new MessageEmbed() |
92 |
|
|
.setColor('GREY') |
93 |
|
|
.setTitle('System Restart') |
94 |
|
|
.setDescription('This action has been canceled.') |
95 |
|
|
], |
96 |
|
|
components: [disabledRow] |
97 |
|
|
}); |
98 |
|
|
} |
99 |
|
|
}) |
100 |
|
|
.catch(async e => { |
101 |
|
|
console.log(e); |
102 |
|
|
|
103 |
|
|
await reply.edit({ |
104 |
|
|
embeds: [ |
105 |
|
|
new MessageEmbed() |
106 |
|
|
.setColor('GREY') |
107 |
|
|
.setTitle('System Restart') |
108 |
|
|
.setDescription('This action has been canceled due to inactivity.') |
109 |
|
|
], |
110 |
|
|
components: [disabledRow] |
111 |
|
|
}); |
112 |
|
|
}); |
113 |
|
|
} |
114 |
|
|
} |