3
0
mirror of https://github.com/reality/dbot.git synced 2024-11-23 20:39:25 +01:00

fix a bunch of shit

This commit is contained in:
reality 2013-06-22 20:23:47 +00:00
parent 39db5423df
commit a65c96138e

View File

@ -11,8 +11,9 @@ var users = function(dbot) {
/*** Internal API ***/ /*** Internal API ***/
this.internalAPI = { this.internalAPI = {
'createUser': function(server, nick, callback) { 'createUser': function(server, nick, callback) {
var id = uuid.v4();
this.db.create('users', id, { this.db.create('users', id, {
'id': uuid.v4(), 'id': id,
'primaryNick': nick, 'primaryNick': nick,
'currentNick': nick, 'currentNick': nick,
'server': server, 'server': server,
@ -27,8 +28,9 @@ var users = function(dbot) {
}.bind(this), }.bind(this),
'createChannel': function(server, name, callback) { 'createChannel': function(server, name, callback) {
var id = uuid.v4();
this.db.create('channel_users', id, { this.db.create('channel_users', id, {
'id': uuid.v4(), 'id': id,
'server': server, 'server': server,
'name': name, 'name': name,
'users': [] 'users': []
@ -44,7 +46,7 @@ var users = function(dbot) {
if(!_.include(channel.users, user.id)) { if(!_.include(channel.users, user.id)) {
channel.users.push(user.id); channel.users.push(user.id);
} }
if(!_.include(user.channels, channel.id) { if(!_.include(user.channels, channel.id)) {
user.channels.push(channel.id); user.channels.push(channel.id);
} }
@ -53,7 +55,7 @@ var users = function(dbot) {
dbot.api.event.emit('new_channel_user', [ user, channel ]); dbot.api.event.emit('new_channel_user', [ user, channel ]);
callback(err); callback(err);
}); });
}); }.bind(this));
}.bind(this), }.bind(this),
'updateChannelPrimaryUser': function(server, oldUser, newUser) { 'updateChannelPrimaryUser': function(server, oldUser, newUser) {
@ -97,10 +99,10 @@ var users = function(dbot) {
if(event.action == 'JOIN' && event.user != dbot.config.name) { if(event.action == 'JOIN' && event.user != dbot.config.name) {
if(!event.rUser) { if(!event.rUser) {
this.internalAPI.createUser(event.server, event.user, function(user) { this.internalAPI.createUser(event.server, event.user, function(user) {
this.internalAPI.addChannelUser(channel, user, function() {}); this.internalAPI.addChannelUser(event.rChannel, user, function() {});
}); }.bind(this));
} else if(!_.include(event.rUser.channels, event.rChannel.id)) { } else if(!_.include(event.rUser.channels, event.rChannel.id)) {
this.internalAPI.addChannelUser(channel, user, function() {}); this.internalAPI.addChannelUser(event.rChannel, event.rUser, function() {});
} }
} else if(event.action == 'NICK') { } else if(event.action == 'NICK') {
this.api.isKnownUser(event.server, event.newNick, function(isKnown) { this.api.isKnownUser(event.server, event.newNick, function(isKnown) {
@ -125,6 +127,8 @@ var users = function(dbot) {
event.rUser = user; event.rUser = user;
callback(false); callback(false);
}); });
} else {
callback(false);
} }
}.bind(this)); }.bind(this));
@ -134,15 +138,17 @@ var users = function(dbot) {
event.rChannel = channel; event.rChannel = channel;
callback(false); callback(false);
}); });
} else {
callback(false);
} }
}.bind(this)); }.bind(this));
dbot.instance.addListener('366', 'users', function(event) { dbot.instance.addListener('366', 'users', function(event) {
var checkChannel = function(channel) { var checkChannel = function(channel) {
async.eachSeries(event.channel.nicks, function(nick, next) { async.eachSeries(_.keys(event.channel.nicks), function(nick, next) {
this.api.resolveUser(event.server, nick, function(user) { this.api.resolveUser(event.server, nick, function(user) {
var checkChannelUser = function(user) { var checkChannelUser = function(user) {
if(!_.inlude(channel.users, user.id)) { if(!_.include(channel.users, user.id)) {
this.internalAPI.addChannelUser(channel, user, next); this.internalAPI.addChannelUser(channel, user, next);
} else { } else {
next(); next();
@ -155,8 +161,14 @@ var users = function(dbot) {
this.internalAPI.createUser(event.server, nick, checkChannelUser); this.internalAPI.createUser(event.server, nick, checkChannelUser);
} }
}.bind(this)); }.bind(this));
}); }.bind(this), function(err) {});
}; }.bind(this);
if(!event.rChannel) {
this.internalAPI.createChannel(event.server, event.channel.name, checkChannel);
} else {
checkChannel(event.rChannel);
}
}.bind(this)); }.bind(this));
_.each(dbot.instance.connections, function(connection) { _.each(dbot.instance.connections, function(connection) {