mirror of
https://github.com/reality/dbot.git
synced 2024-11-27 22:39:26 +01:00
repair nunsub
This commit is contained in:
parent
83e5a35677
commit
84ddfb90a6
@ -36,37 +36,48 @@ var api = function(dbot) {
|
|||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
var offlineOps = {};
|
this.db.read('nunsubs', cName + '.' + server, function(err, nunsubs) {
|
||||||
async.each(ops, function(op, done) {
|
if(nunsubs) {
|
||||||
dbot.api.users.isOnline(server, cName, op, function(err, user, online) {
|
_.each(nunsubs.users, function(user) {
|
||||||
if(!err && !online) offlineOps[op] = user;
|
var uPart = user.split('.')[0];
|
||||||
if(user.currentNick !== op) {
|
if(_.include(ops, uPart)) {
|
||||||
ops = _.without(ops, op);
|
ops = _.without(ops, uPart);
|
||||||
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 +96,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', 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));
|
||||||
if(!_.include(nunsubs, event.rUser.id)) {
|
} else {
|
||||||
nunsubs.users.push(event.rUser.id);
|
event.reply(dbot.t('already_nunsubbed', { 'cName': cName }));
|
||||||
this.db.save('nunsubs', channel.id, nunsubs, function() {
|
}
|
||||||
var reply = dbot.t('nunsubbed', { 'cName': cName })
|
}.bind(this));
|
||||||
if(_.has(this.config.chan_redirs, cName)) {
|
} else {
|
||||||
reply += dbot.t('n_also_found', { 'afaName' : this.config.chan_redirs[cName] });
|
event.reply('Channel not known.');
|
||||||
}
|
}
|
||||||
event.reply(reply);
|
|
||||||
}.bind(this));
|
|
||||||
} else {
|
|
||||||
event.reply(dbot.t('already_nunsubbed', { 'cName': cName }));
|
|
||||||
}
|
|
||||||
}.bind(this));
|
|
||||||
} else {
|
|
||||||
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', 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