fix ~mergeusers, create getChannel and resolveChannel distinction [#548]

This commit is contained in:
reality 2013-08-17 17:09:55 +00:00
parent 06053b9e17
commit 9d6b2cc3e1
3 changed files with 13 additions and 7 deletions

View File

@ -33,7 +33,7 @@ var api = function(dbot) {
});
},
'getChannel': function(server, channelName, callback) {
'resolveChannel': function(server, channelName, callback) {
var channel = false;
this.db.search('channel_users', {
'server': server,
@ -47,6 +47,13 @@ var api = function(dbot) {
});
},
'getChannel': function(uuid, callback) {
this.db.read('channel_users', uuid, function(err, channel) {
if(err) channel = false;
callback(channel);
});
},
'getRandomChannelUser': function(server, channel, callback) {
var channel;
this.db.search('channel_users', {

View File

@ -98,12 +98,11 @@ var commands = function(dbot) {
if(oldUser) {
user.aliases.push(oldUser.primaryNick);
user.aliases = _.union(user.aliases, oldUser.aliases);
this.internalAPI.mergeChannelUsers(event.server, oldUser, user);
this.internalAPI.mergeChannelUsers(oldUser, user);
this.db.del('users', oldUser.id, function(err) {
if(!err) {
this.db.save('users', user.id, user, function(err) {
if(!err) {
this.internalAPI.mergeChannelUsers(event.server, secondaryUser, primaryUser);
event.reply(dbot.t('merged_users', {
'old_user': secondaryUser,
'new_user': primaryUser

View File

@ -120,10 +120,10 @@ var users = function(dbot) {
});
}.bind(this),
'mergeChannelUsers': function(server, oldUser, newUser) {
'mergeChannelUsers': function(oldUser, newUser) {
newUser.channels = _.union(oldUser.channels, newUser.channels);
_.each(newUser.channels, function(name) {
this.api.getChannel(server, name, function(channel) {
_.each(newUser.channels, function(uuid) {
this.api.getChannel(uuid, function(channel) {
if(_.include(channel.users, oldUser.id)) {
channel.users = _.without(channel.users, oldUser.id);
}
@ -189,7 +189,7 @@ var users = function(dbot) {
dbot.instance.addPreEmitHook(function(event, callback) {
if(event.channel) {
this.api.getChannel(event.server, event.channel.name, function(channel) {
this.api.resolveChannel(event.server, event.channel.name, function(channel) {
event.rChannel = channel;
callback(false);
});