Use new wrapper function for finding contributor
Fixes a bug with the find algo as well.
This commit is contained in:
parent
c190490d9b
commit
149bc0c052
@ -18,18 +18,13 @@ module.exports = async function(robot, kredits) {
|
||||
const apiURL = wikiURL + 'api.php';
|
||||
|
||||
function getContributorByWikiUser(username) {
|
||||
return Contributor.all().then(contributors => {
|
||||
let contrib = contributors.find(c => {
|
||||
if (typeof c.accounts !== 'object') { return false; }
|
||||
return c.accounts.find(a => {
|
||||
a.url === `${process.env.KREDITS_MEDIAWIKI_URL}User:${username}`;
|
||||
});
|
||||
});
|
||||
if (!contrib) {
|
||||
throw new Error();
|
||||
} else {
|
||||
return contrib;
|
||||
}
|
||||
let account = {
|
||||
site: url.parse(process.env.KREDITS_MEDIAWIKI_URL).hostname,
|
||||
username: username
|
||||
}
|
||||
return Contributor.findByAccount(account).then(contributor => {
|
||||
robot.logger.debug('CONTRIBUTOR: ', contributor)
|
||||
if (contributor) { return contributor; } else { throw new Error(); }
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user