aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuca Matei Pintilie <lucafulger@gmail.com>2022-09-17 14:33:57 +0000
committerLuca Matei Pintilie <lucafulger@gmail.com>2022-09-17 14:33:57 +0000
commit98cffec9af364c56776e7a2304c025bf7241965b (patch)
tree822da21464996ee1860d3e2de26e0c42a38c6f3e
parent849135ac4d5206e34980e73cec48706d169aa7a6 (diff)
downloadspeedrunbot-slash-98cffec9af364c56776e7a2304c025bf7241965b.tar
speedrunbot-slash-98cffec9af364c56776e7a2304c025bf7241965b.tar.gz
speedrunbot-slash-98cffec9af364c56776e7a2304c025bf7241965b.tar.bz2
speedrunbot-slash-98cffec9af364c56776e7a2304c025bf7241965b.tar.lz
speedrunbot-slash-98cffec9af364c56776e7a2304c025bf7241965b.tar.xz
speedrunbot-slash-98cffec9af364c56776e7a2304c025bf7241965b.tar.zst
speedrunbot-slash-98cffec9af364c56776e7a2304c025bf7241965b.zip
Lookup the user directly if it's not already found
-rwxr-xr-xsrc/srcom/utils.ts21
1 files changed, 10 insertions, 11 deletions
diff --git a/src/srcom/utils.ts b/src/srcom/utils.ts
index 9c96fa2..82a83c4 100755
--- a/src/srcom/utils.ts
+++ b/src/srcom/utils.ts
@@ -416,14 +416,6 @@ export async function searchUsers(name: string): Promise<{
}[]> {
if (!name) return [];
const output: { name: string }[] = [];
- let shortName: Promise<{ name: string } | false> | false = false;
-
- if (name.length <= 2) {
- shortName = fetch(`${SRC_API}/users?lookup=${encodeURIComponent(name)}`)
- .then((res) => res.json()).then((user: { data: SpeedrunCom.User[] }) => ({
- name: user.data[0].names.international,
- }), (_) => false);
- }
// This is super un official way and can break at any time
// Which is why we fall back on the normal API
@@ -459,9 +451,16 @@ export async function searchUsers(name: string): Promise<{
name: user.names.international,
})));
}
- if (shortName) {
- const name = await shortName;
- if (name) output.splice(0, 0, name);
+
+ // If the name still hasn't been found then try to get it directly
+ if (!output.find((user) => user.name.toLowerCase() === name.toLowerCase())) {
+ const shortName: false | { name: string } = await fetch(
+ `${SRC_API}/users?lookup=${encodeURIComponent(name)}`,
+ )
+ .then((res) => res.json()).then((user: { data: SpeedrunCom.User[] }) => ({
+ name: user.data[0].names.international,
+ }), (_) => false);
+ if (shortName) output.unshift(shortName)
}
return output;