From 2d761347a7b4c3673c36c977bf89c2c7150fd533 Mon Sep 17 00:00:00 2001 From: Jeremy <51220084+jeremy-rifkin@users.noreply.github.com> Date: Sun, 30 Jul 2023 14:08:20 -0400 Subject: [PATCH] Dynamically import config --- src/components/server-suggestion-reactions.ts | 9 +++++++-- src/utils.ts | 9 +++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/components/server-suggestion-reactions.ts b/src/components/server-suggestion-reactions.ts index e3e15fe5..1a093088 100644 --- a/src/components/server-suggestion-reactions.ts +++ b/src/components/server-suggestion-reactions.ts @@ -1,13 +1,14 @@ import * as Discord from "discord.js"; import { strict as assert } from "assert"; import { is_root, MINUTE, server_suggestions_channel_id, suggestion_dashboard_thread_id } from "../common.js"; -import { delay, M } from "../utils.js"; +import { delay, file_exists, M } from "../utils.js"; import { TRACKER_START_TIME } from "./server-suggestion-tracker.js"; import { forge_snowflake } from "./snowflake.js"; -import { react_blacklist } from "../config.js"; import { BotComponent } from "../bot-component.js"; import { Wheatley } from "../wheatley.js"; +let react_blacklist = new Set(); + const root_only_reacts = new Set([ "🟢", "🔴", "🟡", "🔵", "🟩", "🟥", "🟨", @@ -98,6 +99,10 @@ export default class ServerSuggestionReactions extends BotComponent { } override async on_ready() { + if(await file_exists("src/config.ts")) { + const config = "../config.js"; + react_blacklist = (await import(config)).react_blacklist; + } for(const channel_id of monitored_channels_ids) { const channel = await this.wheatley.client.channels.fetch(channel_id); assert(channel && (channel instanceof Discord.TextChannel || channel instanceof Discord.ThreadChannel)); diff --git a/src/utils.ts b/src/utils.ts index 40706711..fcd83095 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -515,3 +515,12 @@ export async function directory_exists(path: string) { return false; } } + +export async function file_exists(path: string) { + try { + const stats = await fs.promises.stat(path); + return stats.isFile(); + } catch(error) { + return false; + } +}