diff --git a/modules/users/api.js b/modules/users/api.js index 8fc537a..c6fdae5 100644 --- a/modules/users/api.js +++ b/modules/users/api.js @@ -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', { diff --git a/modules/users/commands.js b/modules/users/commands.js index 6409ab9..884125b 100644 --- a/modules/users/commands.js +++ b/modules/users/commands.js @@ -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 diff --git a/modules/users/users.js b/modules/users/users.js index 26bbc42..c70a511 100644 --- a/modules/users/users.js +++ b/modules/users/users.js @@ -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); });