From 24d14e70054d501a430abf8fe9fd0ec21c0ff184 Mon Sep 17 00:00:00 2001 From: reality Date: Fri, 5 Sep 2014 08:51:48 +0000 Subject: [PATCH] read flags --- modules/atheme/atheme.js | 45 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/modules/atheme/atheme.js b/modules/atheme/atheme.js index ba78e31..acb6732 100644 --- a/modules/atheme/atheme.js +++ b/modules/atheme/atheme.js @@ -5,6 +5,32 @@ var _ = require('underscore')._; var atheme = function(dbot) { + this.flagStack = {}; + + this.api = { + 'getChannelFlags': function(server, channel, callback) { + if(!_.has(this.flagStack, server)) this.flagStack[server] = {}; + if(_.has(flagStack[server], channel)) { // Already an active flag call + this.flagStack[server][channel].callbacks.push(callback); + } else { + this.flagStack[server][channel] = { + 'flags': {}, + 'callbacks': [ callback ] + }; + } + + dbot.say(server, 'chanserv', 'FLAGS ' + channel); + setTimeout(function() { // Delete callback if no response + if(_.has(this.flagStack[server], channel)) { + _.each(this.flagStack[server][channel].callbacks, function(callback) { + callback(true, null); + }); + delete this.flagStack[server][channel]; + } + }.bind(this), 10000); + } + }; + this.commands = { '~chanserv': function(event) { if(_.has(this.config.chanserv, event.input[1])) { @@ -24,6 +50,25 @@ var atheme = function(dbot) { }; this.commands['~chanserv'].regex = [/^chanserv (\+.)/, 2]; this.commands['~chanmode'].regex = [/^chanmode (\+.)/, 2]; + + this.listener = function(event) { + if(event.user === 'chanserv') { + var flags = event.message.match(/(\d+)\s+([^ ]+)\s+(\+\w+)\s+\((\#.+)\)/), + end = event.message.match(/End of (\#.+) FLAGS listing./); + + if(flags && _.has(this.flagStack[event.server], flags[4])) { + this.flagStack[event.server][flags[4]].flags[flags[2]] = flags[3]; + } else if(end) { + if(_.has(this.flagStack[event.server], end[1])) { + _.each(this.flagStack[event.server][end[1]].callbacks, function(callback) { + callback(null, this.flagStack[event.server][end[1]].flags); + }); + delete this.flagStack[event.server][end[1]]; + } + } + } + }.bind(this); + this.on = 'NOTICE'; }; exports.fetch = function(dbot) {