2014-09-04 11:36:57 +02:00
|
|
|
var _ = require('underscore')._;
|
2013-01-14 22:03:47 +01:00
|
|
|
|
|
|
|
var commands = function(dbot) {
|
2014-09-04 11:36:57 +02:00
|
|
|
this.commands = {
|
2013-01-14 22:03:47 +01:00
|
|
|
'~alias': function(event) {
|
2014-09-04 11:36:57 +02:00
|
|
|
var nick = event.params[1] || event.user;
|
|
|
|
this.api.resolveUser(event.server, nick, function(err, user) {
|
2013-03-24 17:04:01 +01:00
|
|
|
if(user) {
|
2014-09-04 11:36:57 +02:00
|
|
|
this.api.getUserAliases(user.id, function(err, aliases) {
|
|
|
|
var including = _.first(aliases, 10).join(', ');
|
2013-01-14 22:03:47 +01:00
|
|
|
|
2014-09-04 11:36:57 +02:00
|
|
|
if(nick === user.primaryNick) {
|
|
|
|
if(aliases.length === 0) {
|
|
|
|
event.reply(dbot.t('primary_no_alias', {
|
|
|
|
'user': user.primaryNick,
|
|
|
|
'currentNick': user.currentNick
|
|
|
|
}));
|
|
|
|
} else {
|
|
|
|
event.reply(dbot.t('primary', {
|
|
|
|
'user': user.primaryNick,
|
|
|
|
'currentNick': user.currentNick,
|
|
|
|
'count': aliases.length,
|
|
|
|
'including': including
|
|
|
|
}));
|
|
|
|
}
|
2013-03-24 17:04:01 +01:00
|
|
|
} else {
|
2014-09-04 11:36:57 +02:00
|
|
|
event.reply(dbot.t('alias', {
|
|
|
|
'alias': nick,
|
|
|
|
'user': user.primaryNick
|
|
|
|
}));
|
2013-03-24 17:04:01 +01:00
|
|
|
}
|
2013-08-28 22:22:56 +02:00
|
|
|
});
|
|
|
|
} else {
|
2014-09-04 11:36:57 +02:00
|
|
|
event.reply(dbot.t('unknown_alias', { 'alias': nick }));
|
2013-08-28 22:22:56 +02:00
|
|
|
}
|
2014-09-04 11:36:57 +02:00
|
|
|
}.bind(this));
|
2013-08-28 22:22:56 +02:00
|
|
|
},
|
|
|
|
|
2013-04-20 13:21:04 +02:00
|
|
|
'~addalias': function(event) {
|
2014-09-04 11:36:57 +02:00
|
|
|
var nick = event.params[1],
|
|
|
|
alias = event.params[2];
|
2013-04-20 13:21:04 +02:00
|
|
|
|
2014-09-04 11:36:57 +02:00
|
|
|
this.api.resolveUser(event.server, nick, function(err, user) {
|
2013-04-20 13:21:04 +02:00
|
|
|
if(user) {
|
2014-09-04 11:36:57 +02:00
|
|
|
this.api.resolveUser(event.server, alias, function(err, aUser) {
|
|
|
|
if(!aUser) {
|
|
|
|
this.internalAPI.createAlias(alias, user, function(err) {
|
2013-04-20 13:21:04 +02:00
|
|
|
event.reply(dbot.t('alias_added', {
|
|
|
|
'user': user.primaryNick,
|
|
|
|
'alias': alias
|
|
|
|
}));
|
2014-09-04 11:36:57 +02:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
event.reply(dbot.t('alias_exists', {
|
|
|
|
'alias': alias,
|
|
|
|
'user': aUser.primaryNick
|
|
|
|
}));
|
|
|
|
}
|
2013-08-17 19:23:43 +02:00
|
|
|
});
|
|
|
|
} else {
|
2014-09-04 11:36:57 +02:00
|
|
|
event.reply(dbot.t('unknown_alias', { 'alias': nick }));
|
2013-08-17 19:23:43 +02:00
|
|
|
}
|
|
|
|
}.bind(this));
|
|
|
|
},
|
|
|
|
|
2013-01-14 22:03:47 +01:00
|
|
|
'~setaliasparent': function(event) {
|
2014-09-04 11:36:57 +02:00
|
|
|
var newPrimary = event.params[1];
|
2013-03-24 17:04:01 +01:00
|
|
|
this.api.resolveUser(event.server, newPrimary, function(user) {
|
2014-09-04 11:36:57 +02:00
|
|
|
if(user) {
|
|
|
|
if(user.primaryNick !== newPrimary) {
|
|
|
|
this.internalAPI.reparentUser(user, newPrimary, function() {
|
2013-03-24 17:59:26 +01:00
|
|
|
event.reply(dbot.t('aliasparentset', {
|
|
|
|
'newParent': newPrimary,
|
2014-09-04 11:36:57 +02:00
|
|
|
'newAlias': user.primaryNick
|
2013-03-24 17:59:26 +01:00
|
|
|
}));
|
2014-09-04 11:36:57 +02:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
event.reply(dbot.t('already_primary', { 'user': newPrimary }));
|
|
|
|
}
|
2013-03-24 17:04:01 +01:00
|
|
|
} else {
|
2014-09-04 11:36:57 +02:00
|
|
|
event.reply(dbot.t('unknown_alias', { 'alias': nick }));
|
2013-03-24 17:04:01 +01:00
|
|
|
}
|
2014-09-04 11:36:57 +02:00
|
|
|
});
|
2013-01-14 22:03:47 +01:00
|
|
|
},
|
|
|
|
|
2014-09-04 11:36:57 +02:00
|
|
|
'~rmalias': function(event) {
|
|
|
|
var alias = event.params[1];
|
2013-01-14 22:03:47 +01:00
|
|
|
|
2014-09-04 11:36:57 +02:00
|
|
|
this.api.resolveUser(event.server, alias, function(err, user) {
|
|
|
|
if(user) { // Retrieving user record via alias proves existence of alias record
|
|
|
|
this.internalAPI.removeAlias(event.server, alias, function(err) {
|
|
|
|
event.reply(dbot.t('alias_removed', {
|
|
|
|
'primary': user.primaryNick,
|
|
|
|
'alias': alias
|
|
|
|
}));
|
|
|
|
});
|
2013-03-24 17:04:01 +01:00
|
|
|
} else {
|
2014-09-04 11:36:57 +02:00
|
|
|
event.reply(dbot.t('unknown_alias', { 'alias': nick }));
|
2013-03-24 17:04:01 +01:00
|
|
|
}
|
2014-09-04 11:36:57 +02:00
|
|
|
});
|
2013-03-24 17:04:01 +01:00
|
|
|
}
|
2013-01-14 22:03:47 +01:00
|
|
|
};
|
2014-09-04 11:36:57 +02:00
|
|
|
this.commands['~setaliasparent'].access = 'moderator';
|
|
|
|
this.commands['~addalias'].access = 'moderator';
|
|
|
|
this.commands['~rmalias'].access = 'moderator';
|
|
|
|
this.commands['~mergeusers'].access = 'moderator';
|
2013-01-14 22:03:47 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.fetch = function(dbot) {
|
|
|
|
return commands(dbot);
|
|
|
|
};
|