From ed86f98427dd0eec5489ce5fedc2bd82045d3256 Mon Sep 17 00:00:00 2001 From: Sam Nicholls Date: Wed, 23 Jan 2013 23:32:50 +0000 Subject: [PATCH] Profile move and merge API [Untested] --- modules/profile/api.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/modules/profile/api.js b/modules/profile/api.js index e6b22c8..246b741 100644 --- a/modules/profile/api.js +++ b/modules/profile/api.js @@ -14,6 +14,41 @@ var api = function(dbot) { this.profiles[server][primary] = {}; _.defaults(this.profiles[server][primary], this.config.schema); }, + + /** + * Given a server and "new" alias, resolve this alias to the user's + * new primary name and move profile data pertaining to the alias to + * the new primary name. + */ + 'renameProfile': function(server, alias){ + if(!_.has(this.profiles, server)) return; + var profiles = dbot.db.profiles[server]; + + if(_.has(profiles, alias)){ + var primary = dbot.api.users.resolveUser(server, alias, true).toLowerCase(); + alias = alias.trim().toLowerCase(); + + profiles[primary] = profiles[alias]; + delete profiles[alias]; + } + }, + + /** + * Given a server and a primary username which has been converted to a + * secondary alias find and remove the profile for the alias. + */ + 'mergeProfile': function(server, mergeFromPrimary){ + if(!_.has(this.profiles, server)) return; + var profiles = dbot.db.profiles[server]; + + mergeFromPrimary = mergeFromPrimary.toLowerCase(); + var mergeToPrimary = dbot.api.users.resolveUser(server, mergeFromPrimary, true).toLowerCase(); + if(!_.has(profiles, mergeToPrimary) + || !_.has(profiles, mergeFromPrimary)) return; + + // Remove the profile of the alias + delete profiles[mergeFromPrimary]; + }, } };