Merge branch 'master' into fix-33

This commit is contained in:
Christer Warén
2021-09-03 01:57:31 +03:00
22 changed files with 504 additions and 66 deletions

View File

@ -0,0 +1,43 @@
import Discord from "discord.js";
module.exports = {
name: 'SIGINT',
async execute(client) {
setTimeout(async function () {
let message = {};
if (!client.stations) return process.exit();
let currentRadios = client.radio.keys();
let radio = currentRadios.next();
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);
client.funcs.saveState(client, currentRadio.guild, currentRadio);
currentRadio.connection?.destroy();
currentRadio.audioPlayer?.stop();
currentRadio.message?.delete();
client.radio.delete(radio.value);
}
radio = currentRadios.next();
}
console.log("\n");
client.funcs.logger("Bot", "Closing");
console.log("\n");
client.user.setStatus('dnd');
setInterval(() => {
if(radio.done){
process.exit();
}
}, 1000);
}, 5000);
}
}

View File

@ -0,0 +1,6 @@
module.exports = {
name: 'SIGTERM',
async execute(client) {
process.emit('SIGINT');
}
}

View File

@ -3,7 +3,6 @@ import Discord from "discord.js";
module.exports = {
name: 'interactionCreate',
async execute(client, interaction) {
/*if (!interaction.isCommand()) return;*/
const permissions = interaction.channel.permissionsFor(interaction.client.user);
if (!permissions.has('EMBED_LINKS')) return interaction.send(client.messages.noPermsEmbed);
@ -16,7 +15,10 @@ module.exports = {
try {
command.execute(interaction, client, Discord, command);
} catch (error) {
interaction.reply(client.messages.runningCommandFailed);
interaction.reply({
content: client.messages.runningCommandFailed,
ephemeral: true
});
console.error(error);
}
} else if (interaction.isSelectMenu() || interaction.isButton()){
@ -27,7 +29,10 @@ module.exports = {
try {
command.execute(interaction, client, Discord, command);
} catch (error) {
interaction.reply(client.messages.runningCommandFailed);
interaction.reply({
content: client.messages.runningCommandFailed,
ephemeral: true
});
console.error(error);
}
}

View File

@ -0,0 +1,54 @@
import Discord from "discord.js";
module.exports = {
name: 'messageCreate',
async execute(client, msg) {
if (msg.author.bot || !msg.guild) return;
let prefix = "rx$";
if(client.user.username == "RadioX"){
prefix = "rx>";
} else if (client.user.username == "RadioX Beta"){
prefix = "rx-";
} else if (client.user.username == "RadioX Dev"){
prefix = "rx$";
} else if(msg.mentions.members.first() && msg.mentions.members.first().user.id === client.user.id){
prefix = "<@!" + client.user.id + "> ";
} else {
return;
}
const args = msg.content.slice(prefix.length).split(' ');
if (!msg.content.startsWith(prefix)) return;
if (!args[0]) return;
const commandName = args[0].toLowerCase();
if (commandName === 'none') return;
const command = client.commands.get(commandName) || client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName)) || client.commandAliases.get(commandName);
if (!command && msg.content !== `${prefix}`) return;
const permissions = msg.channel.permissionsFor(msg.client.user);
if (!permissions.has('EMBED_LINKS')) return msg.channel.send(client.messages.noPermsEmbed);
try {
let message = {};
message.messageCommandsDeprecatedTitle = client.messages.messageCommandsDeprecatedTitle.replace("%client.user.username%", client.user.username);
const embed = new Discord.MessageEmbed()
.setTitle(message.messageCommandsDeprecatedTitle)
.setThumbnail("https://cdn.discordapp.com/emojis/" + client.messageEmojis["logo"].replace(/[^0-9]+/g, ''))
.setColor(client.config.embedColor)
.setDescription(client.messages.messageCommandsDeprecatedDescription)
.setFooter(client.messages.footerText, "https://cdn.discordapp.com/emojis/" + client.messageEmojis["eximiabots"].replace(/[^0-9]+/g, ''));
msg.channel.send({ embeds: [embed] });
setTimeout(function() {
msg.delete();
}, 30000);
} catch (error) {
msg.reply({
content: client.messages.runningCommandFailed,
ephemeral: true
});
console.error(error);
}
}
}

View File

@ -0,0 +1,10 @@
module.exports = {
name: 'messageDelete',
async execute(client, msg) {
if (!msg.author.bot || !msg.guild) return;
const radio = client.radio.get(msg.guild.id);
if (!radio) return;
if(msg.id != radio.message.id) return;
radio.message = null;
}
}

View File

@ -1,22 +1,24 @@
import Datastore from "../datastore.js";
const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));
module.exports = {
name: 'ready',
async execute(client) {
console.log('RadioX ' + client.config.version);
console.log('Internet Radio to your Discord guild');
console.log('(c)2020-2021 EximiaBots by Warén Group');
console.log('');
client.funcs.logger("Bot", "Ready");
/*DATASTORE*/
client.funcs.logger('Datastore', 'Initialize');
client.datastore = new Datastore();
/*DEVELOPERS*/
client.funcs.logger('Developers', 'List');
client.funcs.logger('Developers');
client.developers = "";
let user = "";
for (let i = 0; i < client.config.devId.length; i++) {
user = await client.users.fetch(client.config.devId[i]);
console.log(" - " + user.tag);
console.log("- " + user.tag);
if (i == client.config.devId.length - 1) {
client.developers += user.tag;
} else {
@ -32,9 +34,9 @@ module.exports = {
.then(client.funcs.checkFetchStatus)
.then(response => response.json());
client.funcs.logger('Stations', 'List');
client.funcs.logger('Stations');
client.stations.forEach(station => {
console.log(" - " + station.name);
console.log("- " + station.name);
});
console.log("\n");
@ -65,15 +67,15 @@ module.exports = {
/*GUILDS*/
client.funcs.logger('Guilds', 'Started fetching list');
client.funcs.logger('Guilds', 'List');
client.funcs.logger('Guilds');
let guilds = await client.guilds.fetch();
guilds.forEach(guild => {
console.log(" - " + guild.id + ": " + guild.name);
console.log("- " + guild.id + ": " + guild.name);
});
console.log("\n");
client.funcs.logger('Guilds', 'Successfully fetched list');
/*STATISTICS*/
client.datastore.calculateGlobal(client);
@ -83,5 +85,10 @@ module.exports = {
/*COMMANDS*/
require(`../commands.js`).execute(client);
setTimeout(function () {
/*RESTORE RADIO*/
require(`../restoreradio.js`).execute(client, guilds);
}, 5000);
}
}