fix Expression Cloner, ServerInfo & SeeSummaries plugins (#3536)

This commit is contained in:
sadan4 2025-07-03 20:14:59 -04:00 committed by dorkbutt
parent 09ed2c78ba
commit bef4b01382
No known key found for this signature in database
5 changed files with 33 additions and 12 deletions

View file

@ -20,12 +20,13 @@ import { findGroupChildrenByChildId, NavContextMenuPatchCallback } from "@api/Co
import { migratePluginSettings } from "@api/Settings"; import { migratePluginSettings } from "@api/Settings";
import { CheckedTextInput } from "@components/CheckedTextInput"; import { CheckedTextInput } from "@components/CheckedTextInput";
import { Devs } from "@utils/constants"; import { Devs } from "@utils/constants";
import { getGuildAcronym } from "@utils/discord";
import { Logger } from "@utils/Logger"; import { Logger } from "@utils/Logger";
import { Margins } from "@utils/margins"; import { Margins } from "@utils/margins";
import { ModalContent, ModalHeader, ModalRoot, openModalLazy } from "@utils/modal"; import { ModalContent, ModalHeader, ModalRoot, openModalLazy } from "@utils/modal";
import definePlugin from "@utils/types"; import definePlugin from "@utils/types";
import { findByCodeLazy, findStoreLazy } from "@webpack"; import { findByCodeLazy, findStoreLazy } from "@webpack";
import { Constants, EmojiStore, FluxDispatcher, Forms, GuildStore, Menu, PermissionsBits, PermissionStore, React, RestAPI, Toasts, Tooltip, UserStore } from "@webpack/common"; import { Constants, EmojiStore, FluxDispatcher, Forms, GuildStore, IconUtils, Menu, PermissionsBits, PermissionStore, React, RestAPI, Toasts, Tooltip, UserStore } from "@webpack/common";
import { Guild } from "discord-types/general"; import { Guild } from "discord-types/general";
import { Promisable } from "type-fest"; import { Promisable } from "type-fest";
@ -250,13 +251,18 @@ function CloneModal({ data }: { data: Sticker | Emoji; }) {
width: "100%", width: "100%",
height: "100%", height: "100%",
}} }}
src={g.getIconURL(512, true)} src={IconUtils.getGuildIconURL({
id: g.id,
icon: g.icon,
canAnimate: true,
size: 512
})}
alt={g.name} alt={g.name}
/> />
) : ( ) : (
<Forms.FormText <Forms.FormText
style={{ style={{
fontSize: getFontSize(g.acronym), fontSize: getFontSize(getGuildAcronym(g)),
width: "100%", width: "100%",
overflow: "hidden", overflow: "hidden",
whiteSpace: "nowrap", whiteSpace: "nowrap",
@ -264,7 +270,7 @@ function CloneModal({ data }: { data: Sticker | Emoji; }) {
cursor: isCloning ? "not-allowed" : "pointer", cursor: isCloning ? "not-allowed" : "pointer",
}} }}
> >
{g.acronym} {getGuildAcronym(g)}
</Forms.FormText> </Forms.FormText>
)} )}
</div> </div>

View file

@ -18,7 +18,7 @@
import ErrorBoundary from "@components/ErrorBoundary"; import ErrorBoundary from "@components/ErrorBoundary";
import { Devs } from "@utils/constants"; import { Devs } from "@utils/constants";
import { getIntlMessage } from "@utils/discord"; import { getIntlMessage, hasGuildFeature } from "@utils/discord";
import definePlugin from "@utils/types"; import definePlugin from "@utils/types";
import { Constants, GuildStore, PermissionStore, RestAPI } from "@webpack/common"; import { Constants, GuildStore, PermissionStore, RestAPI } from "@webpack/common";
@ -27,8 +27,8 @@ function showDisableInvites(guildId: string) {
if (!guild) return false; if (!guild) return false;
return ( return (
// @ts-ignore // @ts-expect-error
!guild.hasFeature("INVITES_DISABLED") && !hasGuildFeature(guild, "INVITES_DISABLED") &&
PermissionStore.getGuildPermissionProps(guild).canManageRoles PermissionStore.getGuildPermissionProps(guild).canManageRoles
); );
} }

View file

@ -7,6 +7,7 @@
import { DataStore } from "@api/index"; import { DataStore } from "@api/index";
import { definePluginSettings } from "@api/Settings"; import { definePluginSettings } from "@api/Settings";
import { Devs } from "@utils/constants"; import { Devs } from "@utils/constants";
import { hasGuildFeature } from "@utils/discord";
import definePlugin, { OptionType } from "@utils/types"; import definePlugin, { OptionType } from "@utils/types";
import { findByCodeLazy, findByPropsLazy } from "@webpack"; import { findByCodeLazy, findByPropsLazy } from "@webpack";
import { ChannelStore, GuildStore } from "@webpack/common"; import { ChannelStore, GuildStore } from "@webpack/common";
@ -57,7 +58,7 @@ export default definePlugin({
{ {
find: "SUMMARIZEABLE.has", find: "SUMMARIZEABLE.has",
replacement: { replacement: {
match: /\i\.hasFeature\(\i\.\i\.SUMMARIES_ENABLED\w+?\)/g, match: /\i\.features\.has\(\i\.\i\.SUMMARIES_ENABLED\w+?\)/g,
replace: "true" replace: "true"
} }
}, },
@ -109,7 +110,8 @@ export default definePlugin({
const channel = ChannelStore.getChannel(channelId); const channel = ChannelStore.getChannel(channelId);
// SUMMARIES_ENABLED feature is not in discord-types // SUMMARIES_ENABLED feature is not in discord-types
const guild = GuildStore.getGuild(channel.guild_id); const guild = GuildStore.getGuild(channel.guild_id);
// @ts-ignore
return guild.hasFeature("SUMMARIES_ENABLED_GA"); // @ts-expect-error
return hasGuildFeature(guild, "SUMMARIES_ENABLED_GA");
} }
}); });

View file

@ -7,7 +7,7 @@
import "./styles.css"; import "./styles.css";
import { classNameFactory } from "@api/Styles"; import { classNameFactory } from "@api/Styles";
import { openImageModal, openUserProfile } from "@utils/discord"; import { getGuildAcronym, openImageModal, openUserProfile } from "@utils/discord";
import { classes } from "@utils/misc"; import { classes } from "@utils/misc";
import { ModalRoot, ModalSize, openModal } from "@utils/modal"; import { ModalRoot, ModalSize, openModal } from "@utils/modal";
import { useAwaiter } from "@utils/react"; import { useAwaiter } from "@utils/react";
@ -103,7 +103,7 @@ function GuildInfoModal({ guild }: GuildProps) {
width: 512, width: 512,
})} })}
/> />
: <div aria-hidden className={classes(IconClasses.childWrapper, IconClasses.acronym)}>{guild.acronym}</div> : <div aria-hidden className={classes(IconClasses.childWrapper, IconClasses.acronym)}>{getGuildAcronym(guild)}</div>
} }
<div className={cl("name-and-description")}> <div className={cl("name-and-description")}>

View file

@ -19,6 +19,7 @@
import { MessageObject } from "@api/MessageEvents"; import { MessageObject } from "@api/MessageEvents";
import { ChannelActionCreators, ChannelStore, ComponentDispatch, Constants, FluxDispatcher, GuildStore, i18n, IconUtils, InviteActions, MessageActions, RestAPI, SelectedChannelStore, SelectedGuildStore, UserProfileActions, UserProfileStore, UserSettingsActionCreators, UserUtils } from "@webpack/common"; import { ChannelActionCreators, ChannelStore, ComponentDispatch, Constants, FluxDispatcher, GuildStore, i18n, IconUtils, InviteActions, MessageActions, RestAPI, SelectedChannelStore, SelectedGuildStore, UserProfileActions, UserProfileStore, UserSettingsActionCreators, UserUtils } from "@webpack/common";
import { Channel, Guild, Message, User } from "discord-types/general"; import { Channel, Guild, Message, User } from "discord-types/general";
import GuildFeatures from "discord-types/other/Constants";
import { Except } from "type-fest"; import { Except } from "type-fest";
import { runtimeHashMessageKey } from "./intlHash"; import { runtimeHashMessageKey } from "./intlHash";
@ -218,3 +219,15 @@ export function getEmojiURL(id: string, animated: boolean, size: number) {
const url = IconUtils.getEmojiURL({ id, animated, size }); const url = IconUtils.getEmojiURL({ id, animated, size });
return animated ? url.replace(".webp", ".gif") : url; return animated ? url.replace(".webp", ".gif") : url;
} }
// Discord has a similar function in their code
export function getGuildAcronym(guild: Guild): string {
return guild.name
.replaceAll("'s ", " ")
.replace(/\w+/g, m => m[0])
.replace(/\s/g, "");
}
export function hasGuildFeature(guild: Guild, feature: keyof GuildFeatures["GuildFeatures"]): boolean {
return guild.features?.has(feature) ?? false;
}