fix Expression Cloner, ServerInfo & SeeSummaries plugins (#3536)
This commit is contained in:
parent
09ed2c78ba
commit
bef4b01382
5 changed files with 33 additions and 12 deletions
|
|
@ -20,12 +20,13 @@ import { findGroupChildrenByChildId, NavContextMenuPatchCallback } from "@api/Co
|
|||
import { migratePluginSettings } from "@api/Settings";
|
||||
import { CheckedTextInput } from "@components/CheckedTextInput";
|
||||
import { Devs } from "@utils/constants";
|
||||
import { getGuildAcronym } from "@utils/discord";
|
||||
import { Logger } from "@utils/Logger";
|
||||
import { Margins } from "@utils/margins";
|
||||
import { ModalContent, ModalHeader, ModalRoot, openModalLazy } from "@utils/modal";
|
||||
import definePlugin from "@utils/types";
|
||||
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 { Promisable } from "type-fest";
|
||||
|
||||
|
|
@ -250,13 +251,18 @@ function CloneModal({ data }: { data: Sticker | Emoji; }) {
|
|||
width: "100%",
|
||||
height: "100%",
|
||||
}}
|
||||
src={g.getIconURL(512, true)}
|
||||
src={IconUtils.getGuildIconURL({
|
||||
id: g.id,
|
||||
icon: g.icon,
|
||||
canAnimate: true,
|
||||
size: 512
|
||||
})}
|
||||
alt={g.name}
|
||||
/>
|
||||
) : (
|
||||
<Forms.FormText
|
||||
style={{
|
||||
fontSize: getFontSize(g.acronym),
|
||||
fontSize: getFontSize(getGuildAcronym(g)),
|
||||
width: "100%",
|
||||
overflow: "hidden",
|
||||
whiteSpace: "nowrap",
|
||||
|
|
@ -264,7 +270,7 @@ function CloneModal({ data }: { data: Sticker | Emoji; }) {
|
|||
cursor: isCloning ? "not-allowed" : "pointer",
|
||||
}}
|
||||
>
|
||||
{g.acronym}
|
||||
{getGuildAcronym(g)}
|
||||
</Forms.FormText>
|
||||
)}
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
import ErrorBoundary from "@components/ErrorBoundary";
|
||||
import { Devs } from "@utils/constants";
|
||||
import { getIntlMessage } from "@utils/discord";
|
||||
import { getIntlMessage, hasGuildFeature } from "@utils/discord";
|
||||
import definePlugin from "@utils/types";
|
||||
import { Constants, GuildStore, PermissionStore, RestAPI } from "@webpack/common";
|
||||
|
||||
|
|
@ -27,8 +27,8 @@ function showDisableInvites(guildId: string) {
|
|||
if (!guild) return false;
|
||||
|
||||
return (
|
||||
// @ts-ignore
|
||||
!guild.hasFeature("INVITES_DISABLED") &&
|
||||
// @ts-expect-error
|
||||
!hasGuildFeature(guild, "INVITES_DISABLED") &&
|
||||
PermissionStore.getGuildPermissionProps(guild).canManageRoles
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
import { DataStore } from "@api/index";
|
||||
import { definePluginSettings } from "@api/Settings";
|
||||
import { Devs } from "@utils/constants";
|
||||
import { hasGuildFeature } from "@utils/discord";
|
||||
import definePlugin, { OptionType } from "@utils/types";
|
||||
import { findByCodeLazy, findByPropsLazy } from "@webpack";
|
||||
import { ChannelStore, GuildStore } from "@webpack/common";
|
||||
|
|
@ -57,7 +58,7 @@ export default definePlugin({
|
|||
{
|
||||
find: "SUMMARIZEABLE.has",
|
||||
replacement: {
|
||||
match: /\i\.hasFeature\(\i\.\i\.SUMMARIES_ENABLED\w+?\)/g,
|
||||
match: /\i\.features\.has\(\i\.\i\.SUMMARIES_ENABLED\w+?\)/g,
|
||||
replace: "true"
|
||||
}
|
||||
},
|
||||
|
|
@ -109,7 +110,8 @@ export default definePlugin({
|
|||
const channel = ChannelStore.getChannel(channelId);
|
||||
// SUMMARIES_ENABLED feature is not in discord-types
|
||||
const guild = GuildStore.getGuild(channel.guild_id);
|
||||
// @ts-ignore
|
||||
return guild.hasFeature("SUMMARIES_ENABLED_GA");
|
||||
|
||||
// @ts-expect-error
|
||||
return hasGuildFeature(guild, "SUMMARIES_ENABLED_GA");
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
import "./styles.css";
|
||||
|
||||
import { classNameFactory } from "@api/Styles";
|
||||
import { openImageModal, openUserProfile } from "@utils/discord";
|
||||
import { getGuildAcronym, openImageModal, openUserProfile } from "@utils/discord";
|
||||
import { classes } from "@utils/misc";
|
||||
import { ModalRoot, ModalSize, openModal } from "@utils/modal";
|
||||
import { useAwaiter } from "@utils/react";
|
||||
|
|
@ -103,7 +103,7 @@ function GuildInfoModal({ guild }: GuildProps) {
|
|||
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")}>
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
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 { Channel, Guild, Message, User } from "discord-types/general";
|
||||
import GuildFeatures from "discord-types/other/Constants";
|
||||
import { Except } from "type-fest";
|
||||
|
||||
import { runtimeHashMessageKey } from "./intlHash";
|
||||
|
|
@ -218,3 +219,15 @@ export function getEmojiURL(id: string, animated: boolean, size: number) {
|
|||
const url = IconUtils.getEmojiURL({ id, animated, size });
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue