2021-09-05 00:17:21 +00:00
|
|
|
|
import Discord from "discord.js";
|
2021-09-07 22:39:35 +00:00
|
|
|
|
const _importDynamic = new Function('modulePath', 'return import(modulePath)');
|
|
|
|
|
const fetch = (...args) => _importDynamic('node-fetch').then(({default: fetch}) => fetch(...args));
|
2021-09-05 00:17:21 +00:00
|
|
|
|
|
2021-06-08 09:01:56 +00:00
|
|
|
|
module.exports = {
|
|
|
|
|
name: 'maintenance',
|
|
|
|
|
description: 'Bot Maintenance',
|
|
|
|
|
category: 'info',
|
2021-09-06 01:21:50 +00:00
|
|
|
|
options: [
|
|
|
|
|
{ type: "NUMBER", name: "action", description: "Select action", required: false}
|
|
|
|
|
],
|
|
|
|
|
async execute(interaction, client) {
|
2021-06-08 09:01:56 +00:00
|
|
|
|
let message = {};
|
|
|
|
|
|
2021-09-06 11:42:49 +00:00
|
|
|
|
if(!client.funcs.isDev(client.config.devId, interaction.user.id)) return interaction.reply({
|
|
|
|
|
content: client.messageEmojis["error"] + client.messages.notAllowed,
|
|
|
|
|
ephemeral: true
|
|
|
|
|
});
|
2021-09-06 01:21:50 +00:00
|
|
|
|
let action = interaction.options?.getNumber("action") ?? interaction.values?.[0];
|
|
|
|
|
const options = new Array(
|
|
|
|
|
{
|
|
|
|
|
emoji: "🌀",
|
|
|
|
|
label: "Restart Bot",
|
|
|
|
|
description: "",
|
|
|
|
|
value: "0"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
emoji: "<:RadioXStop:688541155377414168>",
|
|
|
|
|
label: "Save Radios",
|
|
|
|
|
description: "",
|
|
|
|
|
value: "4"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
emoji: "<:RadioXPlay:688541155712827458>",
|
|
|
|
|
label: "Restore Radios",
|
|
|
|
|
description: "",
|
|
|
|
|
value: "5"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
emoji: "#️⃣",
|
|
|
|
|
label: "Reload Commands",
|
|
|
|
|
description: "",
|
|
|
|
|
value: "6"
|
|
|
|
|
},
|
2021-09-06 16:43:14 +00:00
|
|
|
|
{
|
|
|
|
|
emoji: "<:RadioXList:688541155519889482>",
|
|
|
|
|
label: "Reload Stations",
|
|
|
|
|
description: "",
|
|
|
|
|
value: "7"
|
|
|
|
|
},
|
2021-09-06 01:21:50 +00:00
|
|
|
|
{
|
|
|
|
|
emoji: "<:dnd:746069698139127831>",
|
|
|
|
|
label: "Enable Maintenance Mode",
|
|
|
|
|
description: "",
|
|
|
|
|
value: "8"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
emoji: "<:online:746069731836035098>",
|
|
|
|
|
label: "Disable Maintenance Mode",
|
|
|
|
|
description: "",
|
|
|
|
|
value: "9"
|
|
|
|
|
}
|
|
|
|
|
);
|
2021-09-09 09:44:50 +00:00
|
|
|
|
|
2021-09-06 01:21:50 +00:00
|
|
|
|
const menu = new Discord.MessageActionRow()
|
|
|
|
|
.addComponents(
|
|
|
|
|
new Discord.MessageSelectMenu()
|
|
|
|
|
.setCustomId('maintenance')
|
|
|
|
|
.setPlaceholder('Select action')
|
|
|
|
|
.addOptions(options)
|
|
|
|
|
);
|
2021-06-08 09:01:56 +00:00
|
|
|
|
|
2021-09-06 01:21:50 +00:00
|
|
|
|
if(!action){
|
2021-09-06 02:11:49 +00:00
|
|
|
|
return interaction.reply({
|
2021-09-06 01:21:50 +00:00
|
|
|
|
content: "**" + client.messages.maintenanceTitle + "**",
|
|
|
|
|
components: [menu],
|
2021-09-04 23:12:57 +00:00
|
|
|
|
ephemeral: true
|
|
|
|
|
});
|
2021-09-06 01:21:50 +00:00
|
|
|
|
}
|
2021-06-08 09:01:56 +00:00
|
|
|
|
|
2021-09-06 01:21:50 +00:00
|
|
|
|
client.funcs.logger('Maintenance', options.find(option => option.value == action).label);
|
|
|
|
|
|
|
|
|
|
const embed = new Discord.MessageEmbed()
|
2021-09-04 23:12:57 +00:00
|
|
|
|
.setTitle(client.messages.maintenanceTitle)
|
|
|
|
|
.setColor(client.config.embedColor)
|
2021-09-06 01:21:50 +00:00
|
|
|
|
.setDescription(options.find(option => option.value == action).label)
|
2021-09-04 23:12:57 +00:00
|
|
|
|
.setFooter(client.messages.footerText, "https://cdn.discordapp.com/emojis/" + client.messageEmojis["eximiabots"].replace(/[^0-9]+/g, ''));
|
2021-09-09 09:44:50 +00:00
|
|
|
|
|
2021-09-06 01:21:50 +00:00
|
|
|
|
interaction.reply({
|
|
|
|
|
embeds: [embed],
|
|
|
|
|
ephemeral: true
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
switch(action){
|
|
|
|
|
case "0":
|
2021-09-10 00:17:22 +00:00
|
|
|
|
client.config.maintenance = true;
|
2021-09-06 01:21:50 +00:00
|
|
|
|
process.emit('SIGINT');
|
|
|
|
|
break;
|
|
|
|
|
case "4":
|
2021-09-10 00:17:22 +00:00
|
|
|
|
client.config.maintenance = true;
|
2021-09-06 01:21:50 +00:00
|
|
|
|
client.user.setStatus('idle');
|
2021-09-06 18:45:13 +00:00
|
|
|
|
client.funcs.saveRadios(client);
|
2021-09-06 01:21:50 +00:00
|
|
|
|
client.user.setStatus('online');
|
2021-09-10 00:17:22 +00:00
|
|
|
|
client.config.maintenance = false;
|
2021-09-06 01:21:50 +00:00
|
|
|
|
break;
|
|
|
|
|
case "5":
|
2021-09-10 00:17:22 +00:00
|
|
|
|
client.config.maintenance = true;
|
2021-09-06 01:21:50 +00:00
|
|
|
|
client.user.setStatus('idle');
|
|
|
|
|
let guilds = await client.guilds.fetch();
|
2021-09-06 18:45:13 +00:00
|
|
|
|
client.funcs.restoreRadios(client, guilds);
|
2021-09-06 01:21:50 +00:00
|
|
|
|
client.user.setStatus('online');
|
2021-09-10 00:17:22 +00:00
|
|
|
|
client.config.maintenance = false;
|
2021-09-06 01:21:50 +00:00
|
|
|
|
break;
|
|
|
|
|
case "6":
|
2021-09-10 00:17:22 +00:00
|
|
|
|
client.config.maintenance = true;
|
2021-09-06 01:21:50 +00:00
|
|
|
|
client.user.setStatus('idle');
|
|
|
|
|
require(`../commands.js`).execute(client);
|
|
|
|
|
client.user.setStatus('online');
|
2021-09-10 00:17:22 +00:00
|
|
|
|
client.config.maintenance = false;
|
2021-09-06 01:21:50 +00:00
|
|
|
|
break;
|
2021-09-06 16:43:14 +00:00
|
|
|
|
case "7":
|
|
|
|
|
try {
|
|
|
|
|
client.funcs.logger('Stations', 'Started fetching list – ' + client.config.stationslistUrl);
|
|
|
|
|
client.stations = await fetch(client.config.stationslistUrl)
|
|
|
|
|
.then(client.funcs.checkFetchStatus)
|
|
|
|
|
.then(response => response.json());
|
2021-09-09 09:44:50 +00:00
|
|
|
|
|
2021-09-06 16:43:14 +00:00
|
|
|
|
client.funcs.logger('Stations', 'Successfully fetched list');
|
2021-09-11 20:02:37 +00:00
|
|
|
|
|
|
|
|
|
client.streamer.refresh(client);
|
|
|
|
|
|
2021-09-06 16:43:14 +00:00
|
|
|
|
} catch (error) {
|
|
|
|
|
client.funcs.logger('Stations', 'Fetching list failed');
|
|
|
|
|
}
|
|
|
|
|
break;
|
2021-09-06 01:21:50 +00:00
|
|
|
|
case "8":
|
|
|
|
|
client.user.setStatus('dnd');
|
2021-09-09 15:55:18 +00:00
|
|
|
|
client.funcs.logger("Maintenance Mode", "Enabled");
|
2021-09-10 00:13:40 +00:00
|
|
|
|
client.config.maintenance = true;
|
2021-09-06 01:21:50 +00:00
|
|
|
|
break;
|
|
|
|
|
case "9":
|
|
|
|
|
client.user.setStatus('online');
|
2021-09-09 15:55:18 +00:00
|
|
|
|
client.funcs.logger("Maintenance Mode", "Disabled");
|
|
|
|
|
client.config.maintenance = false;
|
2021-09-06 01:21:50 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-08 09:01:56 +00:00
|
|
|
|
}
|
2021-09-09 09:44:50 +00:00
|
|
|
|
};
|