mirror of
https://github.com/reality/dbot.git
synced 2024-11-24 04:49:25 +01:00
whoops
This commit is contained in:
commit
f8bc0be366
@ -35,38 +35,48 @@ var api = function(dbot) {
|
|||||||
return k;
|
return k;
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
this.db.read('nunsubs', cName + '.' + server, function(err, nunsubs) {
|
||||||
var offlineOps = {};
|
if(nunsubs) {
|
||||||
async.each(ops, function(op, done) {
|
_.each(nunsubs.users, function(user) {
|
||||||
dbot.api.users.isOnline(server, cName, op, function(err, user, online) {
|
var uPart = user.split('.')[0];
|
||||||
if(!err && !online) offlineOps[op] = user;
|
if(_.include(ops, uPart)) {
|
||||||
if(user && user.currentNick !== op) {
|
ops = _.without(ops, uPart);
|
||||||
ops = _.without(ops, op);
|
}
|
||||||
ops.push(user.currentNick);
|
|
||||||
}
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
}, function() {
|
|
||||||
// Queue notifies for offline ops
|
|
||||||
_.each(offlineOps, function(op) {
|
|
||||||
if(!this.pending[op.id]) this.pending[op.id] = [];
|
|
||||||
this.pending[op.id].push({
|
|
||||||
'time': new Date().getTime(),
|
|
||||||
'channel': cName,
|
|
||||||
'user': user.id,
|
|
||||||
'message': message
|
|
||||||
});
|
});
|
||||||
this.pNotify[op.id] = true;
|
|
||||||
}, this);
|
|
||||||
|
|
||||||
// Send notifies to online ops
|
|
||||||
ops = _.difference(ops, _.keys(offlineOps));
|
|
||||||
message = this.internalAPI.formatNotify(type, server,
|
|
||||||
user, cName, message);
|
|
||||||
this.internalAPI.notify(server, ops, message);
|
|
||||||
if(_.has(this.config.chan_redirs, cName)) {
|
|
||||||
dbot.say(server, this.config.chan_redirs[cName], message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var offlineOps = {};
|
||||||
|
async.each(ops, function(op, done) {
|
||||||
|
dbot.api.users.isOnline(server, cName, op, function(err, user, online) {
|
||||||
|
if(!err && !online) offlineOps[op] = user;
|
||||||
|
if(user.currentNick !== op) {
|
||||||
|
ops = _.without(ops, op);
|
||||||
|
ops.push(user.currentNick);
|
||||||
|
}
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
}, function() {
|
||||||
|
// Queue notifies for offline ops
|
||||||
|
_.each(offlineOps, function(op) {
|
||||||
|
if(!this.pending[op.id]) this.pending[op.id] = [];
|
||||||
|
this.pending[op.id].push({
|
||||||
|
'time': new Date().getTime(),
|
||||||
|
'channel': cName,
|
||||||
|
'user': user.id,
|
||||||
|
'message': message
|
||||||
|
});
|
||||||
|
this.pNotify[op.id] = true;
|
||||||
|
}, this);
|
||||||
|
|
||||||
|
// Send notifies to online ops
|
||||||
|
ops = _.difference(ops, _.keys(offlineOps));
|
||||||
|
message = this.internalAPI.formatNotify(type, server,
|
||||||
|
user, cName, message);
|
||||||
|
this.internalAPI.notify(server, ops, message);
|
||||||
|
if(_.has(this.config.chan_redirs, cName)) {
|
||||||
|
dbot.say(server, this.config.chan_redirs[cName], message);
|
||||||
|
}
|
||||||
|
}.bind(this));
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
} else {
|
} else {
|
||||||
@ -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)) {
|
||||||
|
@ -139,56 +139,54 @@ 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': cId,
|
||||||
'id': channel.id,
|
'users': []
|
||||||
'users': []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!_.include(nunsubs, event.rUser.id)) {
|
|
||||||
nunsubs.users.push(event.rUser.id);
|
|
||||||
this.db.save('nunsubs', channel.id, nunsubs, function() {
|
|
||||||
var reply = dbot.t('nunsubbed', { 'cName': cName })
|
|
||||||
if(_.has(this.config.chan_redirs, cName)) {
|
|
||||||
reply += dbot.t('n_also_found', { 'afaName' : this.config.chan_redirs[cName] });
|
|
||||||
}
|
|
||||||
event.reply(reply);
|
|
||||||
}.bind(this));
|
|
||||||
} else {
|
|
||||||
event.reply(dbot.t('already_nunsubbed', { 'cName': cName }));
|
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}
|
||||||
} else {
|
|
||||||
event.reply('Channel not known.');
|
if(!_.include(nunsubs, event.rUser.id)) {
|
||||||
}
|
nunsubs.users.push(event.rUser.id);
|
||||||
}.bind(this));
|
this.db.save('nunsubs', cId, nunsubs, function() {
|
||||||
|
var reply = dbot.t('nunsubbed', { 'cName': cName })
|
||||||
|
if(_.has(this.config.chan_redirs, cName)) {
|
||||||
|
reply += dbot.t('n_also_found', { 'afaName' : this.config.chan_redirs[cName] });
|
||||||
|
}
|
||||||
|
event.reply(reply);
|
||||||
|
}.bind(this));
|
||||||
|
} else {
|
||||||
|
event.reply(dbot.t('already_nunsubbed', { 'cName': cName }));
|
||||||
|
}
|
||||||
|
}.bind(this));
|
||||||
|
} else {
|
||||||
|
event.reply('Channel not known.');
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
'~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', cId, nunsubs, function() {
|
||||||
this.db.save('nunsubs', channel.id, nunsubs, function() {
|
event.reply(dbot.t('ununsubbed', { 'cName': cName }));
|
||||||
event.reply(dbot.t('ununsubbed', { 'cName': cName }));
|
});
|
||||||
});
|
} else {
|
||||||
} else {
|
event.reply(dbot.t('not_nunsubbed', { 'cName': cName }));
|
||||||
event.reply(dbot.t('not_nunsubbed', { 'cName': cName }));
|
}
|
||||||
}
|
}.bind(this));
|
||||||
}.bind(this));
|
} else {
|
||||||
} else {
|
event.reply('Channel not known.');
|
||||||
event.reply('Channel not known.');
|
}
|
||||||
}
|
|
||||||
}.bind(this));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
commands['~report'].regex = /^report (#[^ ]+ )?([^ ]+) (.*)$/;
|
commands['~report'].regex = /^report (#[^ ]+ )?([^ ]+) (.*)$/;
|
||||||
|
Loading…
Reference in New Issue
Block a user