2023-05-23 21:48:29 +00:00
|
|
|
|
import { ActionRowBuilder, EmbedBuilder, StringSelectMenuBuilder } from "discord.js";
|
2023-06-04 01:07:41 +00:00
|
|
|
|
import Streamer from "../classes/Streamer";
|
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
|
|
|
|
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",
|
|
|
|
|
value: "0"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
emoji: "<:RadioXStop:688541155377414168>",
|
|
|
|
|
label: "Save Radios",
|
|
|
|
|
value: "4"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
emoji: "<:RadioXPlay:688541155712827458>",
|
|
|
|
|
label: "Restore Radios",
|
|
|
|
|
value: "5"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
emoji: "#️⃣",
|
|
|
|
|
label: "Reload Commands",
|
|
|
|
|
value: "6"
|
|
|
|
|
},
|
2021-09-06 16:43:14 +00:00
|
|
|
|
{
|
|
|
|
|
emoji: "<:RadioXList:688541155519889482>",
|
|
|
|
|
label: "Reload Stations",
|
|
|
|
|
value: "7"
|
|
|
|
|
},
|
2021-09-06 01:21:50 +00:00
|
|
|
|
{
|
|
|
|
|
emoji: "<:dnd:746069698139127831>",
|
|
|
|
|
label: "Enable Maintenance Mode",
|
|
|
|
|
value: "8"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
emoji: "<:online:746069731836035098>",
|
|
|
|
|
label: "Disable Maintenance Mode",
|
|
|
|
|
value: "9"
|
2021-09-12 14:39:38 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
emoji: "💤",
|
|
|
|
|
label: "Streamer Mode – Manual",
|
|
|
|
|
value: "10"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
emoji: "📡",
|
|
|
|
|
label: "Streamer Mode – Auto",
|
|
|
|
|
value: "11"
|
2021-09-06 01:21:50 +00:00
|
|
|
|
}
|
|
|
|
|
);
|
2021-09-09 09:44:50 +00:00
|
|
|
|
|
2022-07-18 20:44:19 +00:00
|
|
|
|
const menu = new ActionRowBuilder()
|
2021-09-06 01:21:50 +00:00
|
|
|
|
.addComponents(
|
2023-05-23 21:48:29 +00:00
|
|
|
|
new StringSelectMenuBuilder()
|
2021-09-06 01:21:50 +00:00
|
|
|
|
.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);
|
|
|
|
|
|
2022-07-18 20:44:19 +00:00
|
|
|
|
const embed = new EmbedBuilder()
|
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)
|
2022-04-06 09:35:58 +00:00
|
|
|
|
.setFooter({
|
|
|
|
|
text: client.messages.footerText,
|
|
|
|
|
iconURL: "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
|
|
|
|
|
});
|
|
|
|
|
|
2021-09-12 14:49:21 +00:00
|
|
|
|
let guilds = await client.guilds.fetch();
|
|
|
|
|
|
2021-09-06 01:21:50 +00:00
|
|
|
|
switch(action){
|
|
|
|
|
case "0":
|
2021-09-12 14:49:21 +00:00
|
|
|
|
client.config.maintenanceMode = true;
|
2021-09-06 01:21:50 +00:00
|
|
|
|
process.emit('SIGINT');
|
|
|
|
|
break;
|
|
|
|
|
case "4":
|
2021-09-12 14:49:21 +00:00
|
|
|
|
client.config.maintenanceMode = true;
|
2021-09-06 01:21:50 +00:00
|
|
|
|
client.user.setStatus('idle');
|
2021-09-16 01:52:30 +00:00
|
|
|
|
client.radio.save(client);
|
2021-09-06 01:21:50 +00:00
|
|
|
|
client.user.setStatus('online');
|
2021-09-12 14:49:21 +00:00
|
|
|
|
client.config.maintenanceMode = false;
|
2021-09-06 01:21:50 +00:00
|
|
|
|
break;
|
|
|
|
|
case "5":
|
2021-09-12 14:49:21 +00:00
|
|
|
|
client.config.maintenanceMode = true;
|
2021-09-06 01:21:50 +00:00
|
|
|
|
client.user.setStatus('idle');
|
2021-09-16 01:52:30 +00:00
|
|
|
|
client.radio.restore(client, guilds);
|
2021-09-06 01:21:50 +00:00
|
|
|
|
client.user.setStatus('online');
|
2021-09-12 14:49:21 +00:00
|
|
|
|
client.config.maintenanceMode = false;
|
2021-09-06 01:21:50 +00:00
|
|
|
|
break;
|
|
|
|
|
case "6":
|
2021-09-12 14:49:21 +00:00
|
|
|
|
client.config.maintenanceMode = true;
|
2021-09-06 01:21:50 +00:00
|
|
|
|
client.user.setStatus('idle');
|
|
|
|
|
require(`../commands.js`).execute(client);
|
|
|
|
|
client.user.setStatus('online');
|
2021-09-12 14:49:21 +00:00
|
|
|
|
client.config.maintenanceMode = false;
|
2021-09-06 01:21:50 +00:00
|
|
|
|
break;
|
2021-09-06 16:43:14 +00:00
|
|
|
|
case "7":
|
|
|
|
|
try {
|
2021-09-16 01:52:30 +00:00
|
|
|
|
client.stations.fetch({
|
|
|
|
|
url: client.config.stationslistUrl
|
|
|
|
|
});
|
2021-09-11 20:02:37 +00:00
|
|
|
|
client.streamer.refresh(client);
|
|
|
|
|
|
2021-09-06 16:43:14 +00:00
|
|
|
|
} catch (error) {
|
2021-09-16 01:52:30 +00:00
|
|
|
|
|
2021-09-06 16:43:14 +00:00
|
|
|
|
}
|
|
|
|
|
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-12 14:49:21 +00:00
|
|
|
|
client.config.maintenanceMode = 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");
|
2021-09-12 14:49:21 +00:00
|
|
|
|
client.config.maintenanceMode = false;
|
2021-09-12 14:39:38 +00:00
|
|
|
|
break;
|
|
|
|
|
case "10":
|
2021-09-14 14:12:47 +00:00
|
|
|
|
client.config.streamerMode = "manual";
|
2021-09-12 14:49:21 +00:00
|
|
|
|
client.config.maintenanceMode = true;
|
2021-09-14 14:12:47 +00:00
|
|
|
|
|
2021-09-12 14:39:38 +00:00
|
|
|
|
client.user.setStatus('idle');
|
2021-09-17 23:14:13 +00:00
|
|
|
|
client.radio.save(client);
|
2021-09-12 14:39:38 +00:00
|
|
|
|
|
2021-09-14 14:12:47 +00:00
|
|
|
|
setInterval(() => {
|
|
|
|
|
if(client.radio.size == 0 && client.config.streamerMode == "manual" && client.config.maintenanceMode){
|
|
|
|
|
client.streamer.leave(client);
|
|
|
|
|
client.streamer = new Streamer();
|
|
|
|
|
client.streamer.init(client);
|
2021-09-12 14:49:21 +00:00
|
|
|
|
|
2021-09-16 01:52:30 +00:00
|
|
|
|
client.radio.restore(client, guilds);
|
2021-09-14 14:12:47 +00:00
|
|
|
|
client.user.setStatus('online');
|
|
|
|
|
client.config.maintenanceMode = false;
|
|
|
|
|
}
|
2021-09-12 14:39:38 +00:00
|
|
|
|
|
2021-09-14 14:12:47 +00:00
|
|
|
|
if(!client.config.maintenanceMode){
|
|
|
|
|
clearInterval();
|
|
|
|
|
}
|
|
|
|
|
}, 500);
|
2021-09-12 14:39:38 +00:00
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case "11":
|
2021-09-14 14:12:47 +00:00
|
|
|
|
client.config.streamerMode = "auto";
|
2021-09-12 14:49:21 +00:00
|
|
|
|
client.config.maintenanceMode = true;
|
2021-09-14 14:12:47 +00:00
|
|
|
|
|
2021-09-12 14:39:38 +00:00
|
|
|
|
client.user.setStatus('idle');
|
2021-09-18 12:01:27 +00:00
|
|
|
|
client.radio.save(client);
|
2021-09-12 14:39:38 +00:00
|
|
|
|
|
2021-09-14 14:12:47 +00:00
|
|
|
|
setInterval(() => {
|
|
|
|
|
if(client.radio.size == 0 && client.config.streamerMode == "auto" && client.config.maintenanceMode){
|
|
|
|
|
client.streamer.leave(client);
|
|
|
|
|
client.streamer = new Streamer();
|
|
|
|
|
client.streamer.init(client);
|
|
|
|
|
|
2021-09-16 01:52:30 +00:00
|
|
|
|
client.radio.restore(client, guilds);
|
2021-09-14 14:12:47 +00:00
|
|
|
|
client.user.setStatus('online');
|
|
|
|
|
client.config.maintenanceMode = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!client.config.maintenanceMode){
|
|
|
|
|
clearInterval();
|
|
|
|
|
}
|
|
|
|
|
}, 500);
|
2021-09-12 14:39:38 +00:00
|
|
|
|
|
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
|
|
|
|
};
|