33 lines
1003 B
TypeScript
33 lines
1003 B
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 (shuttingDown) return;
|
|
shuttingDown = true;
|
|
log.n('Disconnecting from Discord');
|
|
client.destroy();
|
|
});
|
|
|
|
export function login() {
|
|
log.i(`Creating Discord connection..`);
|
|
client.login(config?.discord.token);
|
|
}
|
|
|
|
export * as Discord from "./discord.ts"; |