Include resource directory Ran `deno fmt` with 4 space indent, that changed every file (!!!!!) various changes
46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
import * as discord from "discord.js";
|
|
import { Config } from "./config.ts";
|
|
import Logging from "@proxnet/undead-logging";
|
|
|
|
const log = new Logging("Discord");
|
|
|
|
const config = Config.getConfig();
|
|
if (typeof config == "undefined") {
|
|
log.e(`Cannot start: Discord configuration is unavailable`);
|
|
Deno.exit(1);
|
|
}
|
|
|
|
export const client = new discord.Client({
|
|
intents: [
|
|
discord.GatewayIntentBits.Guilds,
|
|
discord.GatewayIntentBits.GuildPresences,
|
|
],
|
|
});
|
|
|
|
client.once(discord.Events.ClientReady, (client) => {
|
|
log.i(`Logged in to Discord as "${client.user.tag}"`);
|
|
client.user?.setActivity(config.public.motd, {
|
|
type: discord.ActivityType.Custom,
|
|
});
|
|
});
|
|
|
|
let shuttingDown = false;
|
|
Deno.addSignalListener("SIGINT", () => {
|
|
if (client.readyTimestamp == null) return;
|
|
if (shuttingDown) return;
|
|
shuttingDown = true;
|
|
log.n("Disconnecting from Discord");
|
|
client.destroy();
|
|
});
|
|
|
|
export function login() {
|
|
if (config.discord?.token == Config.defaultConfig.discord?.token) {
|
|
log.i("Discord not configured, ignoring");
|
|
return;
|
|
}
|
|
log.i(`Creating Discord connection..`);
|
|
client.login(config.discord?.token);
|
|
}
|
|
|
|
export * as Discord from "./discord.ts";
|