eximiabots-radiox/src/client/commands/maintenance.js

138 lines
4.7 KiB
JavaScript
Raw Normal View History

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-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 = {};
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"
},
{
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":
process.emit('SIGINT');
break;
case "4":
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');
break;
case "5":
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');
break;
case "6":
client.user.setStatus('idle');
require(`../commands.js`).execute(client);
client.user.setStatus('online');
break;
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
client.funcs.logger('Stations', 'Successfully fetched list');
} catch (error) {
client.funcs.logger('Stations', 'Fetching list failed');
}
break;
2021-09-06 01:21:50 +00:00
case "8":
client.user.setStatus('dnd');
break;
case "9":
client.user.setStatus('online');
break;
default:
}
2021-06-08 09:01:56 +00:00
}
2021-09-09 09:44:50 +00:00
};