utils: safety checks to resolveUser; ignore a tslint error
This commit is contained in:
parent
4f8dc4f0ae
commit
5a1cf205a7
1 changed files with 6 additions and 2 deletions
|
@ -404,7 +404,7 @@ export function downloadFile(attachmentUrl: string, retries = 3): Promise<{ path
|
||||||
if (retries === 0) {
|
if (retries === 0) {
|
||||||
throw httpsErr;
|
throw httpsErr;
|
||||||
} else {
|
} else {
|
||||||
console.warn("File download failed, retrying. Error given:", httpsErr.message);
|
console.warn("File download failed, retrying. Error given:", httpsErr.message); // tslint:disable-line
|
||||||
resolve(downloadFile(attachmentUrl, retries - 1));
|
resolve(downloadFile(attachmentUrl, retries - 1));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -650,6 +650,10 @@ export async function resolveUser(bot: Client, value: string): Promise<User | Un
|
||||||
|
|
||||||
// If we have the user cached, return that directly
|
// If we have the user cached, return that directly
|
||||||
const userId = resolveUserId(bot, value);
|
const userId = resolveUserId(bot, value);
|
||||||
|
if (!userId) {
|
||||||
|
return new UnknownUser({ id: userId });
|
||||||
|
}
|
||||||
|
|
||||||
if (bot.users.has(userId)) {
|
if (bot.users.has(userId)) {
|
||||||
return bot.users.get(userId);
|
return bot.users.get(userId);
|
||||||
}
|
}
|
||||||
|
@ -660,7 +664,7 @@ export async function resolveUser(bot: Client, value: string): Promise<User | Un
|
||||||
return new UnknownUser({ id: userId });
|
return new UnknownUser({ id: userId });
|
||||||
}
|
}
|
||||||
|
|
||||||
const freshUser = await bot.getRESTUser(userId);
|
const freshUser = await bot.getRESTUser(userId).catch(noop);
|
||||||
if (freshUser) {
|
if (freshUser) {
|
||||||
bot.users.add(freshUser, bot);
|
bot.users.add(freshUser, bot);
|
||||||
return freshUser;
|
return freshUser;
|
||||||
|
|
Loading…
Add table
Reference in a new issue