From 14c236a7218aae082f419072dc4d83ae7cd054ee Mon Sep 17 00:00:00 2001 From: harryob <55142896+harryob@users.noreply.github.com> Date: Tue, 22 Oct 2024 13:51:34 +0100 Subject: [PATCH] properly prevent spamming the api --- src/components/userLookup.tsx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/components/userLookup.tsx b/src/components/userLookup.tsx index c7da1a2..88c9aaf 100644 --- a/src/components/userLookup.tsx +++ b/src/components/userLookup.tsx @@ -89,10 +89,13 @@ export const LookupMenu: React.FC = ( updateUser({ userCkey: value }); return; } - if ( - potentialUser && - (!userData || userData.ckey != potentialUser.toLowerCase()) - ) { + + if (!potentialUser) return; + + const re = /[\\^]|[^a-z0-9@]/g; + const checked = potentialUser.toLowerCase().replace(re, ""); + + if (potentialUser && (!userData || userData.ckey != checked)) { updateUser({ userCkey: potentialUser as string }); } }, [value, userData, discordId, updateUser, potentialUser, user, loading]);