kiwiirc / irc-framework

🛠️ A better IRC framework for node.js. For bots and full clients.
MIT License
181 stars 63 forks source link

Customize an RPL_WHOSPCRPL for UnrealIRCd 5 #317

Closed Madriix closed 1 year ago

Madriix commented 2 years ago

Hi,

Since around 2015/2016 I have been using several irc-frameworks in productions, which are:

For this second, every time there is an update, I delete the whole "irc framework" folder and install the new version again, then put my "bots" folder back inside. Each time I have to modify this file: https://github.com/kiwiirc/irc-framework/blob/master/src/commands/handlers/misc.js#L111

    RPL_WHOSPCRPL: function(command, handler) {
        const cache = handler.cache('who');
        if (!cache.members) {
            cache.members = [];
        }
        const params = command.params;

        // G = Gone, H = Here
        const is_away = params[6][0].toUpperCase() === 'G';

        // get user channel modes
        const net_prefixes = handler.network.options.PREFIX;
        // filter PREFIX array against the prefix's in who reply returning matched PREFIX objects
        const chan_prefixes = net_prefixes.filter(f => params[6].indexOf(f.symbol) > -1);
        // use _.map to return an array of mode strings from matched PREFIX objects
        const chan_modes = _.map(chan_prefixes, 'mode');

        // Some ircd's use n/a for no level, unify them all to 0 for no level
        const op_level = !/^[0-9]+$/.test(params[9]) ? 0 : parseInt(params[9], 10);

        cache.members.push({
            nick: params[5],
            ident: params[2],
            hostname: params[3],
            server: params[4],
            op_level: op_level,
            real_name: params[10],
            account: params[8] === '0' ? '' : params[8],
            away: is_away,
            num_hops_away: parseInt(params[7], 10),
            channel: params[1],
            channel_modes: chan_modes,
            tags: command.tags
        });
    },

by this one (which is compatible with UnrealIRCd 5):

    RPL_WHOSPCRPL: function(command, handler) {
        const cache = handler.cache('who');
        if (!cache.members) {
            cache.members = [];
        }
        const params = command.params;

        // G = Gone, H = Here
        const is_away = params[7][0].toUpperCase() === 'G';

        // get user channel modes
        const net_prefixes = handler.network.options.PREFIX;
        // filter PREFIX array against the prefix's in who reply returning matched PREFIX objects
        const chan_prefixes = net_prefixes.filter(f => params[7].indexOf(f.symbol) > -1);
        // use _.map to return an array of mode strings from matched PREFIX objects
        const chan_modes = _.map(chan_prefixes, 'mode');

        // Some ircd's use n/a for no level, unify them all to 0 for no level
        const op_level = !/^[0-9]+$/.test(params[11]) ? 0 : parseInt(params[11], 10);

        cache.members.push({
            nick: params[6],
            ident: params[2],
            hostname: params[4],
            server: params[5],
            op_level: op_level,
            real_name: params[12],
            account: params[10] === '0' ? '' : params[10],
            away: is_away,
            num_hops_away: parseInt(params[8], 10),
            channel: params[1],
            channel_modes: chan_modes,
            tags: command.tags,
            idle: params[9],
            ip: params[3]
        });
    },

I am using this: bot.raw('WHO * %cuhsnfdaorli'); a bot retrieves the idle (time)

is there a system to avoid restoring this every time when updating? It would have to be the default maybe or I don't know.

Cdt

ItsOnlyBinary commented 1 year ago

Here is an example of using middleware and overloading of bot.raw() to intercept outgoing who messages and implement a modified parser for the replies. https://gist.github.com/ItsOnlyBinary/0e677815b89bf73c3f753925f7aca028

Note that this code is written for master which includes whox parsing changes that are not yet in a release.