2023-08-19 16:56:22 +01:00
|
|
|
import * as dotenv from "dotenv";
|
|
|
|
import { CoreClient } from "./client/client";
|
|
|
|
import { IntentsBitField } from "discord.js";
|
|
|
|
import Registry from "./registry";
|
2023-11-10 18:32:08 +00:00
|
|
|
import { existsSync } from "fs";
|
|
|
|
import { ExecException, exec } from "child_process";
|
2023-08-19 16:56:22 +01:00
|
|
|
|
|
|
|
dotenv.config();
|
|
|
|
|
|
|
|
const requiredConfigs: string[] = [
|
|
|
|
"BOT_TOKEN",
|
|
|
|
"BOT_VER",
|
|
|
|
"BOT_AUTHOR",
|
|
|
|
"BOT_OWNERID",
|
|
|
|
"BOT_CLIENTID",
|
2023-10-14 17:07:28 +01:00
|
|
|
"BOT_ENV",
|
2023-12-29 19:51:59 +00:00
|
|
|
"DATA_DIR",
|
2023-08-19 16:56:22 +01:00
|
|
|
"DB_HOST",
|
|
|
|
"DB_PORT",
|
|
|
|
"DB_AUTH_USER",
|
|
|
|
"DB_AUTH_PASS",
|
|
|
|
"DB_SYNC",
|
|
|
|
"DB_LOGGING",
|
2023-11-03 19:35:49 +00:00
|
|
|
"EXPRESS_PORT",
|
2023-11-10 18:32:08 +00:00
|
|
|
"GDRIVESYNC_WHITELIST",
|
2023-08-19 16:56:22 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
requiredConfigs.forEach(config => {
|
|
|
|
if (!process.env[config]) {
|
|
|
|
throw `${config} is required in .env`;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const client = new CoreClient([
|
|
|
|
IntentsBitField.Flags.Guilds,
|
|
|
|
IntentsBitField.Flags.GuildMembers,
|
|
|
|
]);
|
|
|
|
|
|
|
|
Registry.RegisterCommands();
|
|
|
|
Registry.RegisterEvents();
|
2023-09-03 20:27:29 +01:00
|
|
|
Registry.RegisterButtonEvents();
|
2023-08-19 16:56:22 +01:00
|
|
|
|
2023-12-29 19:51:59 +00:00
|
|
|
if (!existsSync(`${process.env.DATA_DIR}/cards`) && process.env.GDRIVESYNC_AUTO && process.env.GDRIVESYNC_AUTO == 'true') {
|
2023-11-10 18:32:08 +00:00
|
|
|
console.log("Card directory not found, syncing...");
|
|
|
|
|
|
|
|
CoreClient.AllowDrops = false;
|
|
|
|
|
|
|
|
exec(`rclone sync card-drop-gdrive: ${process.cwd()}/cards`, async (error: ExecException | null) => {
|
|
|
|
if (error) {
|
|
|
|
console.error(error.code);
|
|
|
|
throw `Error while running sync command. Code: ${error.code}`;
|
|
|
|
} else {
|
|
|
|
console.log('Synced successfully.');
|
|
|
|
CoreClient.AllowDrops = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-08-19 16:56:22 +01:00
|
|
|
client.start();
|