Fix channel settings

This commit is contained in:
Hri7566 2023-09-10 01:33:17 -04:00
parent c835d4611a
commit 28d9127059
4 changed files with 23 additions and 13 deletions

View File

@ -6,9 +6,9 @@ lobbySettings:
lobby: true
chat: true
crownsolo: false
visible: true
color: "#eeeeee"
color2: "#888888"
visible: true
defaultSettings:
chat: true

View File

@ -49,19 +49,26 @@ export class Channel {
// TODO Add the crown
constructor(
private _id: string,
set: Partial<ChannelSettings> = config.defaultSettings
) {
constructor(private _id: string, set?: Partial<ChannelSettings>) {
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
}

View File

@ -6,10 +6,9 @@ export function loadConfig<T>(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;
}
}

3
src/util/types.d.ts vendored
View File

@ -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;
}>;