all repos — stealth-developers @ 039ea63e339048b4103f508452368b3563a04188

src/index.ts (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
import { Client, Events, GatewayIntentBits } from "discord.js";

import { connectDatabase } from "./database/connection";
import registerEvents from "./handlers/events.ts";
import registerInteractions from "./handlers/interactions.ts";

import config from "./config.ts";
import { watchForum } from "./utils/forumWatcher.ts";
import logger from "./utils/logging.ts";

const client = new Client({
	intents: [
		GatewayIntentBits.GuildMessages,
		GatewayIntentBits.Guilds,
		GatewayIntentBits.MessageContent,
	],
});

client.on(Events.ClientReady, async (client) => {
	logger.info(`logged in as ${client.user?.tag}!`);

	await connectDatabase();
	await Promise.all([registerEvents(client), registerInteractions(client)]);
	logger.info("events and interactions registered!");
	console.log();

	const forumConfig = config.data.roblox?.forumWatcher;
	const forumChannels = forumConfig?.channels ?? [];
	if (!forumConfig || !forumConfig.enabled) return;
	await watchForum(client);
	setInterval(
		() => {
			watchForum(client).catch((error) => {
				logger.error("error while watching forum:", error);
			});
		},
		forumConfig.interval * 1000 || 60000,
	);
});

await client.login(config.data.discord.token);

process.on("unhandledRejection", (error) => {
	logger.error("unhandled promise rejection:", error);
});

process.on("uncaughtException", (error) => {
	logger.error("uncaught exception:", error);
});