mirror of
https://github.com/warengroup/eximiabots-radiox.git
synced 2024-12-23 01:13:17 +00:00
Simplify events
This commit is contained in:
parent
348ac90cba
commit
87cf4b62c8
@ -6,7 +6,7 @@ import Streamer from "./client/classes/Streamer";
|
||||
import Statistics from "./client/classes/Statistics";
|
||||
import { command } from "./client/commands";
|
||||
import config from "./config";
|
||||
import { events } from "./client/events"
|
||||
import events from "./client/events"
|
||||
import { funcs } from "./client/funcs";
|
||||
import { messages } from "./client/messages";
|
||||
|
||||
@ -20,7 +20,6 @@ GatewayIntents.add(
|
||||
|
||||
export default class RadioClient extends Client {
|
||||
readonly commands: Collection<string, command>;
|
||||
readonly events = events;
|
||||
readonly funcs = funcs;
|
||||
readonly config = config;
|
||||
readonly messages = messages;
|
||||
@ -52,47 +51,7 @@ export default class RadioClient extends Client {
|
||||
this.funcs.logger("Maintenance Mode", "Enabled");
|
||||
this.config.maintenanceMode = true;
|
||||
|
||||
this.on("ready", () => {
|
||||
this.events.ready.execute(this);
|
||||
});
|
||||
|
||||
this.on("messageDelete", msg => {
|
||||
this.events.messageDelete.execute(this, msg);
|
||||
});
|
||||
|
||||
this.on("interactionCreate", interaction => {
|
||||
this.events.interactionCreate.execute(this, interaction);
|
||||
});
|
||||
|
||||
this.on("voiceStateUpdate", (oldState, newState) => {
|
||||
this.events.voiceStateUpdate.execute(this, oldState, newState);
|
||||
});
|
||||
|
||||
this.on("error", error => {
|
||||
this.funcs.logger("Discord Client", "Error");
|
||||
console.error(error);
|
||||
console.log('');
|
||||
});
|
||||
|
||||
process.on('SIGINT', () => {
|
||||
this.events.SIGINT.execute(this);
|
||||
});
|
||||
|
||||
process.on('SIGTERM', () => {
|
||||
this.events.SIGTERM.execute(this);
|
||||
});
|
||||
|
||||
process.on('uncaughtException', (error) => {
|
||||
this.events.uncaughtException.execute(this, error);
|
||||
});
|
||||
|
||||
process.on('exit', () => {
|
||||
this.funcs.logger("Bot", "Stopping");
|
||||
});
|
||||
|
||||
process.on('warning', (warning) => {
|
||||
this.events.warning.execute(this, warning);
|
||||
});
|
||||
events(this);
|
||||
|
||||
this.login(this.config.token).catch((err) => {
|
||||
this.funcs.logger("Discord Client", "Login Error");
|
||||
|
@ -1,3 +1,4 @@
|
||||
import RadioClient from "../Client"
|
||||
import interactionCreate from "./events/interactionCreate"
|
||||
import messageDelete from "./events/messageDelete"
|
||||
import ready from "./events/ready"
|
||||
@ -7,6 +8,46 @@ import uncaughtException from "./events/uncaughtException"
|
||||
import voiceStateUpdate from "./events/voiceStateUpdate"
|
||||
import warning from "./events/warning"
|
||||
|
||||
export const events = {
|
||||
interactionCreate, messageDelete, ready, SIGINT, SIGTERM, uncaughtException, voiceStateUpdate, warning
|
||||
export default function events(client: RadioClient) {
|
||||
client.on("ready", () => {
|
||||
ready(client);
|
||||
});
|
||||
|
||||
client.on("messageDelete", msg => {
|
||||
messageDelete(client, msg);
|
||||
});
|
||||
|
||||
client.on("interactionCreate", interaction => {
|
||||
interactionCreate(client, interaction);
|
||||
});
|
||||
|
||||
client.on("voiceStateUpdate", (oldState, newState) => {
|
||||
voiceStateUpdate(client, oldState, newState);
|
||||
});
|
||||
|
||||
client.on("error", error => {
|
||||
client.funcs.logger("Discord Client", "Error");
|
||||
console.error(error);
|
||||
console.log('');
|
||||
});
|
||||
|
||||
process.on('SIGINT', () => {
|
||||
SIGINT(client);
|
||||
});
|
||||
|
||||
process.on('SIGTERM', () => {
|
||||
SIGTERM(client);
|
||||
});
|
||||
|
||||
process.on('uncaughtException', (error) => {
|
||||
uncaughtException(client, error);
|
||||
});
|
||||
|
||||
process.on('exit', () => {
|
||||
client.funcs.logger("Bot", "Stopping");
|
||||
});
|
||||
|
||||
process.on('warning', (error) => {
|
||||
warning(client, error);
|
||||
});
|
||||
}
|
||||
|
@ -1,8 +1,6 @@
|
||||
import RadioClient from "../../Client";
|
||||
|
||||
export default {
|
||||
name: 'SIGINT',
|
||||
execute(client: RadioClient) {
|
||||
export default function SIGINT(client: RadioClient) {
|
||||
client.user?.setStatus('dnd');
|
||||
|
||||
client.streamer?.leave(client);
|
||||
@ -13,5 +11,4 @@ export default {
|
||||
process.exit();
|
||||
}
|
||||
}, 500);
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,5 @@
|
||||
import RadioClient from "../../Client";
|
||||
|
||||
export default {
|
||||
name: 'SIGTERM',
|
||||
execute(client: RadioClient) {
|
||||
export default function SIGTERM(client: RadioClient) {
|
||||
process.emit('SIGINT');
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,8 @@
|
||||
import { PermissionFlagsBits } from "discord.js";
|
||||
import { Interaction, PermissionFlagsBits } from "discord.js";
|
||||
import RadioClient from "../../Client";
|
||||
|
||||
export default {
|
||||
name: 'interactionCreate',
|
||||
async execute(client: RadioClient, interaction: any) {
|
||||
export default function interactionCreate(client: RadioClient, interaction: Interaction) {
|
||||
if(!(interaction.isButton()) && !(interaction.isChatInputCommand()) && !(interaction.isStringSelectMenu())) return;
|
||||
|
||||
if(client.config.maintenanceMode){
|
||||
return interaction.reply({
|
||||
@ -12,7 +11,8 @@ export default {
|
||||
});
|
||||
}
|
||||
|
||||
const permissions = interaction.channel.permissionsFor(interaction.client.user);
|
||||
//@ts-ignore
|
||||
const permissions = interaction.channel?.permissionsFor(interaction.client.user);
|
||||
if (!permissions.has(PermissionFlagsBits.ViewChannel)) return;
|
||||
|
||||
if (!permissions.has(PermissionFlagsBits.EmbedLinks)) return interaction.reply({
|
||||
@ -49,5 +49,4 @@ export default {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,11 @@
|
||||
import { Message, PartialMessage } from "discord.js";
|
||||
import RadioClient from "../../Client";
|
||||
|
||||
export default {
|
||||
name: 'messageDelete',
|
||||
async execute(client: RadioClient, msg: Message | PartialMessage) {
|
||||
export default function messageDelete(client: RadioClient, msg: Message | PartialMessage){
|
||||
if(!msg.author?.bot || !msg.guild) return;
|
||||
const radio = client.radio?.get(msg.guild.id);
|
||||
if(!radio) return;
|
||||
if(!radio.message) return;
|
||||
if(msg.id != radio.message.id) return;
|
||||
radio.message = null;
|
||||
}
|
||||
}
|
||||
|
@ -6,10 +6,7 @@ import Streamer from "../classes/Streamer";
|
||||
import Statistics from "../classes/Statistics";
|
||||
import commands from "../commands";
|
||||
|
||||
export default {
|
||||
name: 'ready',
|
||||
async execute(client: RadioClient) {
|
||||
|
||||
export default async function ready(client: RadioClient) {
|
||||
client.funcs.logger("Bot", "Ready");
|
||||
|
||||
/*DATASTORE*/
|
||||
@ -82,6 +79,4 @@ export default {
|
||||
client.config.maintenanceMode = false;
|
||||
}
|
||||
}, 10000);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,10 @@
|
||||
import RadioClient from "../../Client";
|
||||
|
||||
export default {
|
||||
name: 'uncaughtException',
|
||||
execute(client: RadioClient, error: any) {
|
||||
export default function uncaughtException(client: RadioClient, error: Error) {
|
||||
client.funcs.logger("Error");
|
||||
console.log(error.stack);
|
||||
console.log('');
|
||||
|
||||
if(error.name == "DiscordAPIError" && error.message == "Unknown interaction") return;
|
||||
process.emit('SIGINT');
|
||||
}
|
||||
}
|
||||
|
@ -5,9 +5,7 @@ const {
|
||||
joinVoiceChannel
|
||||
} = require("@discordjs/voice");
|
||||
|
||||
export default {
|
||||
name: "voiceStateUpdate",
|
||||
async execute(client: RadioClient, oldState: VoiceState, newState: VoiceState) {
|
||||
export default async function voiceStateUpdate(client: RadioClient, oldState: VoiceState, newState: VoiceState) {
|
||||
if (oldState.channel === null) return;
|
||||
let change = false;
|
||||
const radio = client.radio?.get(newState.guild.id);
|
||||
@ -33,7 +31,6 @@ export default {
|
||||
guildId: oldState.channel?.guild.id,
|
||||
adapterCreator: oldState.channel?.guild.voiceAdapterCreator
|
||||
})
|
||||
//radio.connection = await oldState.channel.join()
|
||||
),
|
||||
1000
|
||||
);
|
||||
@ -50,7 +47,7 @@ export default {
|
||||
change = true;
|
||||
radio.voiceChannel = newState.channel;
|
||||
radio.connection = getVoiceConnection(newState.channel.guild.id);
|
||||
//radio.connection = await newState.channel.join();
|
||||
|
||||
}
|
||||
}
|
||||
if ((oldState.channel.members.filter(member => !member.user.bot).size === 0 && oldState.channel === radio.voiceChannel) || change) {
|
||||
@ -65,5 +62,4 @@ export default {
|
||||
}
|
||||
}, 5000);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
@ -1,8 +1,6 @@
|
||||
import RadioClient from "../../Client";
|
||||
|
||||
export default {
|
||||
name: 'warning',
|
||||
execute(client: RadioClient, warning: Error) {
|
||||
export default function warning(client: RadioClient, warning: Error) {
|
||||
if(warning.name == "ExperimentalWarning" && warning.message.startsWith("stream/web")) return;
|
||||
|
||||
client.funcs.logger("Warning");
|
||||
@ -10,5 +8,4 @@ export default {
|
||||
console.warn(warning.message);
|
||||
console.warn(warning.stack);
|
||||
console.log('');
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user