2013-10-28 17:44:37 +01:00
|
|
|
/**
|
|
|
|
* Module Name: charybdis
|
|
|
|
* Description: charybdis and atheme mode references
|
|
|
|
*/
|
|
|
|
var _ = require('underscore')._;
|
|
|
|
|
2014-09-04 17:26:28 +02:00
|
|
|
var atheme = function(dbot) {
|
2014-09-05 10:51:48 +02:00
|
|
|
this.flagStack = {};
|
|
|
|
|
|
|
|
this.api = {
|
|
|
|
'getChannelFlags': function(server, channel, callback) {
|
|
|
|
if(!_.has(this.flagStack, server)) this.flagStack[server] = {};
|
2014-09-05 11:15:05 +02:00
|
|
|
if(_.has(this.flagStack[server], channel)) { // Already an active flag call
|
2014-09-05 10:51:48 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-10-28 17:44:37 +01:00
|
|
|
this.commands = {
|
|
|
|
'~chanserv': function(event) {
|
|
|
|
if(_.has(this.config.chanserv, event.input[1])) {
|
|
|
|
event.reply('ChanServ flag ' + event.input[1] + ': ' + this.config.chanserv[event.input[1]]);
|
|
|
|
} else {
|
|
|
|
event.reply('I don\'t know anything about ' + event.input[1]);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
'~chanmode': function(event) {
|
|
|
|
if(_.has(this.config.chanmodes, event.input[1])) {
|
|
|
|
event.reply('Channel Mode ' + event.input[1] + ': ' + this.config.chanmodes[event.input[1]]);
|
|
|
|
} else {
|
|
|
|
event.reply('I don\'t know anything about ' + event.input[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2014-09-04 17:26:28 +02:00
|
|
|
this.commands['~chanserv'].regex = [/^chanserv (\+.)/, 2];
|
|
|
|
this.commands['~chanmode'].regex = [/^chanmode (\+.)/, 2];
|
2014-09-05 10:51:48 +02:00
|
|
|
|
|
|
|
this.listener = function(event) {
|
2014-09-05 11:15:05 +02:00
|
|
|
if(event.user === 'ChanServ') {
|
|
|
|
var flags = event.params.match(/(\d+)\s+([^ ]+)\s+(\+\w+)\s+\((\#\w+)\)/),
|
|
|
|
end = event.params.match(/end of \u0002(\#\w+)\u0002 flags listing/i);
|
2014-09-05 10:51:48 +02:00
|
|
|
|
|
|
|
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);
|
2014-09-05 11:15:05 +02:00
|
|
|
}.bind(this));
|
2014-09-05 10:51:48 +02:00
|
|
|
delete this.flagStack[event.server][end[1]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}.bind(this);
|
|
|
|
this.on = 'NOTICE';
|
2013-10-28 17:44:37 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.fetch = function(dbot) {
|
2014-09-04 17:26:28 +02:00
|
|
|
return new atheme(dbot);
|
2013-10-28 17:44:37 +01:00
|
|
|
};
|