3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-25 04:02:39 +01:00

~mergeusers command [#94]

This commit is contained in:
reality 2013-01-02 21:06:43 +00:00
parent f537b05493
commit b4e4338148
2 changed files with 39 additions and 7 deletions

View File

@ -10,5 +10,11 @@
},
"aliasparentset": {
"english": "{newParent} is now the parent user, and {newAlias} is an alias."
},
"unprimary_error": {
"english": "One of those users isn't currently recorded as a primary user."
},
"merged_users": {
"english": "{old_user} and their aliases have been merged into {new_user}."
}
}

View File

@ -11,6 +11,17 @@ var users = function(dbot) {
return knownUsers[event.server];
};
var updateAliases = function(event, oldUser, newUser) {
var knownUsers = getServerUsers(event);
for(var alias in knownUsers.aliases) {
if(knownUsers.aliases.hasOwnProperty(alias)) {
if(knownUsers.aliases[alias] === oldUser) {
knownUsers.aliases[alias] = newUser;
}
}
}
}
dbot.instance.addListener('366', 'users', function(event) {
var knownUsers = getServerUsers(event);
for(var nick in event.channel.nicks) {
@ -56,13 +67,7 @@ var users = function(dbot) {
knownUsers.aliases[newAlias] = newParent;
// Update aliases to point to new primary user
for(var alias in knownUsers.aliases) {
if(knownUsers.aliases.hasOwnProperty(alias)) {
if(knownUsers.aliases[alias] === newAlias) {
knownUsers.aliases[alias] = newParent;
}
}
}
updateAliases(event, newAlias, newParent);
event.reply(dbot.t('aliasparentset', { 'newParent': newParent,
'newAlias': newAlias }));
@ -72,6 +77,27 @@ var users = function(dbot) {
event.reply(dbot.t('unknown_alias', { 'alias': newParent}));
}
}
},
'~mergeusers': function(event) {
if(dbot.config.admins.include(event.user)) {
var knownUsers = getServerUsers(event);
var primaryUser = event.params[1];
var secondaryUser = event.params[2];
if(knownUsers.users.include(primaryUser) && knownUsers.users.include(secondaryUser)) {
knownUsers.users.splice(knownUsers.users.indexOf(secondaryUser), 1);
knownUsers.aliases[secondaryUser] = primaryUser;
updateAliases(event, secondaryUser, primaryUser);
event.reply(dbot.t('merged_users', {
'old_user': secondaryUser,
'new_user': primaryUser
}));
} else {
event.reply(dbot.t('unprimary_error'));
}
}
}
};