Base utilities, add README, Redis, Discord integration, db keygroup planning
This commit is contained in:
34
src/discord.ts
Normal file
34
src/discord.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import * as discord from "discord.js";
|
||||
import { Config } from "./config.ts";
|
||||
import Logging from "@proxnet/undead-logging";
|
||||
import process from "node:process";
|
||||
|
||||
const log = new Logging("Discord");
|
||||
|
||||
const config = Config.getConfig();
|
||||
if (typeof config == 'undefined') {
|
||||
log.e(`Cannot start: Discord configuration is unavailable`);
|
||||
process.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";
|
||||
Reference in New Issue
Block a user