mirror of
https://github.com/warengroup/eximiabots-radiox.git
synced 2025-06-17 01:56:00 +00:00
Merge branch 'master' into fix-33
This commit is contained in:
@ -85,6 +85,10 @@ class RadioClient extends Client {
|
||||
process.on('SIGTERM', () => {
|
||||
require(`${events}SIGTERM`).execute(this);
|
||||
});
|
||||
|
||||
process.on('uncaughtException', (error) => {
|
||||
require(`${events}uncaughtException`).execute(this, error);
|
||||
});
|
||||
|
||||
this.on("error", error => {
|
||||
console.error(error);
|
||||
|
@ -3,7 +3,6 @@ import Discord from "discord.js";
|
||||
module.exports = {
|
||||
name: 'bug',
|
||||
description: 'Report a bug',
|
||||
permission: 'none',
|
||||
category: 'info',
|
||||
async execute(interaction, client) {
|
||||
let message = {};
|
||||
|
@ -3,7 +3,6 @@ import Discord from "discord.js";
|
||||
module.exports = {
|
||||
name: 'help',
|
||||
description: 'Get help using bot',
|
||||
permission: 'none',
|
||||
category: 'info',
|
||||
execute(interaction, client) {
|
||||
let message = {};
|
||||
|
@ -3,7 +3,6 @@ import Discord from "discord.js";
|
||||
module.exports = {
|
||||
name: 'invite',
|
||||
description: 'Invite Bot',
|
||||
permission: 'none',
|
||||
category: 'info',
|
||||
execute(interaction, client) {
|
||||
let message = {};
|
||||
|
@ -3,13 +3,15 @@ import Discord from "discord.js";
|
||||
module.exports = {
|
||||
name: 'list',
|
||||
description: 'List radio stations',
|
||||
permission: 'none',
|
||||
category: 'radio',
|
||||
execute(interaction, client) {
|
||||
let message = {};
|
||||
if(!client.stations) {
|
||||
message.errorToGetPlaylist = client.messages.errorToGetPlaylist.replace("%client.config.supportGuild%", client.config.supportGuild);
|
||||
return interaction.reply(client.messageEmojis["error"] + message.errorToGetPlaylist);
|
||||
return interaction.reply({
|
||||
content: client.messageEmojis["error"] + message.errorToGetPlaylist,
|
||||
ephemeral: true
|
||||
});
|
||||
}
|
||||
|
||||
const radio = client.radio.get(interaction.guild.id);
|
||||
|
@ -1,9 +1,9 @@
|
||||
import Discord from "discord.js";
|
||||
import fetch from "node-fetch";
|
||||
|
||||
module.exports = {
|
||||
name: 'maintenance',
|
||||
description: 'Bot Maintenance',
|
||||
permission: 'none',
|
||||
category: 'info',
|
||||
options: [
|
||||
{ type: "NUMBER", name: "action", description: "Select action", required: false}
|
||||
@ -11,7 +11,10 @@ module.exports = {
|
||||
async execute(interaction, client) {
|
||||
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({
|
||||
content: client.messageEmojis["error"] + client.messages.notAllowed,
|
||||
ephemeral: true
|
||||
});
|
||||
let action = interaction.options?.getNumber("action") ?? interaction.values?.[0];
|
||||
const options = new Array(
|
||||
{
|
||||
@ -38,6 +41,12 @@ module.exports = {
|
||||
description: "",
|
||||
value: "6"
|
||||
},
|
||||
{
|
||||
emoji: "<:RadioXList:688541155519889482>",
|
||||
label: "Reload Stations",
|
||||
description: "",
|
||||
value: "7"
|
||||
},
|
||||
{
|
||||
emoji: "<:dnd:746069698139127831>",
|
||||
label: "Enable Maintenance Mode",
|
||||
@ -87,17 +96,13 @@ module.exports = {
|
||||
break;
|
||||
case "4":
|
||||
client.user.setStatus('idle');
|
||||
setTimeout(function () {
|
||||
client.funcs.saveRadios(client);
|
||||
}, 5000);
|
||||
client.funcs.saveRadios(client);
|
||||
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.funcs.restoreRadios(client, guilds);
|
||||
client.user.setStatus('online');
|
||||
break;
|
||||
case "6":
|
||||
@ -105,6 +110,18 @@ module.exports = {
|
||||
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());
|
||||
|
||||
client.funcs.logger('Stations', 'Successfully fetched list');
|
||||
} catch (error) {
|
||||
client.funcs.logger('Stations', 'Fetching list failed');
|
||||
}
|
||||
break;
|
||||
case "8":
|
||||
client.user.setStatus('dnd');
|
||||
break;
|
||||
|
@ -1,7 +1,6 @@
|
||||
module.exports = {
|
||||
name: 'next',
|
||||
description: 'Next Station',
|
||||
permission: 'none',
|
||||
category: 'radio',
|
||||
async execute(interaction, client, command) {
|
||||
if (client.funcs.check(client, interaction, command)) {
|
||||
@ -17,8 +16,6 @@ module.exports = {
|
||||
ephemeral: true
|
||||
});
|
||||
|
||||
interaction.deferUpdate();
|
||||
|
||||
let url = station.stream[station.stream.default];
|
||||
|
||||
client.funcs.statisticsUpdate(client, interaction.guild, radio);
|
||||
@ -28,7 +25,14 @@ module.exports = {
|
||||
radio.station = station;
|
||||
radio.textChannel = interaction.channel;
|
||||
radio.startTime = date.getTime();
|
||||
client.funcs.play(null, interaction.guild, client, url);
|
||||
|
||||
if(interaction.isCommand()) {
|
||||
client.funcs.play(interaction, interaction.guild, client, url);
|
||||
}
|
||||
if(interaction.isButton()) {
|
||||
interaction.deferUpdate();
|
||||
client.funcs.play(null, interaction.guild, client, url);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ import Discord from "discord.js";
|
||||
module.exports = {
|
||||
name: 'nowplaying',
|
||||
description: 'Current Radio Station',
|
||||
permission: 'none',
|
||||
category: 'radio',
|
||||
async execute(interaction, client, command) {
|
||||
if (client.funcs.check(client, interaction, command)) {
|
||||
|
@ -11,13 +11,15 @@ module.exports = {
|
||||
options: [
|
||||
{ type: "STRING", name: "query", description: "Select station", required: false}
|
||||
],
|
||||
permission: "none",
|
||||
category: "radio",
|
||||
async execute(interaction, client) {
|
||||
let message = {};
|
||||
if(!client.stations) {
|
||||
message.errorToGetPlaylist = client.messages.errorToGetPlaylist.replace("%client.config.supportGuild%", client.config.supportGuild);
|
||||
return interaction.reply(client.messageEmojis["error"] + message.errorToGetPlaylist);
|
||||
return interaction.reply({
|
||||
content: client.messageEmojis["error"] + message.errorToGetPlaylist,
|
||||
ephemeral: true
|
||||
});
|
||||
}
|
||||
|
||||
let query = interaction.options?.getString("query") ?? interaction.values?.[0];
|
||||
@ -27,26 +29,32 @@ module.exports = {
|
||||
let url = query ? query.replace(/<(.+)>/g, "$1") : "";
|
||||
const radio = client.radio.get(interaction.guild.id);
|
||||
const voiceChannel = interaction.member.voice.channel;
|
||||
if (!radio) {
|
||||
if (!interaction.member.voice.channel)
|
||||
return interaction.reply({
|
||||
content: client.messageEmojis["error"] + client.messages.noVoiceChannel,
|
||||
ephemeral: true
|
||||
});
|
||||
} else {
|
||||
if (voiceChannel !== radio.voiceChannel)
|
||||
return interaction.reply({
|
||||
content: client.messageEmojis["error"] + client.messages.wrongVoiceChannel,
|
||||
ephemeral: true
|
||||
});
|
||||
if (!voiceChannel) return interaction.reply({
|
||||
content: client.messageEmojis["error"] + client.messages.noVoiceChannel,
|
||||
ephemeral: true
|
||||
});
|
||||
if (radio) {
|
||||
if (voiceChannel !== radio.voiceChannel) return interaction.reply({
|
||||
content: client.messageEmojis["error"] + client.messages.wrongVoiceChannel,
|
||||
ephemeral: true
|
||||
});
|
||||
}
|
||||
if (!query) return interaction.reply(client.messages.noQuery);
|
||||
if (!query) return interaction.reply({
|
||||
content: client.messages.noQuery,
|
||||
ephemeral: true
|
||||
});
|
||||
const permissions = voiceChannel.permissionsFor(interaction.client.user);
|
||||
if (!permissions.has("CONNECT")) {
|
||||
return interaction.reply(client.messageEmojis["error"] + client.messages.noPermsConnect);
|
||||
return interaction.reply({
|
||||
content: client.messageEmojis["error"] + client.messages.noPermsConnect,
|
||||
ephemeral: true
|
||||
});
|
||||
}
|
||||
if (!permissions.has("SPEAK")) {
|
||||
return interaction.reply(client.messageEmojis["error"] + client.messages.noPermsSpeak);
|
||||
return interaction.reply({
|
||||
content: client.messageEmojis["error"] + client.messages.noPermsSpeak,
|
||||
ephemeral: true
|
||||
});
|
||||
}
|
||||
let station;
|
||||
const number = parseInt(query - 1);
|
||||
@ -66,17 +74,15 @@ module.exports = {
|
||||
station = client.stations[number];
|
||||
}
|
||||
} else {
|
||||
if (query.length < 3)
|
||||
return interaction.reply({
|
||||
content: client.messageEmojis["error"] + client.messages.tooShortSearch,
|
||||
ephemeral: true
|
||||
});
|
||||
if (query.length < 3) return interaction.reply({
|
||||
content: client.messageEmojis["error"] + client.messages.tooShortSearch,
|
||||
ephemeral: true
|
||||
});
|
||||
const sstation = await client.funcs.searchStation(query, client);
|
||||
if (!sstation)
|
||||
return interaction.reply({
|
||||
content: client.messageEmojis["error"] + client.messages.noSearchResults,
|
||||
ephemeral: true
|
||||
});
|
||||
if (!sstation) return interaction.reply({
|
||||
content: client.messageEmojis["error"] + client.messages.noSearchResults,
|
||||
ephemeral: true
|
||||
});
|
||||
url = sstation.stream[sstation.stream.default];
|
||||
station = sstation;
|
||||
}
|
||||
@ -129,7 +135,10 @@ module.exports = {
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
client.radio.delete(interaction.guild.id);
|
||||
return interaction.reply(client.messageEmojis["error"] + `An error occured: ${error}`);
|
||||
return interaction.reply({
|
||||
content: client.messageEmojis["error"] + `An error occured: ${error}`,
|
||||
ephemeral: true
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
@ -1,7 +1,6 @@
|
||||
module.exports = {
|
||||
name: 'prev',
|
||||
description: 'Previous Station',
|
||||
permission: 'none',
|
||||
category: 'radio',
|
||||
async execute(interaction, client, command) {
|
||||
if (client.funcs.check(client, interaction, command)) {
|
||||
@ -17,8 +16,6 @@ module.exports = {
|
||||
ephemeral: true
|
||||
});
|
||||
|
||||
interaction.deferUpdate();
|
||||
|
||||
let url = station.stream[station.stream.default];
|
||||
|
||||
client.funcs.statisticsUpdate(client, interaction.guild, radio);
|
||||
@ -28,7 +25,14 @@ module.exports = {
|
||||
radio.station = station;
|
||||
radio.textChannel = interaction.channel;
|
||||
radio.startTime = date.getTime();
|
||||
client.funcs.play(null, interaction.guild, client, url);
|
||||
|
||||
if(interaction.isCommand()) {
|
||||
client.funcs.play(interaction, interaction.guild, client, url);
|
||||
}
|
||||
if(interaction.isButton()) {
|
||||
interaction.deferUpdate();
|
||||
client.funcs.play(null, interaction.guild, client, url);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ import Discord from "discord.js";
|
||||
module.exports = {
|
||||
name: 'statistics',
|
||||
description: 'Show statistics',
|
||||
permission: 'none',
|
||||
category: 'info',
|
||||
execute(interaction, client) {
|
||||
let message = {};
|
||||
@ -15,7 +14,10 @@ module.exports = {
|
||||
|
||||
if(!client.stations) {
|
||||
message.errorToGetPlaylist = client.messages.errorToGetPlaylist.replace("%client.config.supportGuild%", client.config.supportGuild);
|
||||
return interaction.reply(client.messageEmojis["error"] + message.errorToGetPlaylist);
|
||||
return interaction.reply({
|
||||
content: client.messageEmojis["error"] + message.errorToGetPlaylist,
|
||||
ephemeral: true
|
||||
});
|
||||
}
|
||||
|
||||
if(!currentGuild || currentGuild && !currentGuild.statistics){
|
||||
|
@ -3,7 +3,6 @@ import Discord from "discord.js";
|
||||
module.exports = {
|
||||
name: 'status',
|
||||
description: 'Bot Status',
|
||||
permission: 'none',
|
||||
category: 'info',
|
||||
async execute(interaction, client) {
|
||||
let message = {};
|
||||
|
@ -3,7 +3,6 @@ import Discord from "discord.js";
|
||||
module.exports = {
|
||||
name: 'stop',
|
||||
description: 'Stop radio',
|
||||
permission: 'none',
|
||||
category: 'radio',
|
||||
async execute(interaction, client, command) {
|
||||
const radio = client.radio.get(interaction.guild.id);
|
||||
|
@ -1,23 +1,18 @@
|
||||
const { REST } = require('@discordjs/rest');
|
||||
const { Routes } = require('discord-api-types/v9');
|
||||
const { token, version } = require('../../config.js');
|
||||
|
||||
module.exports = {
|
||||
name: 'SIGINT',
|
||||
async execute(client) {
|
||||
execute(client) {
|
||||
client.user.setStatus('dnd');
|
||||
|
||||
console.log("\n");
|
||||
client.funcs.logger("Bot", "Closing");
|
||||
console.log("\n");
|
||||
|
||||
client.funcs.saveRadios(client);
|
||||
|
||||
setTimeout(async function () {
|
||||
let message = {};
|
||||
|
||||
if (!client.stations) return process.exit();
|
||||
|
||||
await client.funcs.saveRadios(client);
|
||||
await process.exit();
|
||||
}, 5000);
|
||||
setInterval(() => {
|
||||
if(client.radio.size == 0){
|
||||
process.exit();
|
||||
}
|
||||
}, 500);
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
module.exports = {
|
||||
name: 'SIGTERM',
|
||||
async execute(client) {
|
||||
execute(client) {
|
||||
process.emit('SIGINT');
|
||||
}
|
||||
}
|
7
src/client/events/uncaughtException.js
Normal file
7
src/client/events/uncaughtException.js
Normal file
@ -0,0 +1,7 @@
|
||||
module.exports = {
|
||||
name: 'uncaughtException',
|
||||
execute(client, error) {
|
||||
console.log(error.stack);
|
||||
process.emit('SIGINT');
|
||||
}
|
||||
}
|
@ -24,14 +24,6 @@ module.exports = function (client, interaction, command) {
|
||||
});
|
||||
return false;
|
||||
}
|
||||
if(!command.permission == 'none'){
|
||||
if (!permissions.has(command.permission)) {
|
||||
message.noPerms = client.messages.noPerms.replace("%command.permission%", command.permission);
|
||||
interaction.reply({
|
||||
content: client.messageEmojis["error"] + message.noPerms,
|
||||
ephemeral: true
|
||||
});
|
||||
return false;
|
||||
} else return true;
|
||||
} else return true;
|
||||
|
||||
return true;
|
||||
};
|
||||
|
@ -27,7 +27,10 @@ module.exports = async function play(interaction, guild, client, url) {
|
||||
radio.connection?.destroy();
|
||||
radio.audioPlayer?.stop();
|
||||
client.radio.delete(guild.id);
|
||||
return interaction.reply(client.messages.errorPlaying);
|
||||
return interaction.reply({
|
||||
content: client.messages.errorPlaying,
|
||||
ephemeral: true
|
||||
});
|
||||
});
|
||||
|
||||
message.nowplayingDescription = client.messages.nowplayingDescription.replace("%radio.station.name%", radio.station.name);
|
||||
|
@ -1,4 +1,4 @@
|
||||
module.exports = async function saveRadios(client) {
|
||||
module.exports = function saveRadios(client) {
|
||||
let currentRadios = client.radio.keys();
|
||||
let radio = currentRadios.next();
|
||||
|
||||
@ -7,8 +7,8 @@ module.exports = async function saveRadios(client) {
|
||||
currentRadio.guild = client.datastore.getEntry(radio.value).guild;
|
||||
|
||||
if (currentRadio) {
|
||||
await client.funcs.statisticsUpdate(client, currentRadio.guild, currentRadio);
|
||||
await client.funcs.saveState(client, currentRadio.guild, currentRadio);
|
||||
client.funcs.statisticsUpdate(client, currentRadio.guild, currentRadio);
|
||||
client.funcs.saveState(client, currentRadio.guild, currentRadio);
|
||||
currentRadio.connection?.destroy();
|
||||
currentRadio.audioPlayer?.stop();
|
||||
currentRadio.message?.delete();
|
||||
|
Reference in New Issue
Block a user