3
0
mirror of https://github.com/reality/dbot.git synced 2024-11-24 04:49:25 +01:00
This commit is contained in:
Luke Slater 2014-09-15 21:20:59 +00:00
commit f8bc0be366
2 changed files with 83 additions and 75 deletions

View File

@ -35,12 +35,21 @@ var api = function(dbot) {
return k; return k;
} }
}.bind(this)); }.bind(this));
this.db.read('nunsubs', cName + '.' + server, function(err, nunsubs) {
if(nunsubs) {
_.each(nunsubs.users, function(user) {
var uPart = user.split('.')[0];
if(_.include(ops, uPart)) {
ops = _.without(ops, uPart);
}
});
}
var offlineOps = {}; var offlineOps = {};
async.each(ops, function(op, done) { async.each(ops, function(op, done) {
dbot.api.users.isOnline(server, cName, op, function(err, user, online) { dbot.api.users.isOnline(server, cName, op, function(err, user, online) {
if(!err && !online) offlineOps[op] = user; if(!err && !online) offlineOps[op] = user;
if(user && user.currentNick !== op) { if(user.currentNick !== op) {
ops = _.without(ops, op); ops = _.without(ops, op);
ops.push(user.currentNick); ops.push(user.currentNick);
} }
@ -69,6 +78,7 @@ var api = function(dbot) {
} }
}.bind(this)); }.bind(this));
}.bind(this)); }.bind(this));
}.bind(this));
} else { } else {
var channel = dbot.instance.connections[server].channels[cName]; var channel = dbot.instance.connections[server].channels[cName];
var ops = _.filter(channel.nicks, function(user) { var ops = _.filter(channel.nicks, function(user) {
@ -85,7 +95,7 @@ var api = function(dbot) {
var perOps = channel.op; var perOps = channel.op;
if(this.config.notifyVoice) perOps = _.union(perOps, channel.voice); if(this.config.notifyVoice) perOps = _.union(perOps, channel.voice);
this.db.read('nunsubs', channel.id, function(err, nunsubs) { this.db.read('nunsubs', cName + '.' + server, function(err, nunsubs) {
async.eachSeries(ops, function(nick, next) { async.eachSeries(ops, function(nick, next) {
dbot.api.users.resolveUser(server, nick, function(user) { dbot.api.users.resolveUser(server, nick, function(user) {
if(nunsubs && _.include(nunsubs.users, user.id)) { if(nunsubs && _.include(nunsubs.users, user.id)) {

View File

@ -139,21 +139,21 @@ var commands = function(dbot) {
}, },
'~nunsub': function(event) { '~nunsub': function(event) {
var cName = event.input[1]; var cName = event.input[1],
cId = event.input[1] + '.' + event.server;
dbot.api.users.resolveChannel(event.server, cName, function(channel) { if(_.has(dbot.instance.connections[event.server].channels, cName)) {
if(channel) { this.db.read('nunsubs', cId, function(err, nunsubs) {
this.db.read('nunsubs', channel.id, function(err, nunsubs) {
if(!nunsubs) { if(!nunsubs) {
var nunsubs = { var nunsubs = {
'id': channel.id, 'id': cId,
'users': [] 'users': []
} }
} }
if(!_.include(nunsubs, event.rUser.id)) { if(!_.include(nunsubs, event.rUser.id)) {
nunsubs.users.push(event.rUser.id); nunsubs.users.push(event.rUser.id);
this.db.save('nunsubs', channel.id, nunsubs, function() { this.db.save('nunsubs', cId, nunsubs, function() {
var reply = dbot.t('nunsubbed', { 'cName': cName }) var reply = dbot.t('nunsubbed', { 'cName': cName })
if(_.has(this.config.chan_redirs, cName)) { if(_.has(this.config.chan_redirs, cName)) {
reply += dbot.t('n_also_found', { 'afaName' : this.config.chan_redirs[cName] }); reply += dbot.t('n_also_found', { 'afaName' : this.config.chan_redirs[cName] });
@ -167,18 +167,17 @@ var commands = function(dbot) {
} else { } else {
event.reply('Channel not known.'); event.reply('Channel not known.');
} }
}.bind(this));
}, },
'~ununsub': function(event) { '~ununsub': function(event) {
var cName = event.input[1]; var cName = event.input[1],
cId = event.input[1] + '.' + event.server;
dbot.api.users.resolveChannel(event.server, cName, function(channel) { if(_.has(dbot.instance.connections[event.server].channels, cName)) {
if(channel) { this.db.read('nunsubs', cId, function(err, nunsubs) {
this.db.read('nunsubs', channel.id, function(err, nunsubs) {
if(!_.isUndefined(nunsubs) && _.include(nunsubs.users, event.rUser.id)) { if(!_.isUndefined(nunsubs) && _.include(nunsubs.users, event.rUser.id)) {
nunsubs.users = _.without(nunsubs.users, event.rUser.id); nunsubs.users = _.without(nunsubs.users, event.rUser.id);
this.db.save('nunsubs', channel.id, nunsubs, function() { this.db.save('nunsubs', cId, nunsubs, function() {
event.reply(dbot.t('ununsubbed', { 'cName': cName })); event.reply(dbot.t('ununsubbed', { 'cName': cName }));
}); });
} else { } else {
@ -188,7 +187,6 @@ var commands = function(dbot) {
} else { } else {
event.reply('Channel not known.'); event.reply('Channel not known.');
} }
}.bind(this));
} }
}; };
commands['~report'].regex = /^report (#[^ ]+ )?([^ ]+) (.*)$/; commands['~report'].regex = /^report (#[^ ]+ )?([^ ]+) (.*)$/;