2021-06-08 09:01:56 +00:00
|
|
|
import Discord, { Client, Collection } from "discord.js";
|
|
|
|
import fs from "fs";
|
|
|
|
import Datastore from "./client/datastore.js";
|
|
|
|
import { command, radio } from "./client/utils/typings.js";
|
|
|
|
import config from "./config.js";
|
|
|
|
import messages from "./client/messages.js";
|
2021-08-22 17:47:40 +00:00
|
|
|
import path from "path";
|
2021-06-08 09:01:56 +00:00
|
|
|
|
2021-09-02 15:18:37 +00:00
|
|
|
const events = "./client/events/";
|
|
|
|
|
2021-06-08 09:01:56 +00:00
|
|
|
const GatewayIntents = new Discord.Intents();
|
|
|
|
GatewayIntents.add(
|
|
|
|
1 << 0, // GUILDS
|
|
|
|
1 << 7, // GUILD_VOICE_STATES
|
2021-09-02 09:07:08 +00:00
|
|
|
1 << 9 // GUILD_MESSAGES
|
2021-06-08 09:01:56 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
class RadioClient extends Client {
|
|
|
|
readonly commands: Collection<string, command>;
|
|
|
|
readonly radio: Map<string, radio>;
|
|
|
|
public funcs: any;
|
|
|
|
readonly config = config;
|
|
|
|
readonly messages = messages;
|
|
|
|
public datastore: Datastore | null;
|
|
|
|
constructor() {
|
|
|
|
super({
|
|
|
|
intents: GatewayIntents
|
|
|
|
});
|
|
|
|
this.commands = new Collection();
|
|
|
|
this.radio = new Map();
|
|
|
|
this.datastore = null;
|
|
|
|
|
|
|
|
this.funcs = {};
|
|
|
|
this.funcs.check = require("./client/funcs/check.js");
|
|
|
|
this.funcs.checkFetchStatus = require("./client/funcs/checkFetchStatus.js");
|
|
|
|
this.funcs.isDev = require("./client/funcs/isDev.js");
|
2021-08-22 17:47:40 +00:00
|
|
|
this.funcs.logger = require("./client/funcs/logger.js");
|
2021-06-08 09:01:56 +00:00
|
|
|
this.funcs.msToTime = require("./client/funcs/msToTime.js");
|
|
|
|
this.funcs.statisticsUpdate = require("./client/funcs/statisticsUpdate.js");
|
2021-09-02 22:21:55 +00:00
|
|
|
this.funcs.saveState = require("./client/funcs/saveState.js");
|
|
|
|
this.funcs.loadState = require("./client/funcs/loadState.js");
|
2021-09-04 23:23:26 +00:00
|
|
|
this.funcs.searchStation = require("./client/funcs/searchStation.js");
|
2021-09-04 23:35:36 +00:00
|
|
|
this.funcs.play = require("./client/funcs/play.js");
|
2021-09-05 00:11:51 +00:00
|
|
|
this.funcs.listStations = require("./client/funcs/listStations.js");
|
2021-09-06 01:22:35 +00:00
|
|
|
this.funcs.restoreRadios = require("./client/funcs/restoreRadios.js");
|
|
|
|
this.funcs.saveRadios = require("./client/funcs/saveRadios.js");
|
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');
|
|
|
|
console.log('(c)2020-2021 EximiaBots by Warén Group');
|
|
|
|
console.log('');
|
|
|
|
|
|
|
|
this.funcs.logger("Bot", "Starting");
|
|
|
|
|
2021-09-09 15:55:42 +00:00
|
|
|
this.funcs.logger("Maintenance Mode", "Enabled");
|
|
|
|
this.config.maintenance = true;
|
|
|
|
|
2021-06-16 01:49:11 +00:00
|
|
|
const commandFiles = fs.readdirSync(path.join("./src/client/commands")).filter(f => f.endsWith(".js"));
|
2021-06-08 09:01:56 +00:00
|
|
|
for (const file of commandFiles) {
|
|
|
|
const command = require(`./client/commands/${file}`);
|
|
|
|
this.commands.set(command.name, command);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.on("ready", () => {
|
2021-08-28 08:07:47 +00:00
|
|
|
require(`${events}ready`).execute(this);
|
2021-06-08 09:01:56 +00:00
|
|
|
});
|
2021-09-02 09:07:08 +00:00
|
|
|
|
|
|
|
this.on("messageCreate", msg => {
|
|
|
|
require(`${events}messageCreate`).execute(this, msg);
|
|
|
|
});
|
|
|
|
|
2021-09-02 11:39:23 +00:00
|
|
|
this.on("messageDelete", msg => {
|
|
|
|
require(`${events}messageDelete`).execute(this, msg);
|
|
|
|
});
|
|
|
|
|
2021-08-18 22:50:35 +00:00
|
|
|
this.on("interactionCreate", interaction => {
|
2021-08-28 08:07:47 +00:00
|
|
|
require(`${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) => {
|
|
|
|
require(`${events}voiceStateUpdate`).execute(this, oldState, newState);
|
|
|
|
});
|
2021-09-09 09:44:50 +00:00
|
|
|
|
2021-09-09 22:21:42 +00:00
|
|
|
this.on("error", error => {
|
2021-09-09 22:44:21 +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', () => {
|
|
|
|
require(`${events}SIGINT`).execute(this);
|
|
|
|
});
|
2021-09-02 16:18:20 +00:00
|
|
|
|
|
|
|
process.on('SIGTERM', () => {
|
|
|
|
require(`${events}SIGTERM`).execute(this);
|
|
|
|
});
|
2021-09-06 19:35:49 +00:00
|
|
|
|
|
|
|
process.on('uncaughtException', (error) => {
|
|
|
|
require(`${events}uncaughtException`).execute(this, error);
|
|
|
|
});
|
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) => {
|
2021-09-09 22:44:21 +00:00
|
|
|
require(`${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) => {
|
|
|
|
this.funcs.logger("Discord Client / Error");
|
|
|
|
console.log(err);
|
|
|
|
console.log('');
|
|
|
|
});
|
2021-06-08 09:01:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-09 09:44:50 +00:00
|
|
|
export default RadioClient
|