2013-01-14 22:03:47 +01:00
|
|
|
var _ = require('underscore')._;
|
|
|
|
|
|
|
|
var commands = function(dbot) {
|
|
|
|
var commands = {
|
|
|
|
'~alias': function(event) {
|
|
|
|
var knownUsers = this.getServerUsers(event.server),
|
|
|
|
alias = event.params[1].trim();
|
|
|
|
|
|
|
|
if(_.include(knownUsers.users, alias)) {
|
2013-01-20 19:19:44 +01:00
|
|
|
var aliases = this.api.getAliases(event.server, alias);
|
|
|
|
var aliasCount = aliases.length;
|
|
|
|
|
2013-01-20 19:26:07 +01:00
|
|
|
if(aliasCount != 0) {
|
|
|
|
var aliases = _.first(aliases, 10);
|
2013-03-21 07:07:49 +01:00
|
|
|
var including = 'including: ' + aliases.join(', ') + '.';
|
|
|
|
|
2013-01-20 19:26:07 +01:00
|
|
|
event.reply(dbot.t('primary', {
|
|
|
|
'user': alias,
|
|
|
|
'count': aliasCount
|
|
|
|
}) + including);
|
|
|
|
} else {
|
|
|
|
event.reply(dbot.t('primary', {
|
|
|
|
'user': alias,
|
|
|
|
'count': aliasCount
|
2013-03-21 07:07:49 +01:00
|
|
|
}).slice(0, -2) + ".");
|
2013-01-20 19:19:44 +01:00
|
|
|
}
|
2013-01-14 22:03:47 +01:00
|
|
|
} else if(_.has(knownUsers.aliases, alias)) {
|
|
|
|
event.reply(dbot.t('alias', {
|
|
|
|
'alias': alias,
|
|
|
|
'user': knownUsers.aliases[alias]
|
|
|
|
}));
|
|
|
|
} else {
|
|
|
|
event.reply(dbot.t('unknown_alias', { 'alias': alias }));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
'~setaliasparent': function(event) {
|
|
|
|
var knownUsers = this.getServerUsers(event.server);
|
|
|
|
var newParent = event.params[1];
|
|
|
|
|
|
|
|
if(_.has(knownUsers.aliases, newParent)) {
|
|
|
|
var newAlias = knownUsers.aliases[newParent];
|
|
|
|
|
|
|
|
// Replace user entry
|
|
|
|
knownUsers.users = _.without(knownUsers.users, newAlias);
|
|
|
|
knownUsers.users.push(newParent);
|
|
|
|
|
|
|
|
// Replace channels entries with new primary user
|
|
|
|
this.updateChannels(event, newAlias, 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
|
|
|
|
this.updateAliases(event, newAlias, newParent);
|
|
|
|
|
|
|
|
event.reply(dbot.t('aliasparentset', {
|
|
|
|
'newParent': newParent,
|
|
|
|
'newAlias': newAlias
|
|
|
|
}));
|
|
|
|
|
2013-01-15 18:52:13 +01:00
|
|
|
return {
|
|
|
|
'server': event.server,
|
|
|
|
'alias': newAlias
|
|
|
|
};
|
2013-01-14 22:03:47 +01:00
|
|
|
} else {
|
|
|
|
event.reply(dbot.t('unknown_alias', { 'alias': newParent }));
|
|
|
|
}
|
2013-01-15 18:52:13 +01:00
|
|
|
return false;
|
2013-01-14 22:03:47 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
'~mergeusers': function(event) {
|
|
|
|
var knownUsers = this.getServerUsers(event.server);
|
|
|
|
var primaryUser = event.params[1];
|
|
|
|
var secondaryUser = event.params[2];
|
|
|
|
|
|
|
|
if(_.include(knownUsers.users, primaryUser) && _.include(knownUsers.users, secondaryUser)) {
|
|
|
|
knownUsers.users = _.without(knownUsers.users, secondaryUser);
|
|
|
|
knownUsers.aliases[secondaryUser] = primaryUser;
|
|
|
|
this.updateAliases(event, secondaryUser, primaryUser);
|
|
|
|
this.updateChannels(event, secondaryUser, primaryUser);
|
|
|
|
|
|
|
|
event.reply(dbot.t('merged_users', {
|
|
|
|
'old_user': secondaryUser,
|
|
|
|
'new_user': primaryUser
|
|
|
|
}));
|
|
|
|
|
2013-01-15 18:52:13 +01:00
|
|
|
return {
|
|
|
|
'server': event.server,
|
2013-01-17 23:40:49 +01:00
|
|
|
'secondary': secondaryUser
|
2013-01-15 18:52:13 +01:00
|
|
|
};
|
2013-01-14 22:03:47 +01:00
|
|
|
} else {
|
|
|
|
event.reply(dbot.t('unprimary_error'));
|
|
|
|
}
|
2013-01-15 18:52:13 +01:00
|
|
|
return false;
|
2013-01-14 22:03:47 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
commands['~setaliasparent'].access = 'moderator';
|
|
|
|
commands['~mergeusers'].access = 'moderator';
|
|
|
|
|
|
|
|
return commands;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.fetch = function(dbot) {
|
|
|
|
return commands(dbot);
|
|
|
|
};
|