2022-02-02 11:46:42 +02:00
|
|
|
import { discordToken, watchedGuildIds } from "./config.js";
|
|
|
|
import DiscordClient from "./DiscordClient.js";
|
|
|
|
import WatchedGuild from "./WatchedGuild.js";
|
2022-02-01 03:49:12 +02:00
|
|
|
|
2022-02-02 11:46:42 +02:00
|
|
|
export const guildMap = new Map();
|
|
|
|
export const bot = new DiscordClient(discordToken, {
|
|
|
|
intents: 0 | (1 << 0) | (1 << 9) // GUILDS & GUILD_MESSAGES
|
2022-02-01 03:49:12 +02:00
|
|
|
});
|
|
|
|
|
2022-02-02 20:24:14 +02:00
|
|
|
export function wait(time, shouldReject=false) {
|
2022-02-02 11:46:42 +02:00
|
|
|
return new Promise((resolve, reject) => {
|
2022-02-02 20:24:14 +02:00
|
|
|
setTimeout(() => shouldReject ? reject() : resolve(), time);
|
2022-02-02 11:46:42 +02:00
|
|
|
});
|
|
|
|
}
|
2022-02-01 03:49:12 +02:00
|
|
|
|
2022-02-02 11:46:42 +02:00
|
|
|
bot.on("READY", () => {
|
2022-02-01 03:49:12 +02:00
|
|
|
watchedGuildIds.forEach(id => {
|
|
|
|
const watchedGuild = new WatchedGuild();
|
|
|
|
watchedGuild.upstreamGuildId = id;
|
|
|
|
watchedGuild.discordConnect(bot);
|
|
|
|
guildMap.set(id, watchedGuild);
|
|
|
|
});
|
|
|
|
});
|
2022-02-02 20:24:14 +02:00
|
|
|
|
|
|
|
bot.on("close", (code, reason) => {
|
|
|
|
console.log("bot: connection closed, reconnecting...");
|
|
|
|
bot.connect();
|
|
|
|
});
|