forked from GitHub/dbot
report report (it works)
This commit is contained in:
parent
7cb53a8b5a
commit
8c5e871640
@ -23,6 +23,53 @@ var api = function(dbot) {
|
||||
dbot.api.event.emit('new_notify', [ notify, user.primaryNick ]);
|
||||
});
|
||||
|
||||
var channel = dbot.instance.connections[server].channels[cName];
|
||||
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));
|
||||
|
||||
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);
|
||||
|
||||
// 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));
|
||||
} else {
|
||||
var channel = dbot.instance.connections[server].channels[cName];
|
||||
var ops = _.filter(channel.nicks, function(user) {
|
||||
if(this.config.notifyVoice) {
|
||||
@ -52,12 +99,12 @@ var api = function(dbot) {
|
||||
_.each(offlineUsers, function(id) {
|
||||
if(!this.pending[id]) this.pending[id] = [];
|
||||
this.pending[id].push({
|
||||
'time': new Date().getTime(),
|
||||
'channel': cName,
|
||||
'user': user.primaryNick,
|
||||
'time': new Date().gettime(),
|
||||
'channel': cname,
|
||||
'user': user.primarynick,
|
||||
'message': message
|
||||
});
|
||||
this.pNotify[id] = true;
|
||||
this.pnotify[id] = true;
|
||||
}.bind(this));
|
||||
}
|
||||
|
||||
@ -71,6 +118,7 @@ var api = function(dbot) {
|
||||
}.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);
|
||||
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