Skip to content

Commit

Permalink
Dynamically import config
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-rifkin committed Jul 30, 2023
1 parent be026cf commit 2902e48
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/components/server-suggestion-reactions.ts
Original file line number Diff line number Diff line change
@@ -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<string>();

const root_only_reacts = new Set([
"🟢", "🔴", "🟡", "🔵",
"🟩", "🟥", "🟨",
Expand Down Expand Up @@ -98,6 +99,9 @@ export default class ServerSuggestionReactions extends BotComponent {
}

override async on_ready() {
if(await file_exists("src/config.ts")) {
react_blacklist = (await import("../config.js")).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));
Expand Down
9 changes: 9 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 2902e48

Please sign in to comment.