From 0f439545d48b14fea1b5dd71c274391d34813ec2 Mon Sep 17 00:00:00 2001 From: Maxime Poulin Date: Sat, 28 May 2016 22:07:34 -0400 Subject: [PATCH] Fix broken IRC servers with /list --- src/client.js | 1 + src/models/network.js | 1 + src/plugins/inputs/list.js | 7 +++++++ src/plugins/irc-events/list.js | 11 +++++------ 4 files changed, 14 insertions(+), 6 deletions(-) create mode 100644 src/plugins/inputs/list.js diff --git a/src/client.js b/src/client.js index 28c4da3d..0f46db1e 100644 --- a/src/client.js +++ b/src/client.js @@ -47,6 +47,7 @@ var inputs = [ "quit", "raw", "topic", + "list", ].reduce(function(plugins, name) { var path = "./plugins/inputs/" + name; var plugin = require(path); diff --git a/src/models/network.js b/src/models/network.js index 65303756..cbeea7d4 100644 --- a/src/models/network.js +++ b/src/models/network.js @@ -23,6 +23,7 @@ function Network(attr) { serverOptions: { PREFIX: [], }, + chanCache: [], }, attr)); this.name = attr.name || prettify(attr.host); this.channels.unshift( diff --git a/src/plugins/inputs/list.js b/src/plugins/inputs/list.js new file mode 100644 index 00000000..70a4a65f --- /dev/null +++ b/src/plugins/inputs/list.js @@ -0,0 +1,7 @@ +exports.commands = ["list"]; + +exports.input = function(network, chan, cmd, args) { + network.chanCache = []; + network.irc.list(args); + return true; +}; diff --git a/src/plugins/irc-events/list.js b/src/plugins/irc-events/list.js index 66c482a1..db6fdd3c 100644 --- a/src/plugins/irc-events/list.js +++ b/src/plugins/irc-events/list.js @@ -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) {