From 28d9127059f2f1a58b780239312840cf4551d0e7 Mon Sep 17 00:00:00 2001 From: Hri7566 Date: Sun, 10 Sep 2023 01:33:17 -0400 Subject: [PATCH] Fix channel settings --- config/channels.yml | 2 +- src/channel/Channel.ts | 28 +++++++++++++++++++--------- src/util/config.ts | 3 +-- src/util/types.d.ts | 3 ++- 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/config/channels.yml b/config/channels.yml index cbf3088..e941206 100644 --- a/config/channels.yml +++ b/config/channels.yml @@ -6,9 +6,9 @@ lobbySettings: lobby: true chat: true crownsolo: false + visible: true color: "#eeeeee" color2: "#888888" - visible: true defaultSettings: chat: true diff --git a/src/channel/Channel.ts b/src/channel/Channel.ts index 6c11d9b..a5a0a85 100644 --- a/src/channel/Channel.ts +++ b/src/channel/Channel.ts @@ -49,19 +49,26 @@ export class Channel { // TODO Add the crown - constructor( - private _id: string, - set: Partial = config.defaultSettings - ) { + constructor(private _id: string, set?: Partial) { this.logger = new Logger("Channel - " + _id); - // Verify default settings just in case - this.changeSettings(this.settings, true); - if (this.isLobby()) { - set = config.lobbySettings; + // Validate settings in set + // Set the verified settings + + if (set && !this.isLobby()) { + const validatedSet = validateChannelSettings(set); + + for (const key in Object.keys(validatedSet)) { + if (!(validatedSet as any)[key]) continue; + + (this.settings as any)[key] = (set as any)[key]; + } } - this.changeSettings(set); + if (this.isLobby()) { + this.logger.debug(config.lobbySettings); + this.settings = config.lobbySettings; + } } public getID() { @@ -89,6 +96,8 @@ export class Channel { if (set.owner_id) set.owner_id = undefined; } + if (this.isLobby() && !admin) return; + // Verify settings const validSettings = validateChannelSettings(set); @@ -164,6 +173,7 @@ export class Channel { if (this.hasUser(part._id)) { this.ppl.splice(this.ppl.indexOf(part), 1); } + // TODO Broadcast channel update } diff --git a/src/util/config.ts b/src/util/config.ts index b45e11e..ad74b94 100644 --- a/src/util/config.ts +++ b/src/util/config.ts @@ -6,10 +6,9 @@ export function loadConfig(filepath: string, def: T) { const data = readFileSync(filepath).toString(); const parsed = YAML.parse(data); - return parsed as T || def; + return parsed as T; } catch (err) { console.error("Unable to load config:", err); - } finally { return def; } } diff --git a/src/util/types.d.ts b/src/util/types.d.ts index bdd8cc6..5503ec6 100644 --- a/src/util/types.d.ts +++ b/src/util/types.d.ts @@ -32,13 +32,14 @@ declare type ChannelSettings = { crownsolo: boolean; chat: boolean; visible: boolean; - limit: number; } & Partial<{ color2: string; lobby: boolean; owner_id: string; "lyrical notes": boolean; "no cussing": boolean; + + limit: number; noindex: boolean; }>;