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

237 lines
8.1 KiB
TypeScript
Raw Normal View History

2023-06-05 22:39:35 +00:00
import { ActionRowBuilder, AnyComponentBuilder, APIActionRowComponent, APISelectMenuOption, ButtonInteraction, ChatInputCommandInteraction, ColorResolvable, EmbedBuilder, StringSelectMenuBuilder, StringSelectMenuInteraction } from "discord.js";
2023-06-04 21:13:15 +00:00
import RadioClient from "../../Client";
2023-06-04 01:07:41 +00:00
import Streamer from "../classes/Streamer";
2023-06-04 19:35:07 +00:00
import commands from "../commands";
2021-09-07 22:39:35 +00:00
const _importDynamic = new Function('modulePath', 'return import(modulePath)');
2023-06-04 03:20:37 +00:00
// @ts-ignore
const fetch = (...args) => _importDynamic('node-fetch').then(({default: fetch}) => fetch(...args));
2023-06-04 01:29:42 +00:00
export default {
2021-06-08 09:01:56 +00:00
name: 'maintenance',
description: 'Bot Maintenance',
category: 'info',
2023-06-04 21:13:15 +00:00
async execute(interaction: ButtonInteraction | ChatInputCommandInteraction | StringSelectMenuInteraction, client: RadioClient) {
2023-06-04 02:48:42 +00:00
let message: any = {};
2021-06-08 09:01:56 +00:00
if(!client.funcs.isDev(client.config.devId, interaction.user.id)) return interaction.reply({
2023-06-05 23:27:46 +00:00
content: client.messages.emojis["error"] + client.messages.notAllowed,
ephemeral: true
});
2023-06-05 22:39:35 +00:00
let action : number | string | null = null;
if(interaction.isChatInputCommand()){
action = interaction.options?.getNumber("action");
}
if(interaction.isStringSelectMenu()){
action = interaction.values?.[0];
}
const options: APISelectMenuOption[] = new Array(
2021-09-06 01:21:50 +00:00
{
2023-06-05 22:39:35 +00:00
emoji: {
"name": "🌀",
},
2021-09-06 01:21:50 +00:00
label: "Restart Bot",
value: "0"
},
{
2023-06-05 22:39:35 +00:00
emoji: {
id: "688541155377414168",
name: "RadioXStop",
},
2021-09-06 01:21:50 +00:00
label: "Save Radios",
value: "4"
},
{
2023-06-05 22:39:35 +00:00
emoji: {
id: "688541155712827458",
name: "RadioXPlay",
},
2021-09-06 01:21:50 +00:00
label: "Restore Radios",
value: "5"
},
{
2023-06-05 22:39:35 +00:00
emoji: {
name: "#️⃣",
},
2021-09-06 01:21:50 +00:00
label: "Reload Commands",
value: "6"
},
{
2023-06-05 22:39:35 +00:00
emoji: {
id: "688541155519889482",
name: "RadioXList",
},
label: "Reload Stations",
value: "7"
},
2021-09-06 01:21:50 +00:00
{
2023-06-05 22:39:35 +00:00
emoji: {
id: "746069698139127831",
name: "dnd",
},
2021-09-06 01:21:50 +00:00
label: "Enable Maintenance Mode",
value: "8"
},
{
2023-06-05 22:39:35 +00:00
emoji: {
id: "746069731836035098",
name: "online",
},
2021-09-06 01:21:50 +00:00
label: "Disable Maintenance Mode",
value: "9"
2021-09-12 14:39:38 +00:00
},
{
2023-06-05 22:39:35 +00:00
emoji: {
name: "💤",
},
2023-06-04 21:13:15 +00:00
label: "Streamer Mode - Manual",
2021-09-12 14:39:38 +00:00
value: "10"
},
{
2023-06-05 22:39:35 +00:00
emoji: {
name: "📡",
},
2023-06-04 21:13:15 +00:00
label: "Streamer Mode - Auto",
2021-09-12 14:39:38 +00:00
value: "11"
2021-09-06 01:21:50 +00:00
}
);
2021-09-09 09:44:50 +00:00
2023-06-05 22:39:35 +00:00
const menu : ActionRowBuilder<any> = new ActionRowBuilder()
.addComponents(
new StringSelectMenuBuilder()
.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
2023-06-05 22:39:35 +00:00
client.funcs.logger('Maintenance', options.find((option: APISelectMenuOption) => option.value == action)?.label);
2021-09-06 01:21:50 +00:00
2022-07-18 20:44:19 +00:00
const embed = new EmbedBuilder()
2021-09-04 23:12:57 +00:00
.setTitle(client.messages.maintenanceTitle)
2023-06-04 21:13:15 +00:00
.setColor(client.config.embedColor as ColorResolvable)
2023-06-05 22:39:35 +00:00
.setDescription(options.find((option: APISelectMenuOption) => option.value == action)?.label || "-")
.setFooter({
text: client.messages.footerText,
2023-06-05 23:27:46 +00:00
iconURL: "https://cdn.discordapp.com/emojis/" + client.messages.emojis["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;
2023-06-05 22:39:35 +00:00
client.user?.setStatus('idle');
client.radio?.save(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;
case "5":
2021-09-12 14:49:21 +00:00
client.config.maintenanceMode = true;
2023-06-05 22:39:35 +00:00
client.user?.setStatus('idle');
client.radio?.restore(client, guilds);
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;
2023-06-05 22:39:35 +00:00
client.user?.setStatus('idle');
2023-06-04 19:35:07 +00:00
commands.execute(client);
2023-06-05 22:39:35 +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 "7":
try {
2023-06-05 22:39:35 +00:00
client.stations?.fetch({
2021-09-16 01:52:30 +00:00
url: client.config.stationslistUrl
});
2023-06-05 22:39:35 +00:00
client.streamer?.refresh(client);
2021-09-11 20:02:37 +00:00
} catch (error) {
2021-09-16 01:52:30 +00:00
}
break;
2021-09-06 01:21:50 +00:00
case "8":
2023-06-05 22:39:35 +00:00
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":
2023-06-05 22:39:35 +00:00
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
2023-06-05 22:39:35 +00:00
client.user?.setStatus('idle');
client.radio?.save(client);
2021-09-12 14:39:38 +00:00
2021-09-14 14:12:47 +00:00
setInterval(() => {
2023-06-05 22:39:35 +00:00
if(client.radio?.size == 0 && client.config.streamerMode == "manual" && client.config.maintenanceMode){
client.streamer?.leave(client);
2021-09-14 14:12:47 +00:00
client.streamer = new Streamer();
client.streamer.init(client);
2021-09-12 14:49:21 +00:00
2023-06-05 22:39:35 +00:00
client.radio?.restore(client, guilds);
client.user?.setStatus('online');
2021-09-14 14:12:47 +00:00
client.config.maintenanceMode = false;
}
2021-09-12 14:39:38 +00:00
2021-09-14 14:12:47 +00:00
if(!client.config.maintenanceMode){
2023-06-04 02:48:42 +00:00
clearInterval(undefined);
2021-09-14 14:12:47 +00:00
}
}, 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
2023-06-05 22:39:35 +00:00
client.user?.setStatus('idle');
client.radio?.save(client);
2021-09-12 14:39:38 +00:00
2021-09-14 14:12:47 +00:00
setInterval(() => {
2023-06-05 22:39:35 +00:00
if(client.radio?.size == 0 && client.config.streamerMode == "auto" && client.config.maintenanceMode){
client.streamer?.leave(client);
2021-09-14 14:12:47 +00:00
client.streamer = new Streamer();
client.streamer.init(client);
2021-09-16 01:52:30 +00:00
client.radio.restore(client, guilds);
2023-06-05 22:39:35 +00:00
client.user?.setStatus('online');
2021-09-14 14:12:47 +00:00
client.config.maintenanceMode = false;
}
if(!client.config.maintenanceMode){
2023-06-04 02:48:42 +00:00
clearInterval(undefined);
2021-09-14 14:12:47 +00:00
}
}, 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
};