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:
parent
1cd541fd67
commit
56d5b10e1b
1 changed files with 15 additions and 3 deletions
|
@ -8,7 +8,7 @@ import ErrorBoundary from "@components/ErrorBoundary";
|
||||||
import { InfoIcon } from "@components/Icons";
|
import { InfoIcon } from "@components/Icons";
|
||||||
import { ModalCloseButton, ModalContent, ModalHeader, ModalProps, ModalRoot, ModalSize, openModal } from "@utils/modal";
|
import { ModalCloseButton, ModalContent, ModalHeader, ModalProps, ModalRoot, ModalSize, openModal } from "@utils/modal";
|
||||||
import { findByCodeLazy, findExportedComponentLazy } from "@webpack";
|
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 { UnicodeEmoji } from "@webpack/types";
|
||||||
import type { Role } from "discord-types/general";
|
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 ThreeDots = findExportedComponentLazy("Dots", "AnimatedDots");
|
||||||
const getRoleIconData: GetRoleIconData = findByCodeLazy("convertSurrogateToName", "customIconSrc", "unicodeEmoji");
|
const getRoleIconData: GetRoleIconData = findByCodeLazy("convertSurrogateToName", "customIconSrc", "unicodeEmoji");
|
||||||
|
|
||||||
|
let rolesFetched2;
|
||||||
|
let members2;
|
||||||
|
|
||||||
function getRoleIconSrc(role: Role) {
|
function getRoleIconSrc(role: Role) {
|
||||||
const icon = getRoleIconData(role, 20);
|
const icon = getRoleIconData(role, 20);
|
||||||
|
@ -60,6 +61,7 @@ function MembersContainer({ guildId, roleId }: { guildId: string; roleId: string
|
||||||
({ body: usersInRole } = response);
|
({ body: usersInRole } = response);
|
||||||
await GuildUtils.requestMembersById(guildId, usersInRole, !1);
|
await GuildUtils.requestMembersById(guildId, usersInRole, !1);
|
||||||
setRolesFetched([...rolesFetched, roleId]);
|
setRolesFetched([...rolesFetched, roleId]);
|
||||||
|
rolesFetched2 = rolesFetched;
|
||||||
clearInterval(interval);
|
clearInterval(interval);
|
||||||
} catch (error) { console.error("Error fetching members:", error); }
|
} catch (error) { console.error("Error fetching members:", error); }
|
||||||
}, 1200);
|
}, 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]);
|
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 (
|
return (
|
||||||
<ErrorBoundary>
|
<ErrorBoundary>
|
||||||
<ModalRoot {...props} size={ModalSize.LARGE}>
|
<ModalRoot {...props} size={ModalSize.LARGE}>
|
||||||
|
@ -163,7 +171,11 @@ function InRoleModal({ guildId, props, roleId }: { guildId: string; props: Modal
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={cl("modal-list-item-btn")}
|
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"
|
role="button"
|
||||||
tabIndex={0}
|
tabIndex={0}
|
||||||
key={role.id}
|
key={role.id}
|
||||||
|
|
Loading…
Reference in a new issue