Updated maintenance command

This commit is contained in:
Christer Warén 2021-09-06 04:21:50 +03:00
parent 05852b99d4
commit 235a02ca60

View File

@ -5,58 +5,156 @@ module.exports = {
description: 'Bot Maintenance', description: 'Bot Maintenance',
permission: 'none', permission: 'none',
category: 'info', category: 'info',
execute(interaction, client) { options: [
{ type: "NUMBER", name: "action", description: "Select action", required: false}
],
async execute(interaction, client) {
let message = {}; let message = {};
if(!client.funcs.isDev(client.config.devId, interaction.user.id)) return interaction.reply(client.messageEmojis["error"] + client.messages.notAllowed); if(!client.funcs.isDev(client.config.devId, interaction.user.id)) return interaction.reply(client.messageEmojis["error"] + client.messages.notAllowed);
let action = interaction.options?.getNumber("action") ?? interaction.values?.[0];
if(client.config.version.includes("-dev")){ const options = new Array(
interaction.reply({ {
content: "Maintenance Initiated", emoji: "🌀",
ephemeral: true label: "Restart Bot",
}); description: "",
value: "0"
process.emit('SIGINT'); },
} else { {
if(!client.stations) { emoji: "<:RadioXStop:688541155377414168>",
message.errorToGetPlaylist = client.messages.errorToGetPlaylist.replace("%client.config.supportGuild%", client.config.supportGuild); label: "Save Radios",
return interaction.reply(client.messageEmojis["error"] + message.errorToGetPlaylist); description: "",
value: "4"
},
{
emoji: "<:RadioXPlay:688541155712827458>",
label: "Restore Radios",
description: "",
value: "5"
},
{
emoji: "#️⃣",
label: "Reload Commands",
description: "",
value: "6"
},
{
emoji: "<:dnd:746069698139127831>",
label: "Enable Maintenance Mode",
description: "",
value: "8"
},
{
emoji: "<:online:746069731836035098>",
label: "Disable Maintenance Mode",
description: "",
value: "9"
} }
);
let currentRadios = client.radio.keys();
let radio = currentRadios.next(); const menu = new Discord.MessageActionRow()
let stoppedRadios = ""; .addComponents(
new Discord.MessageSelectMenu()
client.user.setStatus('dnd'); .setCustomId('maintenance')
.setPlaceholder('Select action')
while (!radio.done) { .addOptions(options)
let currentRadio = client.radio.get(radio.value); );
currentRadio.guild = client.datastore.getEntry(radio.value).guild;
if(!action){
if(currentRadio){
client.funcs.statisticsUpdate(client, currentRadio.guild, currentRadio);
currentRadio.connection?.destroy();
currentRadio.audioPlayer?.stop();
currentRadio.message?.delete();
client.radio.delete(radio.value);
stoppedRadios += "-" + radio.value + ": " + currentRadio.guild.name + "\n";
}
radio = currentRadios.next();
}
const embed = new Discord.MessageEmbed()
.setTitle(client.messages.maintenanceTitle)
.setThumbnail("https://cdn.discordapp.com/emojis/" + client.messageEmojis["maintenance"].replace(/[^0-9]+/g, ''))
.setColor(client.config.embedColor)
.setDescription("Stopped all radios" + "\n" + stoppedRadios)
.setImage('https://waren.io/berriabot-temp-sa7a36a9xm6837br/images/empty-3.png')
.setFooter(client.messages.footerText, "https://cdn.discordapp.com/emojis/" + client.messageEmojis["eximiabots"].replace(/[^0-9]+/g, ''));
interaction.reply({ interaction.reply({
embeds: [embed], content: "**" + client.messages.maintenanceTitle + "**",
components: [menu],
ephemeral: true ephemeral: true
}); });
} }
client.funcs.logger('Maintenance', options.find(option => option.value == action).label);
const embed = new Discord.MessageEmbed()
.setTitle(client.messages.maintenanceTitle)
.setColor(client.config.embedColor)
.setDescription(options.find(option => option.value == action).label)
.setFooter(client.messages.footerText, "https://cdn.discordapp.com/emojis/" + client.messageEmojis["eximiabots"].replace(/[^0-9]+/g, ''));
interaction.reply({
embeds: [embed],
ephemeral: true
});
switch(action){
case "0":
process.emit('SIGINT');
break;
case "4":
client.user.setStatus('idle');
setTimeout(function () {
client.funcs.saveRadios(client);
}, 5000);
client.user.setStatus('online');
break;
case "5":
client.user.setStatus('idle');
let guilds = await client.guilds.fetch();
setTimeout(function () {
client.funcs.restoreRadios(client, guilds);
}, 5000);
client.user.setStatus('online');
break;
case "6":
client.user.setStatus('idle');
require(`../commands.js`).execute(client);
client.user.setStatus('online');
break;
case "8":
client.user.setStatus('dnd');
break;
case "9":
client.user.setStatus('online');
break;
default:
}
/*
if(!client.stations) {
message.errorToGetPlaylist = client.messages.errorToGetPlaylist.replace("%client.config.supportGuild%", client.config.supportGuild);
return interaction.reply(client.messageEmojis["error"] + message.errorToGetPlaylist);
}
let currentRadios = client.radio.keys();
let radio = currentRadios.next();
let stoppedRadios = "";
client.user.setStatus('dnd');
while (!radio.done) {
let currentRadio = client.radio.get(radio.value);
currentRadio.guild = client.datastore.getEntry(radio.value).guild;
if(currentRadio){
client.funcs.statisticsUpdate(client, currentRadio.guild, currentRadio);
currentRadio.connection?.destroy();
currentRadio.audioPlayer?.stop();
currentRadio.message?.delete();
client.radio.delete(radio.value);
stoppedRadios += "-" + radio.value + ": " + currentRadio.guild.name + "\n";
}
radio = currentRadios.next();
}
const embed = new Discord.MessageEmbed()
.setTitle(client.messages.maintenanceTitle)
.setThumbnail("https://cdn.discordapp.com/emojis/" + client.messageEmojis["maintenance"].replace(/[^0-9]+/g, ''))
.setColor(client.config.embedColor)
.setDescription("Stopped all radios" + "\n" + stoppedRadios)
.setImage('https://waren.io/berriabot-temp-sa7a36a9xm6837br/images/empty-3.png')
.setFooter(client.messages.footerText, "https://cdn.discordapp.com/emojis/" + client.messageEmojis["eximiabots"].replace(/[^0-9]+/g, ''));
interaction.reply({
embeds: [embed],
ephemeral: true
});*/
} }
}; };