From 56d5b10e1b9267d44665436f103f147784bf6237 Mon Sep 17 00:00:00 2001 From: Ryfter Date: Sat, 25 Jan 2025 14:00:44 -0500 Subject: [PATCH] Added 1s delay to stop ratelimits even more added a 1s cooldown between each role selection to stop ratelimits, except if the role has already been fetched --- RoleMembersModal.tsx | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/RoleMembersModal.tsx b/RoleMembersModal.tsx index e14f04e..76c5756 100644 --- a/RoleMembersModal.tsx +++ b/RoleMembersModal.tsx @@ -8,7 +8,7 @@ import ErrorBoundary from "@components/ErrorBoundary"; import { InfoIcon } from "@components/Icons"; import { ModalCloseButton, ModalContent, ModalHeader, ModalProps, ModalRoot, ModalSize, openModal } from "@utils/modal"; import { findByCodeLazy, findExportedComponentLazy } from "@webpack"; -import { Constants, GuildChannelStore, GuildMemberStore, GuildStore, Parser, RestAPI, ScrollerThin, Text, Tooltip, useEffect, UserStore, useState } from "@webpack/common"; +import { Constants, GuildChannelStore, GuildMemberStore, GuildStore, Parser, RestAPI, ScrollerThin, showToast, Text, Tooltip, useEffect, UserStore, useState } from "@webpack/common"; import { UnicodeEmoji } from "@webpack/types"; import type { Role } from "discord-types/general"; @@ -18,7 +18,8 @@ type GetRoleIconData = (role: Role, size: number) => { customIconSrc?: string; u const ThreeDots = findExportedComponentLazy("Dots", "AnimatedDots"); const getRoleIconData: GetRoleIconData = findByCodeLazy("convertSurrogateToName", "customIconSrc", "unicodeEmoji"); - +let rolesFetched2; +let members2; function getRoleIconSrc(role: Role) { const icon = getRoleIconData(role, 20); @@ -60,6 +61,7 @@ function MembersContainer({ guildId, roleId }: { guildId: string; roleId: string ({ body: usersInRole } = response); await GuildUtils.requestMembersById(guildId, usersInRole, !1); setRolesFetched([...rolesFetched, roleId]); + rolesFetched2 = rolesFetched; clearInterval(interval); } catch (error) { console.error("Error fetching members:", error); } }, 1200); @@ -144,6 +146,12 @@ function InRoleModal({ guildId, props, roleId }: { guildId: string; props: Modal const [selectedRole, selectRole] = useState(roles.find(x => x.id === roleId) || roles[0]); + let cooldown; + useEffect(() => { + const timeout = setTimeout(() => cooldown = false, 1000); + return () => clearTimeout(timeout); + }, [selectedRole]); + return ( @@ -163,7 +171,11 @@ function InRoleModal({ guildId, props, roleId }: { guildId: string; props: Modal return (
selectRole(roles[index])} + onClick={() => { + if (selectedRole.id === roles[index].id) return; + cooldown && !rolesFetched2.includes(roles[index].id) ? showToast("To limit ratelimiting, please wait at least a second before switching roles.") + : (selectRole(roles[index]), cooldown = true); + }} role="button" tabIndex={0} key={role.id}