propigate errors from lookupUser

This commit is contained in:
Cynthia Foxwell 2024-08-18 14:16:05 -06:00
parent 83c49eb6ae
commit 5b8a9afbaa
6 changed files with 10 additions and 6 deletions

View file

@ -48,7 +48,7 @@ avatar.callback = async function (msg, line, [user], {server, guild}) {
}
} else if (user) {
const lookup = await lookupUser(msg, user);
if (lookup == "No results" || lookup == "Canceled" || lookup == "Request timed out") {
if (typeof lookup === "string") {
return lookup;
} else {
id = lookup.id;

View file

@ -44,7 +44,7 @@ banner.callback = async function (msg, line, [user], {server, guild}) {
}
} else if (user) {
const lookup = await lookupUser(msg, user);
if (lookup == "No results" || lookup == "Canceled" || lookup == "Request timed out") {
if (typeof lookup === "string") {
return lookup;
} else {
id = lookup.id;

View file

@ -15,7 +15,7 @@ decoration.callback = async function (msg, line, [user]) {
if (user) {
const lookup = await lookupUser(msg, user);
if (lookup == "No results" || lookup == "Canceled" || lookup == "Request timed out") {
if (typeof lookup === "string") {
return lookup;
} else {
id = lookup.id;

View file

@ -52,7 +52,7 @@ presence.callback = async function (msg, line) {
let target;
if (line) {
const user = await lookupUser(msg, line);
if (user == "No results" || user == "Canceled" || user == "Request timed out") {
if (typeof user === "string") {
return user;
} else {
let member = user;

View file

@ -70,7 +70,7 @@ userinfo.callback = async function (msg, line) {
id = msg.author?.id ?? msg.user?.id;
} else {
const lookup = await lookupUser(msg, line);
if (lookup == "No results" || lookup == "Canceled" || lookup == "Request timed out") {
if (typeof lookup === "string") {
return lookup;
} else {
id = lookup.id;

View file

@ -112,7 +112,11 @@ async function selectionMessage(msg, heading, options, timeout = 30000, maxItems
async function lookupUser(msg, str, filter) {
if (REGEX_SNOWFLAKE.test(str)) {
try {
return await hf.bot.requestHandler.request("GET", APIEndpoints.USER(str.match(REGEX_SNOWFLAKE)[1]), true);
} catch (err) {
return err.message;
}
}
let users;