mirror of
https://github.com/reality/dbot.git
synced 2025-01-11 12:32:36 +01:00
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 channel = dbot.instance.connections[server].channels[cName];
|
||||||
var ops = _.filter(channel.nicks, function(user) {
|
if(_.has(dbot.modules, 'atheme')) {
|
||||||
if(this.config.notifyVoice) {
|
dbot.api.atheme.getChannelFlags(server, cName, function(err, flags) {
|
||||||
return user.op || user.voice;
|
var ops = _.map(flags, function(f, k) {
|
||||||
} else {
|
var staff = (f.indexOf('O') !== -1);
|
||||||
return user.op;
|
if(this.config.notifyVoice && !staff) {
|
||||||
}
|
staff = (f.indexOf('V') !== -1);
|
||||||
}, this);
|
}
|
||||||
ops = _.pluck(ops, 'name');
|
if(staff) {
|
||||||
|
return k;
|
||||||
|
}
|
||||||
|
}.bind(this));
|
||||||
|
|
||||||
dbot.api.users.resolveChannel(server, cName, function(channel) {
|
var offlineOps = {};
|
||||||
if(channel) {
|
async.each(ops, function(op, done) {
|
||||||
var perOps = channel.op;
|
dbot.api.users.isOnline(server, cName, op, function(err, user, online) {
|
||||||
if(this.config.notifyVoice) perOps = _.union(perOps, channel.voice);
|
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) {
|
// Send notifies to online ops
|
||||||
async.eachSeries(ops, function(nick, next) {
|
ops = _.difference(ops, _.keys(offlineOps));
|
||||||
dbot.api.users.resolveUser(server, nick, function(user) {
|
message = this.internalAPI.formatNotify(type, server,
|
||||||
if(nunsubs && _.include(nunsubs.users, user.id)) {
|
user, cName, message);
|
||||||
ops = _.without(ops, user.currentNick);
|
this.internalAPI.notify(server, ops, message);
|
||||||
}
|
if(_.has(this.config.chan_redirs, cName)) {
|
||||||
next();
|
dbot.say(server, this.config.chan_redirs[cName], message);
|
||||||
});
|
}
|
||||||
}, 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));
|
||||||
}
|
}.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) {
|
'notifyUsers': function(server, users, message) {
|
||||||
|
@ -43,6 +43,26 @@ var api = function(dbot) {
|
|||||||
callback(true, null);
|
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) {
|
this.listener = function(event) {
|
||||||
// Update current nick
|
// Update current nick
|
||||||
this.api.resolveUser(event.server, event.user, function(err, user) {
|
this.api.resolveUser(event.server, event.user, function(err, user) {
|
||||||
console.log(user);
|
if(user) {
|
||||||
this.internalAPI.updateCurrentNick(user, event.newNick, function(){});
|
this.internalAPI.updateCurrentNick(user, event.newNick, function(){});
|
||||||
this.api.resolveUser(event.server, event.newNick, function(err, eUser) {
|
this.api.resolveUser(event.server, event.newNick, function(err, eUser) {
|
||||||
if(!eUser) {
|
if(!eUser) {
|
||||||
this.internalAPI.createAlias(event.newNick, user, function(){});
|
this.internalAPI.createAlias(event.newNick, user, function(){});
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
this.on = ['NICK'];
|
this.on = ['NICK'];
|
||||||
|
Loading…
Reference in New Issue
Block a user