forked from GitHub/dbot
Add ~setaliasparent command [#83]
This commit is contained in:
parent
e7addd9ff4
commit
944b97e430
@ -21,11 +21,7 @@ var users = function(dbot) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
var commands = {
|
||||||
'name': 'users',
|
|
||||||
'ignorable': false,
|
|
||||||
|
|
||||||
'commands': {
|
|
||||||
'~alias': function(event) {
|
'~alias': function(event) {
|
||||||
var knownUsers = getServerUsers(event);
|
var knownUsers = getServerUsers(event);
|
||||||
var alias = event.params[1].trim();
|
var alias = event.params[1].trim();
|
||||||
@ -34,9 +30,47 @@ var users = function(dbot) {
|
|||||||
} else {
|
} else {
|
||||||
event.reply(alias + ' is not known as an alias to me.');
|
event.reply(alias + ' is not known as an alias to me.');
|
||||||
}
|
}
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
'~setaliasparent': function(event) {
|
||||||
|
if(dbot.config.admins.include(event.user)) {
|
||||||
|
var knownUsers = getServerUsers(event);
|
||||||
|
var newParent = event.params[1];
|
||||||
|
|
||||||
|
if(knownUsers.aliases.hasOwnProperty(newParent)) {
|
||||||
|
var newAlias = knownUsers.aliases[newParent];
|
||||||
|
|
||||||
|
// Replace users entry with new primary user
|
||||||
|
var usersIndex = knownUsers.users.indexOf(newAlias);
|
||||||
|
knownUsers.users[usersIndex] = newParent;
|
||||||
|
|
||||||
|
// Remove alias for new parent & add alias for new alias
|
||||||
|
delete knownUsers.aliases[newParent];
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
event.reply(newParent + ' is now the parent user, and ' +
|
||||||
|
newAlias + ' is an alias.');
|
||||||
|
} else {
|
||||||
|
event.reply('Given new parent does not currently exist as an alias.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
'name': 'users',
|
||||||
|
'ignorable': false,
|
||||||
|
'commands': commands,
|
||||||
|
|
||||||
'listener': function(event) {
|
'listener': function(event) {
|
||||||
var knownUsers = getServerUsers(event);
|
var knownUsers = getServerUsers(event);
|
||||||
if(event.action == 'JOIN') {
|
if(event.action == 'JOIN') {
|
||||||
|
Loading…
Reference in New Issue
Block a user