import { discordToken, logContextMap, watchedGuildIds } from "./config.js"; import DiscordClient from "./DiscordClient.js"; import WatchedGuild from "./WatchedGuild.js"; export const guildMap = new Map(); export const bot = new DiscordClient(discordToken, { intents: 0 | (1 << 0) | (1 << 9) // GUILDS & GUILD_MESSAGES }); export function wait(time, shouldReject=false) { return new Promise((resolve, reject) => { setTimeout(() => shouldReject ? reject() : resolve(), time); }); } export function logger(sink, context) { let sinkFunction; switch (sink) { case "log": { sinkFunction = console.log; break; } case "warn": { sinkFunction = console.warn; break; } case "error": { sinkFunction = console.error; break; } default: { sinkFunction = () => {}; break; } } if (logContextMap[context] && logContextMap[context][sink]) { return (...e) => { sinkFunction(`[${context}]`, ...e); }; } else { return (...e) => {}; } } bot.once("READY", () => { watchedGuildIds.forEach(id => { const watchedGuild = new WatchedGuild(); watchedGuild.upstreamGuildId = id; watchedGuild.discordConnect(bot); guildMap.set(id, watchedGuild); }); });