forked from GitHub/dbot
Fix ~setaliasparent [#272]
This commit is contained in:
parent
3814df98f6
commit
17c2c4b317
@ -15,7 +15,6 @@ var api = function(dbot) {
|
|||||||
'resolveUser': function(server, nick, callback) {
|
'resolveUser': function(server, nick, callback) {
|
||||||
var user = false;
|
var user = false;
|
||||||
this.db.search('users', { 'server': server }, function(result) {
|
this.db.search('users', { 'server': server }, function(result) {
|
||||||
console.log(result.primaryNick);
|
|
||||||
if(result.primaryNick == nick || _.include(result.aliases, nick)) {
|
if(result.primaryNick == nick || _.include(result.aliases, nick)) {
|
||||||
user = result;
|
user = result;
|
||||||
}
|
}
|
||||||
|
@ -36,14 +36,19 @@ var commands = function(dbot) {
|
|||||||
'~setaliasparent': function(event) {
|
'~setaliasparent': function(event) {
|
||||||
var newPrimary = event.params[1].trim();
|
var newPrimary = event.params[1].trim();
|
||||||
this.api.resolveUser(event.server, newPrimary, function(user) {
|
this.api.resolveUser(event.server, newPrimary, function(user) {
|
||||||
if(user) {
|
if(user && user.primaryNick != newPrimary) {
|
||||||
var newAlias = user.primaryNick;
|
var newAlias = user.primaryNick;
|
||||||
user.primaryNick = newPrimary;
|
user.primaryNick = newPrimary;
|
||||||
user.aliases = _.without(user.aliases, newPrimary).push(newAlias);
|
user.aliases = _.without(user.aliases, newPrimary);
|
||||||
|
user.aliases.push(newAlias);
|
||||||
this.internalAPI.updateChannelPrimaryUser(event.server, newAlias, newPrimary);
|
this.internalAPI.updateChannelPrimaryUser(event.server, newAlias, newPrimary);
|
||||||
|
|
||||||
this.db.save('users', user.id, user, function(err) {
|
this.db.save('users', user.id, user, function(err) {
|
||||||
if(!err) {
|
if(!err) {
|
||||||
|
event.reply(dbot.t('aliasparentset', {
|
||||||
|
'newParent': newPrimary,
|
||||||
|
'newAlias': newAlias
|
||||||
|
}));
|
||||||
dbot.api.event.emit('~setaliasparent', {
|
dbot.api.event.emit('~setaliasparent', {
|
||||||
'server': event.server,
|
'server': event.server,
|
||||||
'alias': newAlias
|
'alias': newAlias
|
||||||
@ -51,7 +56,7 @@ var commands = function(dbot) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
event.reply(dbot.t('unknown_alias', { 'alias': newParent }));
|
event.reply(dbot.t('unknown_alias', { 'alias': newPrimary }));
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
@ -80,17 +85,17 @@ var commands = function(dbot) {
|
|||||||
'secondary': secondaryUser
|
'secondary': secondaryUser
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
}.bind(this));
|
||||||
}
|
}
|
||||||
});
|
}.bind(this));
|
||||||
} else {
|
} else {
|
||||||
event.reply(dbot.t('unprimary_error'));
|
event.reply(dbot.t('unprimary_error'));
|
||||||
}
|
}
|
||||||
});
|
}.bind(this));
|
||||||
} else {
|
} else {
|
||||||
event.reply(dbot.t('unprimary_error'));
|
event.reply(dbot.t('unprimary_error'));
|
||||||
}
|
}
|
||||||
});
|
}.bind(this));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ var users = function(dbot) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
}.bind(this));
|
||||||
}.bind(this),
|
}.bind(this),
|
||||||
|
|
||||||
'updateChannelPrimaryUser': function(server, oldUser, newUser) {
|
'updateChannelPrimaryUser': function(server, oldUser, newUser) {
|
||||||
@ -82,7 +82,6 @@ var users = function(dbot) {
|
|||||||
this.api.isKnownUser(event.server, event.newNick, function(isKnown) {
|
this.api.isKnownUser(event.server, event.newNick, function(isKnown) {
|
||||||
if(!isKnown) {
|
if(!isKnown) {
|
||||||
this.api.resolveUser(event.server, event.user, function(user) {
|
this.api.resolveUser(event.server, event.user, function(user) {
|
||||||
dbot.say('aberwiki', '#realitest', event.newNick);
|
|
||||||
user.aliases.push(event.newNick);
|
user.aliases.push(event.newNick);
|
||||||
this.db.save('users', user.id, user, function(err) {
|
this.db.save('users', user.id, user, function(err) {
|
||||||
if(!err) {
|
if(!err) {
|
||||||
|
Loading…
Reference in New Issue
Block a user