forked from GitHub/dbot
report report (it works)
This commit is contained in:
parent
7cb53a8b5a
commit
8c5e871640
@ -24,53 +24,101 @@ var api = function(dbot) {
|
||||
});
|
||||
|
||||
var channel = dbot.instance.connections[server].channels[cName];
|
||||
var ops = _.filter(channel.nicks, function(user) {
|
||||
if(this.config.notifyVoice) {
|
||||
return user.op || user.voice;
|
||||
} else {
|
||||
return user.op;
|
||||
}
|
||||
}, this);
|
||||
ops = _.pluck(ops, 'name');
|
||||
if(_.has(dbot.modules, 'atheme')) {
|
||||
dbot.api.atheme.getChannelFlags(server, cName, function(err, flags) {
|
||||
var ops = _.map(flags, function(f, k) {
|
||||
var staff = (f.indexOf('O') !== -1);
|
||||
if(this.config.notifyVoice && !staff) {
|
||||
staff = (f.indexOf('V') !== -1);
|
||||
}
|
||||
if(staff) {
|
||||
return k;
|
||||
}
|
||||
}.bind(this));
|
||||
|
||||
dbot.api.users.resolveChannel(server, cName, function(channel) {
|
||||
if(channel) {
|
||||
var perOps = channel.op;
|
||||
if(this.config.notifyVoice) perOps = _.union(perOps, channel.voice);
|
||||
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': op.id,
|
||||
'message': message
|
||||
});
|
||||
this.pNotify[op.id] = true;
|
||||
}, this);
|
||||
|
||||
this.db.read('nunsubs', channel.id, function(err, nunsubs) {
|
||||
async.eachSeries(ops, function(nick, next) {
|
||||
dbot.api.users.resolveUser(server, nick, function(user) {
|
||||
if(nunsubs && _.include(nunsubs.users, user.id)) {
|
||||
ops = _.without(ops, user.currentNick);
|
||||
}
|
||||
next();
|
||||
});
|
||||
}, function() {
|
||||
offlineUsers = perOps;
|
||||
if(!_.include(this.config.noMissingChans, cName)) {
|
||||
_.each(offlineUsers, function(id) {
|
||||
if(!this.pending[id]) this.pending[id] = [];
|
||||
this.pending[id].push({
|
||||
'time': new Date().getTime(),
|
||||
'channel': cName,
|
||||
'user': user.primaryNick,
|
||||
'message': message
|
||||
});
|
||||
this.pNotify[id] = true;
|
||||
}.bind(this));
|
||||
}
|
||||
|
||||
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));
|
||||
// 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));
|
||||
} else {
|
||||
var channel = dbot.instance.connections[server].channels[cName];
|
||||
var ops = _.filter(channel.nicks, function(user) {
|
||||
if(this.config.notifyVoice) {
|
||||
return user.op || user.voice;
|
||||
} else {
|
||||
return user.op;
|
||||
}
|
||||
}, this);
|
||||
ops = _.pluck(ops, 'name');
|
||||
|
||||
dbot.api.users.resolveChannel(server, cName, function(channel) {
|
||||
if(channel) {
|
||||
var perOps = channel.op;
|
||||
if(this.config.notifyVoice) perOps = _.union(perOps, channel.voice);
|
||||
|
||||
this.db.read('nunsubs', channel.id, function(err, nunsubs) {
|
||||
async.eachSeries(ops, function(nick, next) {
|
||||
dbot.api.users.resolveUser(server, nick, function(user) {
|
||||
if(nunsubs && _.include(nunsubs.users, user.id)) {
|
||||
ops = _.without(ops, user.currentNick);
|
||||
}
|
||||
next();
|
||||
});
|
||||
}, function() {
|
||||
offlineUsers = perOps;
|
||||
if(!_.include(this.config.noMissingChans, cName)) {
|
||||
_.each(offlineUsers, function(id) {
|
||||
if(!this.pending[id]) this.pending[id] = [];
|
||||
this.pending[id].push({
|
||||
'time': new Date().gettime(),
|
||||
'channel': cname,
|
||||
'user': user.primarynick,
|
||||
'message': message
|
||||
});
|
||||
this.pnotify[id] = true;
|
||||
}.bind(this));
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
},
|
||||
|
||||
'notifyUsers': function(server, users, message) {
|
||||
|
@ -43,6 +43,26 @@ var api = function(dbot) {
|
||||
callback(true, null);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// Check if a nick is online under a given alias
|
||||
'isOnline': function(server, channel, nick, callback) {
|
||||
this.api.resolveUser(server, nick, function(err, user) {
|
||||
if(user) {
|
||||
this.api.getUserAliases(user.id, function(err, aliases) {
|
||||
aliases.push(nick);
|
||||
|
||||
var onlineNicks = _.keys(dbot.instance.connections[server].channels[channel].nicks);
|
||||
var isOnline = _.any(onlineNicks, function(nick) {
|
||||
return _.include(aliases, nick);
|
||||
}, this);
|
||||
|
||||
callback(null, user, isOnline);
|
||||
});
|
||||
} else {
|
||||
callback(true, null, null);
|
||||
}
|
||||
}.bind(this));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -106,13 +106,14 @@ var users = function(dbot) {
|
||||
this.listener = function(event) {
|
||||
// Update current nick
|
||||
this.api.resolveUser(event.server, event.user, function(err, user) {
|
||||
console.log(user);
|
||||
this.internalAPI.updateCurrentNick(user, event.newNick, function(){});
|
||||
this.api.resolveUser(event.server, event.newNick, function(err, eUser) {
|
||||
if(!eUser) {
|
||||
this.internalAPI.createAlias(event.newNick, user, function(){});
|
||||
}
|
||||
}.bind(this));
|
||||
if(user) {
|
||||
this.internalAPI.updateCurrentNick(user, event.newNick, function(){});
|
||||
this.api.resolveUser(event.server, event.newNick, function(err, eUser) {
|
||||
if(!eUser) {
|
||||
this.internalAPI.createAlias(event.newNick, user, function(){});
|
||||
}
|
||||
}.bind(this));
|
||||
}
|
||||
}.bind(this));
|
||||
}.bind(this);
|
||||
this.on = ['NICK'];
|
||||
|
Loading…
Reference in New Issue
Block a user