Fix load of channels from user config

While the commits that caused the problem have been reverted,
this still adds test cases to it and make the loading more robust.
This commit is contained in:
Reto Brunner 2023-04-08 13:46:13 +02:00
commit 90ad06a29a
2 changed files with 119 additions and 7 deletions

View file

@ -6,7 +6,7 @@ import crypto from "crypto";
import colors from "chalk";
import log from "./log";
import Chan, {Channel, ChanType} from "./models/chan";
import Chan, {ChanConfig, Channel, ChanType} from "./models/chan";
import Msg, {MessageType, UserInMessage} from "./models/msg";
import Config from "./config";
import {condensedTypes} from "../shared/irc";
@ -251,11 +251,13 @@ class Client {
let channels: Chan[] = [];
if (Array.isArray(args.channels)) {
let badName = false;
let badChanConf = false;
args.channels.forEach((chan: Chan) => {
if (!chan.name) {
badName = true;
args.channels.forEach((chan: ChanConfig) => {
const type = ChanType[(chan.type || "channel").toUpperCase()];
if (!chan.name || !type) {
badChanConf = true;
return;
}
@ -263,13 +265,13 @@ class Client {
client.createChannel({
name: chan.name,
key: chan.key || "",
type: chan.type,
type: type,
muted: chan.muted,
})
);
});
if (badName && client.name) {
if (badChanConf && client.name) {
log.warn(
"User '" +
client.name +