eximiabots-radiox/src/Client.ts

105 lines
3.2 KiB
TypeScript
Raw Normal View History

2022-07-18 20:44:19 +00:00
import { Client, Collection, IntentsBitField } from "discord.js";
2023-06-04 01:07:41 +00:00
import Datastore from "./client/classes/Datastore";
import Radio from "./client/classes/Radio";
import Stations from "./client/classes/Stations";
import Streamer from "./client/classes/Streamer";
2023-06-04 01:29:42 +00:00
import Statistics from "./client/classes/Statistics";
2023-06-04 21:13:15 +00:00
import { command } from "./client/commands";
2023-06-04 01:07:41 +00:00
import config from "./config";
2023-06-05 22:39:35 +00:00
import { messages } from "./client/messages";
import { events } from "./client/events"
import { funcs } from "./client/funcs";
2021-09-02 15:18:37 +00:00
2022-07-18 20:44:19 +00:00
const GatewayIntents = new IntentsBitField();
2021-06-08 09:01:56 +00:00
GatewayIntents.add(
1 << 0, // GUILDS
1 << 7, // GUILD_VOICE_STATES
1 << 9 // GUILD_MESSAGES
2021-06-08 09:01:56 +00:00
);
2023-06-04 02:48:42 +00:00
export default class RadioClient extends Client {
2021-06-08 09:01:56 +00:00
readonly commands: Collection<string, command>;
2023-06-05 22:39:35 +00:00
readonly events = events;
readonly funcs = funcs;
2021-06-08 09:01:56 +00:00
readonly config = config;
readonly messages = messages;
public datastore: Datastore | null;
2021-09-16 01:51:36 +00:00
public stations: Stations | null;
2021-09-11 14:11:10 +00:00
public streamer: Streamer | null;
2021-09-16 01:51:36 +00:00
public statistics: Statistics | null;
public radio: Radio | null;
2023-06-04 21:13:15 +00:00
public messageEmojis: any | null;
public developers: string | undefined;
2023-06-04 19:35:07 +00:00
2021-06-08 09:01:56 +00:00
constructor() {
super({
intents: GatewayIntents
});
this.commands = new Collection();
this.datastore = null;
2021-09-16 01:51:36 +00:00
this.stations = null;
2021-09-11 14:11:10 +00:00
this.streamer = null;
2021-09-16 01:51:36 +00:00
this.statistics = null;
this.radio = null;
2023-06-04 21:13:15 +00:00
this.messageEmojis = null;
2021-06-08 09:01:56 +00:00
2021-09-02 13:50:01 +00:00
console.log('RadioX ' + this.config.version);
console.log('Internet Radio to your Discord guild');
2022-02-22 11:18:41 +00:00
console.log('(c)2020-2022 EximiaBots by Warén Group');
2021-09-02 13:50:01 +00:00
console.log('');
this.funcs.logger("Bot", "Starting");
2021-09-09 15:55:42 +00:00
this.funcs.logger("Maintenance Mode", "Enabled");
this.config.maintenanceMode = true;
2021-09-09 15:55:42 +00:00
2021-06-08 09:01:56 +00:00
this.on("ready", () => {
2023-06-04 19:35:07 +00:00
this.events.ready.execute(this);
2021-06-08 09:01:56 +00:00
});
2021-09-02 11:39:23 +00:00
this.on("messageDelete", msg => {
2023-06-04 19:35:07 +00:00
this.events.messageDelete.execute(this, msg);
2021-09-02 11:39:23 +00:00
});
2021-08-18 22:50:35 +00:00
this.on("interactionCreate", interaction => {
2023-06-04 19:35:07 +00:00
this.events.interactionCreate.execute(this, interaction);
2021-06-08 09:01:56 +00:00
});
2021-09-09 09:44:50 +00:00
2021-06-08 09:01:56 +00:00
this.on("voiceStateUpdate", (oldState, newState) => {
2023-06-04 19:35:07 +00:00
this.events.voiceStateUpdate.execute(this, oldState, newState);
2021-06-08 09:01:56 +00:00
});
2021-09-09 09:44:50 +00:00
2021-09-09 22:21:42 +00:00
this.on("error", error => {
2023-06-05 22:39:35 +00:00
this.funcs.logger("Discord Client", "Error");
2021-09-09 22:21:42 +00:00
console.error(error);
2021-09-09 22:44:21 +00:00
console.log('');
2021-09-09 22:21:42 +00:00
});
2021-09-02 13:50:01 +00:00
process.on('SIGINT', () => {
2023-06-04 19:35:07 +00:00
this.events.SIGINT.execute(this);
2021-09-02 13:50:01 +00:00
});
2021-09-02 16:18:20 +00:00
process.on('SIGTERM', () => {
2023-06-04 19:35:07 +00:00
this.events.SIGTERM.execute(this);
2021-09-02 16:18:20 +00:00
});
2021-09-06 19:35:49 +00:00
process.on('uncaughtException', (error) => {
2023-06-04 19:35:07 +00:00
this.events.uncaughtException.execute(this, error);
2021-09-06 19:35:49 +00:00
});
2021-09-09 09:05:39 +00:00
process.on('exit', () => {
this.funcs.logger("Bot", "Stopping");
});
2021-09-09 09:44:50 +00:00
2021-09-09 22:21:42 +00:00
process.on('warning', (warning) => {
2023-06-04 19:35:07 +00:00
this.events.warning.execute(this, warning);
2021-06-08 09:01:56 +00:00
});
2021-09-09 22:54:43 +00:00
this.login(this.config.token).catch((err) => {
2023-06-05 22:39:35 +00:00
this.funcs.logger("Discord Client", "Login Error");
2021-09-09 22:54:43 +00:00
console.log(err);
console.log('');
});
2021-06-08 09:01:56 +00:00
}
}