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
This commit is contained in:
Ryfter 2025-01-25 14:00:44 -05:00
parent 1cd541fd67
commit 56d5b10e1b

View file

@ -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 (
<ErrorBoundary>
<ModalRoot {...props} size={ModalSize.LARGE}>
@ -163,7 +171,11 @@ function InRoleModal({ guildId, props, roleId }: { guildId: string; props: Modal
return (
<div
className={cl("modal-list-item-btn")}
onClick={() => 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}