Method code for $channel_ui.channels_cmd()

[Turn on line numbering]
arg cmdstr, cmd, args;
var opts, f, d, cur_channels, cd_keys, cd_values, i, alias, db, active, msg, match_with, match_pattern, tmp, form, add, o;

(> .perms(caller(), 'command) <);
[args, opts] = args;
o = opts.slice(1);
if ((f = (| "f?ull" in o |)))
    f = opts[f][3];
if ((d = (| "d?etailed" in o |)))
    d = opts[d][3];
if (listlen(args) > 1) {
    catch any {
        cmd = (| ($channel_db.search(args[1]))[1] |);
        return .channel_members(cmd, f);
    } with {
        return traceback()[1][2];
    }
}
cd_keys = channel_dict.keys();
cd_values = channel_dict.values();
cur_channels = f ? $channel_db.database().values().slice(1) : cd_values;
if (args) {
    match_with = (| .get_setting("match-with", $programmer) |) || 'match_pattern;
    match_pattern = (| args[1][1] |) || (| .get_setting("match-default", $programmer) |) || "*";
    cur_channels = filter f in (cur_channels) where (f.to_string().(match_with)(match_pattern) != 0);
}
if (!cur_channels)
    return "No channels found.";
msg = [];
add = [];
for i in (cur_channels) {
    alias = (| cd_keys[i in cd_values] |) || "";
    db = (| $channel_db.search(tostr(i)) |);
    if (type(db) == 'list) {
        msg += [[active_channels.contains(i) ? "*" : " ", alias, tostr(db[1]), db[7] || "<no description>"]];
        form = "%26r: %50l";
        if (d) {
            tmp = [form.format("Number of users", tostr(db[2])), form.format("Owner", db[5].name()), form.format("Managers", db[6].mmap('namef, 'name).to_english())];
            if (db[3])
                tmp += [form.format("Join Lock", db[3].lock_name())];
            if (db[4])
                tmp += [form.format("Leave Lock", db[4].lock_name())];
            if (db[8])
                tmp += [form.format("Use Lock", db[8].lock_name())];
            add += [tmp];
        }
    } else {
        msg += [[active_channels.contains(i) ? "*" : " ", alias, "", "Channel not in database!"]];
    }
    refresh();
}
msg = msg.transpose().tabulate([["", ""], ["Alias", "-----"], ["Channel", "-------"], ["Description", "-----------"]]);
if (d)
    msg = [msg[1], msg[2], @map i in [3 .. msg.length()] to ([msg[i]] + add[i - 2]).sum()];
return [@msg, "   -----"];

// Created 24-Jul-1996 as a part of ColdCore, see: @help Credit

Tlon