kara
Version:
A third generation EX-400 android
50 lines (37 loc) • 1.19 kB
JavaScript
var Whois = module.exports = function Whois(bot) {
function hook(msg) {
if (/^whois\b/.test(msg.body)) {
msg.tokens = msg.body.trim().split(/\s+/);
msg.query = msg.tokens[1];
if (!msg.query) {
return bot.reply(msg, "try whois <nick>");
}
bot.enqueue(function(next) { onWhois(msg, next) });
}
}
function onWhois(msg, next) {
function onWhoisUser(res) {
var str = [res.name, " is logged in as ", res.nick, " (", res.host, ")"].join("");
bot.reply(msg, str);
}
function onWhoisNotFound(res) {
var str = [res.nick, " is not logged in"].join("");
bot.reply(msg, str);
}
function onWhoisEnd(res) {
bot.removeListener("whois:user", onWhoisUser);
bot.removeListener("whois:notfound", onWhoisNotFound);
next();
}
bot.once("whois:user", onWhoisUser);
bot.once("whois:notfound", onWhoisNotFound);
bot.once("whois:end", onWhoisEnd);
bot.send("WHOIS", [msg.query]);
}
this.enable = function enable() {
bot.on("msg:direct", hook);
};
this.disable = function disable() {
bot.removeListener("msg:direct", hook);
};
};