Fix broken IRC servers with /list

This commit is contained in:
Maxime Poulin 2016-05-28 22:07:34 -04:00
parent 1d47290ada
commit 0f439545d4
4 changed files with 14 additions and 6 deletions

View File

@ -47,6 +47,7 @@ var inputs = [
"quit",
"raw",
"topic",
"list",
].reduce(function(plugins, name) {
var path = "./plugins/inputs/" + name;
var plugin = require(path);

View File

@ -23,6 +23,7 @@ function Network(attr) {
serverOptions: {
PREFIX: [],
},
chanCache: [],
}, attr));
this.name = attr.name || prettify(attr.host);
this.channels.unshift(

View File

@ -0,0 +1,7 @@
exports.commands = ["list"];
exports.input = function(network, chan, cmd, args) {
network.chanCache = [];
network.irc.list(args);
return true;
};

View File

@ -3,11 +3,10 @@ var Msg = require("../../models/msg");
module.exports = function(irc, network) {
var client = this;
var chanCache = {};
var MAX_CHANS = 1000;
irc.on("channel list start", function() {
chanCache[network.id] = [];
network.chanCache = [];
updateListStatus(new Msg({
text: "Loading channel list, this can take a moment...",
@ -16,23 +15,23 @@ module.exports = function(irc, network) {
});
irc.on("channel list", function(channels) {
Array.prototype.push.apply(chanCache[network.id], channels);
Array.prototype.push.apply(network.chanCache, channels);
});
irc.on("channel list end", function() {
updateListStatus(new Msg({
type: "channel_list",
channels: chanCache[network.id].slice(0, MAX_CHANS)
channels: network.chanCache.slice(0, MAX_CHANS)
}));
if (chanCache[network.id].length > MAX_CHANS) {
if (network.chanCache.length > MAX_CHANS) {
updateListStatus(new Msg({
type: "channel_list_truncated",
text: "Channel list is too large: truncated to " + MAX_CHANS + " channels."
}));
}
chanCache[network.id] = [];
network.chanCache = [];
});
function updateListStatus(msg) {