3
0
mirror of https://github.com/reality/dbot.git synced 2024-11-23 20:39:25 +01:00

index for aliases

This commit is contained in:
reality 2017-07-18 02:16:07 +00:00
parent c1c54bbd59
commit d41836e937
2 changed files with 14 additions and 12 deletions

View File

@ -33,15 +33,12 @@ var api = function(dbot) {
// Retrieve user aliases given a user ID
'getUserAliases': function(id, callback) {
var aliases = [];
this.db.search('user_aliases', { 'user': id }, function(result) {
aliases.push(result.alias);
}, function(err) {
if(!err) {
callback(null, aliases);
} else {
callback(true, null);
}
this.api.getUser(id, function(err, user) {
if(!err) {
callback(null, user.aliases);
} else {
callback(true, null);
}
});
},

View File

@ -16,7 +16,8 @@ var users = function(dbot) {
'id': id,
'server': server,
'primaryNick': nick,
'currentNick': nick
'currentNick': nick,
'aliases': []
}, function(err, result) {
if(!err) dbot.api.event.emit('new_user', [ result ]);
callback(err, result);
@ -33,11 +34,14 @@ var users = function(dbot) {
}, function(err, result) {
if(!err) {
dbot.api.event.emit('new_user_alias', [ result, alias ]);
callback(null, result);
user.aliases.push(alias);
this.db.save('users', user.id, user, function() {
callback(null, result);
});
} else {
callback(true, null);
}
});
}.bind(this));
}.bind(this),
// Remove an alias record
@ -134,6 +138,7 @@ var users = function(dbot) {
}
}.bind(this));
}.bind(this);
var checkUserTime = function(user, done) {
if(!_.has(user, 'lastUsed') || (_.has(user, 'lastUsed') && moment(user.lastUsed).diff(moment(user.lastUsed).add(1, 'day'), 'days') > 0)) {
user.lastUsed = moment().unix();