From 875f136d523ce6b7461e9efca435e13764f42aa6 Mon Sep 17 00:00:00 2001
From: thororen1234 <78185467+thororen1234@users.noreply.github.com>
Date: Mon, 30 Jun 2025 15:01:22 -0400
Subject: [PATCH] Fix GuildStore Crashing
---
src/equicordplugins/clientSideBlock/index.tsx | 4 ++--
src/equicordplugins/inRole/index.tsx | 6 +++---
src/equicordplugins/toastNotifications/index.tsx | 4 ++--
src/plugins/betterRoleContext/index.tsx | 4 ++--
src/plugins/mentionAvatars/index.tsx | 4 ++--
.../components/RolesAndUsersPermissions.tsx | 4 ++--
src/plugins/roleColorEverywhere/index.tsx | 4 ++--
src/plugins/viewRaw/index.tsx | 4 ++--
src/plugins/xsOverlay/index.tsx | 4 ++--
src/webpack/common/stores.ts | 2 ++
src/webpack/common/types/stores.d.ts | 3 +++
11 files changed, 24 insertions(+), 19 deletions(-)
diff --git a/src/equicordplugins/clientSideBlock/index.tsx b/src/equicordplugins/clientSideBlock/index.tsx
index bd5cb4a5a..5ef66c1c1 100644
--- a/src/equicordplugins/clientSideBlock/index.tsx
+++ b/src/equicordplugins/clientSideBlock/index.tsx
@@ -7,7 +7,7 @@
import { definePluginSettings } from "@api/Settings";
import { Devs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types";
-import { ChannelStore, GuildMemberStore, GuildStore, RelationshipStore, Text, UserStore } from "@webpack/common";
+import { ChannelStore, GuildMemberStore, GuildRoleStore, RelationshipStore, Text, UserStore } from "@webpack/common";
import { GuildMember } from "discord-types/general";
const settings = definePluginSettings(
@@ -99,7 +99,7 @@ function shouldHideUser(userId: string, channelId?: string) {
// This is really horror
function isRoleAllBlockedMembers(roleId, guildId) {
- const role = GuildStore.getRole(guildId, roleId);
+ const role = GuildRoleStore.getRole(guildId, roleId);
if (!role) return false;
const membersWithRole: GuildMember[] = GuildMemberStore.getMembers(guildId).filter(member => member.roles.includes(roleId));
diff --git a/src/equicordplugins/inRole/index.tsx b/src/equicordplugins/inRole/index.tsx
index d203c49a4..079e18d39 100644
--- a/src/equicordplugins/inRole/index.tsx
+++ b/src/equicordplugins/inRole/index.tsx
@@ -12,7 +12,7 @@ import { InfoIcon } from "@components/Icons";
import { Devs } from "@utils/constants";
import { getCurrentChannel, getCurrentGuild } from "@utils/discord";
import definePlugin from "@utils/types";
-import { Forms, GuildMemberStore, GuildStore, Menu, Parser } from "@webpack/common";
+import { Forms, GuildMemberStore, GuildRoleStore, Menu, Parser } from "@webpack/common";
import { GuildMember } from "discord-types/general";
import { showInRoleModal } from "./RoleMembersModal";
@@ -82,7 +82,7 @@ export default definePlugin({
const channel = getCurrentChannel();
if (!channel) return;
- const role = GuildStore.getRole(guild.id, id);
+ const role = GuildRoleStore.getRole(guild.id, id);
if (!role) return;
children.push(
@@ -108,7 +108,7 @@ export default definePlugin({
const roleIds = roleMentions.map(mention => mention.match(/<@&(\d+)>/)![1]);
- const role = GuildStore.getRole(guild.id, roleIds);
+ const role = GuildRoleStore.getRole(guild.id, roleIds);
if (!role) return;
children.push(
diff --git a/src/equicordplugins/toastNotifications/index.tsx b/src/equicordplugins/toastNotifications/index.tsx
index efc37f70f..d654dd778 100644
--- a/src/equicordplugins/toastNotifications/index.tsx
+++ b/src/equicordplugins/toastNotifications/index.tsx
@@ -21,7 +21,7 @@ import { makeRange } from "@components/PluginSettings/components";
import { EquicordDevs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types";
import { findByPropsLazy, findStore } from "@webpack";
-import { Button, ChannelStore, GuildStore, NavigationRouter, RelationshipStore, SelectedChannelStore, UserStore } from "@webpack/common";
+import { Button, ChannelStore, GuildRoleStore, NavigationRouter, RelationshipStore, SelectedChannelStore, UserStore } from "@webpack/common";
import { Channel, Message, User } from "discord-types/general";
import { ReactNode } from "react";
@@ -196,7 +196,7 @@ const addMention = (id: string, type: string, guildId?: string): ReactNode => {
else if (type === "channel")
name = `#${ChannelStore.getChannel(id)?.name || "unknown-channel"}`;
else if (type === "role" && guildId)
- name = `@${GuildStore.getGuild(guildId).getRole(id)?.name || "unknown-role"}`;
+ name = `@${GuildRoleStore.getRole(guildId, id)?.name || "unknown-role"}`;
// Return the mention as a styled span.
return (
diff --git a/src/plugins/betterRoleContext/index.tsx b/src/plugins/betterRoleContext/index.tsx
index a9bab1a79..f9eae586d 100644
--- a/src/plugins/betterRoleContext/index.tsx
+++ b/src/plugins/betterRoleContext/index.tsx
@@ -12,7 +12,7 @@ import { Devs } from "@utils/constants";
import { getCurrentGuild, openImageModal } from "@utils/discord";
import definePlugin, { OptionType } from "@utils/types";
import { findByPropsLazy } from "@webpack";
-import { GuildStore, Menu, PermissionStore } from "@webpack/common";
+import { GuildRoleStore, Menu, PermissionStore } from "@webpack/common";
const GuildSettingsActions = findByPropsLazy("open", "selectRole", "updateGuild");
@@ -80,7 +80,7 @@ export default definePlugin({
const guild = getCurrentGuild();
if (!guild) return;
- const role = GuildStore.getRole(guild.id, id);
+ const role = GuildRoleStore.getRole(guild.id, id);
if (!role) return;
if (role.colorString) {
diff --git a/src/plugins/mentionAvatars/index.tsx b/src/plugins/mentionAvatars/index.tsx
index 231253394..761daaac2 100644
--- a/src/plugins/mentionAvatars/index.tsx
+++ b/src/plugins/mentionAvatars/index.tsx
@@ -10,7 +10,7 @@ import { definePluginSettings } from "@api/Settings";
import ErrorBoundary from "@components/ErrorBoundary";
import { Devs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types";
-import { GuildStore, SelectedGuildStore, useState } from "@webpack/common";
+import { GuildRoleStore, SelectedGuildStore, useState } from "@webpack/common";
import { User } from "discord-types/general";
const settings = definePluginSettings({
@@ -88,7 +88,7 @@ export default definePlugin({
// Discord uses Role Mentions for uncached users because .... idk
if (!roleId) return null;
- const role = GuildStore.getRole(guildId, roleId);
+ const role = GuildRoleStore.getRole(guildId, roleId);
if (!role?.icon) return ;
diff --git a/src/plugins/permissionsViewer/components/RolesAndUsersPermissions.tsx b/src/plugins/permissionsViewer/components/RolesAndUsersPermissions.tsx
index ed620d7f3..1d1202f7f 100644
--- a/src/plugins/permissionsViewer/components/RolesAndUsersPermissions.tsx
+++ b/src/plugins/permissionsViewer/components/RolesAndUsersPermissions.tsx
@@ -23,7 +23,7 @@ import { copyToClipboard } from "@utils/clipboard";
import { getIntlMessage, getUniqueUsername } from "@utils/discord";
import { ModalCloseButton, ModalContent, ModalHeader, ModalProps, ModalRoot, ModalSize, openModal } from "@utils/modal";
import { findByCodeLazy } from "@webpack";
-import { ContextMenuApi, FluxDispatcher, GuildMemberStore, GuildStore, i18n, Menu, PermissionsBits, ScrollerThin, Text, Tooltip, useEffect, useMemo, UserStore, useState, useStateFromStores } from "@webpack/common";
+import { ContextMenuApi, FluxDispatcher, GuildMemberStore, GuildRoleStore, GuildStore, i18n, Menu, PermissionsBits, ScrollerThin, Text, Tooltip, useEffect, useMemo, UserStore, useState, useStateFromStores } from "@webpack/common";
import { UnicodeEmoji } from "@webpack/types";
import type { Guild, Role, User } from "discord-types/general";
@@ -238,7 +238,7 @@ function RoleContextMenu({ guild, roleId, onClose }: { guild: Guild; roleId: str
id={cl("view-as-role")}
label={getIntlMessage("VIEW_AS_ROLE")}
action={() => {
- const role = GuildStore.getRole(guild.id, roleId);
+ const role = GuildRoleStore.getRole(guild.id, roleId);
if (!role) return;
onClose();
diff --git a/src/plugins/roleColorEverywhere/index.tsx b/src/plugins/roleColorEverywhere/index.tsx
index eaae42af7..80f24e1ce 100644
--- a/src/plugins/roleColorEverywhere/index.tsx
+++ b/src/plugins/roleColorEverywhere/index.tsx
@@ -24,7 +24,7 @@ import { Devs } from "@utils/constants";
import { Logger } from "@utils/Logger";
import definePlugin, { OptionType } from "@utils/types";
import { findByCodeLazy } from "@webpack";
-import { ChannelStore, GuildMemberStore, GuildStore } from "@webpack/common";
+import { ChannelStore, GuildMemberStore, GuildRoleStore, GuildStore } from "@webpack/common";
const useMessageAuthor = findByCodeLazy('"Result cannot be null because the message is not null"');
@@ -216,7 +216,7 @@ export default definePlugin({
},
RoleGroupColor: ErrorBoundary.wrap(({ id, count, title, guildId, label }: { id: string; count: number; title: string; guildId: string; label: string; }) => {
- const role = GuildStore.getRole(guildId, id);
+ const role = GuildRoleStore.getRole(guildId, id);
return (
m.ANNOUNCEMENT_THREAD === 10);
@@ -267,7 +267,7 @@ export default definePlugin({
// color role mentions (unity styling btw lol)
if (message.mention_roles.length > 0) {
for (const roleId of message.mention_roles) {
- const role = GuildStore.getRole(channel.guild_id, roleId);
+ const role = GuildRoleStore.getRole(channel.guild_id, roleId);
if (!role) continue;
const roleColor = role.colorString ?? `#${pingColor}`;
finalMsg = finalMsg.replace(`<@&${roleId}>`, `@${role.name}`);
diff --git a/src/webpack/common/stores.ts b/src/webpack/common/stores.ts
index d00649c7d..efc4fcb22 100644
--- a/src/webpack/common/stores.ts
+++ b/src/webpack/common/stores.ts
@@ -41,6 +41,7 @@ export let PresenceStore: GenericStore;
export let VoiceStateStore: GenericStore;
export let GuildStore: t.GuildStore;
+export let GuildRoleStore: t.GuildRoleStore;
export let UserStore: Stores.UserStore & t.FluxStore;
export let UserProfileStore: GenericStore;
export let SelectedChannelStore: Stores.SelectedChannelStore & t.FluxStore;
@@ -75,6 +76,7 @@ waitForStore("ChannelStore", m => ChannelStore = m);
waitForStore("SelectedChannelStore", m => SelectedChannelStore = m);
waitForStore("SelectedGuildStore", m => SelectedGuildStore = m);
waitForStore("GuildStore", m => GuildStore = m);
+waitForStore("GuildRoleStore", m => GuildRoleStore = m);
waitForStore("GuildMemberStore", m => GuildMemberStore = m);
waitForStore("RelationshipStore", m => RelationshipStore = m);
waitForStore("PermissionStore", m => PermissionStore = m);
diff --git a/src/webpack/common/types/stores.d.ts b/src/webpack/common/types/stores.d.ts
index f14a3fc1a..73cb88814 100644
--- a/src/webpack/common/types/stores.d.ts
+++ b/src/webpack/common/types/stores.d.ts
@@ -253,6 +253,9 @@ export class GuildStore extends FluxStore {
getGuildCount(): number;
getGuilds(): Record;
getGuildIds(): string[];
+}
+
+export class GuildRoleStore extends FluxStore {
getRole(guildId: string, roleId: string): Role;
getRoles(guildId: string): Record;
getAllGuildRoles(): Record>;