2013-01-14 22:03:47 +01:00
|
|
|
var _ = require('underscore')._;
|
|
|
|
|
|
|
|
var commands = function(dbot) {
|
|
|
|
var commands = {
|
|
|
|
'~alias': function(event) {
|
2013-03-24 17:04:01 +01:00
|
|
|
var nick = event.params[1].trim();
|
|
|
|
this.api.resolveUser(event.server, nick, function(user) {
|
|
|
|
if(user) {
|
|
|
|
if(nick == user.primaryNick) {
|
|
|
|
var aliases = _.first(user.aliases, 10);
|
|
|
|
var including = 'including: ' + aliases.join(', ') + '.';
|
2013-01-14 22:03:47 +01:00
|
|
|
|
2013-03-24 17:04:01 +01:00
|
|
|
if(user.aliases.length != 0) {
|
|
|
|
event.reply(dbot.t('primary', {
|
|
|
|
'user': nick,
|
2013-03-25 14:55:47 +01:00
|
|
|
'currentNick': user.currentNick,
|
2013-03-24 17:04:01 +01:00
|
|
|
'count': user.aliases.length,
|
|
|
|
}) + including);
|
|
|
|
} else {
|
|
|
|
event.reply(dbot.t('primary', {
|
|
|
|
'user': nick,
|
2013-03-25 14:55:47 +01:00
|
|
|
'currentNick': user.currentNick,
|
2013-03-24 17:04:01 +01:00
|
|
|
'count': user.aliases.length
|
|
|
|
}).slice(0, -2) + ".");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
event.reply(dbot.t('alias', {
|
|
|
|
'alias': nick,
|
|
|
|
'user': user.primaryNick
|
|
|
|
}));
|
|
|
|
}
|
2013-01-20 19:26:07 +01:00
|
|
|
} else {
|
2013-03-24 17:04:01 +01:00
|
|
|
event.reply(dbot.t('unknown_alias', { 'alias': nick }));
|
2013-01-20 19:19:44 +01:00
|
|
|
}
|
2013-03-24 17:04:01 +01:00
|
|
|
});
|
2013-01-14 22:03:47 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
'~setaliasparent': function(event) {
|
2013-03-24 17:04:01 +01:00
|
|
|
var newPrimary = event.params[1].trim();
|
|
|
|
this.api.resolveUser(event.server, newPrimary, function(user) {
|
2013-03-24 17:59:26 +01:00
|
|
|
if(user && user.primaryNick != newPrimary) {
|
2013-03-24 17:04:01 +01:00
|
|
|
var newAlias = user.primaryNick;
|
|
|
|
user.primaryNick = newPrimary;
|
2013-03-24 17:59:26 +01:00
|
|
|
user.aliases = _.without(user.aliases, newPrimary);
|
|
|
|
user.aliases.push(newAlias);
|
2013-03-24 17:04:01 +01:00
|
|
|
this.internalAPI.updateChannelPrimaryUser(event.server, newAlias, newPrimary);
|
2013-01-14 22:03:47 +01:00
|
|
|
|
2013-03-24 17:04:01 +01:00
|
|
|
this.db.save('users', user.id, user, function(err) {
|
|
|
|
if(!err) {
|
2013-03-24 17:59:26 +01:00
|
|
|
event.reply(dbot.t('aliasparentset', {
|
|
|
|
'newParent': newPrimary,
|
|
|
|
'newAlias': newAlias
|
|
|
|
}));
|
2013-03-24 17:04:01 +01:00
|
|
|
dbot.api.event.emit('~setaliasparent', {
|
|
|
|
'server': event.server,
|
|
|
|
'alias': newAlias
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
2013-03-24 17:59:26 +01:00
|
|
|
event.reply(dbot.t('unknown_alias', { 'alias': newPrimary }));
|
2013-03-24 17:04:01 +01:00
|
|
|
}
|
|
|
|
}.bind(this));
|
2013-01-14 22:03:47 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
'~mergeusers': function(event) {
|
|
|
|
var primaryUser = event.params[1];
|
|
|
|
var secondaryUser = event.params[2];
|
|
|
|
|
2013-03-24 17:04:01 +01:00
|
|
|
this.api.resolveUser(event.server, primaryUser, function(user) {
|
|
|
|
if(user) {
|
|
|
|
this.api.resolveUser(event.server, secondaryUser, function(secondaryUser) {
|
|
|
|
if(secondaryUser) {
|
|
|
|
user.aliases.push(secondaryUser.primaryNick);
|
|
|
|
user.aliases.concat(secondaryUser.aliases);
|
|
|
|
this.db.del('users', secondaryUser.id, function(err) {
|
|
|
|
if(!err) {
|
|
|
|
this.db.save('users', user.id, user, function(err) {
|
|
|
|
if(!err) {
|
|
|
|
this.updateChannels(event, secondaryUser, primaryUser);
|
|
|
|
event.reply(dbot.t('merged_users', {
|
|
|
|
'old_user': secondaryUser,
|
|
|
|
'new_user': primaryUser
|
|
|
|
}));
|
|
|
|
dbot.api.event.emit('~mergeusers', {
|
|
|
|
'server': event.server,
|
|
|
|
'secondary': secondaryUser
|
|
|
|
});
|
|
|
|
}
|
2013-03-24 17:59:26 +01:00
|
|
|
}.bind(this));
|
2013-03-24 17:04:01 +01:00
|
|
|
}
|
2013-03-24 17:59:26 +01:00
|
|
|
}.bind(this));
|
2013-03-24 17:04:01 +01:00
|
|
|
} else {
|
|
|
|
event.reply(dbot.t('unprimary_error'));
|
|
|
|
}
|
2013-03-24 17:59:26 +01:00
|
|
|
}.bind(this));
|
2013-03-24 17:04:01 +01:00
|
|
|
} else {
|
|
|
|
event.reply(dbot.t('unprimary_error'));
|
|
|
|
}
|
2013-03-24 17:59:26 +01:00
|
|
|
}.bind(this));
|
2013-03-24 17:04:01 +01:00
|
|
|
}
|
2013-01-14 22:03:47 +01:00
|
|
|
};
|
2013-03-21 07:58:40 +01:00
|
|
|
|
|
|
|
commands['~alias'].regex = [/^~alias ([\d\w[\]{}^|\\`_-]+?)/, 2];
|
|
|
|
commands['~setaliasparent'].regex = [/^~setaliasparent ([\d\w[\]{}^|\\`_-]+?)/, 2];
|
|
|
|
commands['~mergeusers'].regex = [/^~mergeusers ([\d\w[\]{}^|\\`_-]+?)\s*?([\d\w[\]{}^|\\`_-]+?)/, 3];
|
|
|
|
|
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);
|
|
|
|
};
|