diff --git a/src/plugins/messageLinkEmbeds/index.tsx b/src/plugins/messageLinkEmbeds/index.tsx index c7b3bd012..e600d737d 100644 --- a/src/plugins/messageLinkEmbeds/index.tsx +++ b/src/plugins/messageLinkEmbeds/index.tsx @@ -18,7 +18,6 @@ import { addAccessory } from "@api/MessageAccessories"; import { definePluginSettings } from "@api/Settings"; -import { getSettingStoreLazy } from "@api/SettingsStore"; import ErrorBoundary from "@components/ErrorBoundary"; import { Devs } from "@utils/constants.js"; import { classes } from "@utils/misc"; @@ -36,6 +35,7 @@ import { PermissionStore, RestAPI, Text, + TextAndImagesSettingsStores, UserStore } from "@webpack/common"; import { Channel, Guild, Message } from "discord-types/general"; @@ -46,12 +46,11 @@ const messageCache = new Map(); const Embed = LazyComponent(() => findByCode(".inlineMediaEmbed")); -const ChannelMessage = LazyComponent(() => find(m => m.type?.toString()?.includes('["message","compact","className",'))); +const AutoModEmbed = LazyComponent(() => findByCode(".withFooter]:", "childrenMessageContent:")); +const ChannelMessage = LazyComponent(() => find(m => m.type?.toString()?.includes("renderSimpleAccessories)"))); const SearchResultClasses = findByPropsLazy("message", "searchResult"); -let AutoModEmbed: React.ComponentType = () => null; - const messageLinkRegex = /(?; } -const compactModeEnabled = getSettingStoreLazy("textAndImages", "messageDisplayCompact")!; - function AutomodEmbedAccessory(props: MessageEmbedProps): JSX.Element | null { const { message, channel, guildID } = props; + const compact = TextAndImagesSettingsStores.MessageDisplayCompact.useSetting(); const isDM = guildID === "@me"; const images = getImages(message); const { parse } = Parser; @@ -338,7 +336,7 @@ function AutomodEmbedAccessory(props: MessageEmbedProps): JSX.Element | null { {isDM ? " - Direct Message" : " - " + GuildStore.getGuild(channel.guild_id)?.name} } - compact={compactModeEnabled.getSetting()} + compact={compact} content={ <> {message.content || message.attachments.length <= images.length @@ -365,20 +363,7 @@ export default definePlugin({ name: "MessageLinkEmbeds", description: "Adds a preview to messages that link another message", authors: [Devs.TheSun, Devs.Ven, Devs.RyanCaoDev], - dependencies: ["MessageAccessoriesAPI", "SettingsStoreAPI"], - patches: [ - { - find: ".embedCard", - replacement: [{ - match: /function (\i)\(\i\){var \i=\i\.message,\i=\i\.channel.{0,200}\.hideTimestamp/, - replace: "$self.AutoModEmbed=$1;$&" - }] - } - ], - - set AutoModEmbed(e: any) { - AutoModEmbed = e; - }, + dependencies: ["MessageAccessoriesAPI"], settings, diff --git a/src/plugins/moreUserTags/index.tsx b/src/plugins/moreUserTags/index.tsx index c8820f8be..9921bca8e 100644 --- a/src/plugins/moreUserTags/index.tsx +++ b/src/plugins/moreUserTags/index.tsx @@ -22,7 +22,7 @@ import { Devs } from "@utils/constants"; import { Margins } from "@utils/margins"; import definePlugin, { OptionType } from "@utils/types"; import { findByPropsLazy, findLazy } from "@webpack"; -import { Card, ChannelStore, Forms, GuildStore, Switch, TextInput, Tooltip, useState } from "@webpack/common"; +import { Card, ChannelStore, Forms, GuildStore, PermissionsBits, Switch, TextInput, Tooltip, useState } from "@webpack/common"; import { RC } from "@webpack/types"; import { Channel, Message, User } from "discord-types/general"; @@ -58,7 +58,6 @@ const PermissionUtil = findByPropsLazy("computePermissions", "canEveryoneRole") computePermissions({ ...args }): bigint; }; -const Permissions = findByPropsLazy("SEND_MESSAGES", "VIEW_CREATOR_MONETIZATION_ANALYTICS") as Record; const Tag = findLazy(m => m.Types?.[0] === "BOT") as RC<{ type?: number, className?: string, useRemSizes?: boolean; }> & { Types: Record; }; const isWebhook = (message: Message, user: User) => !!message?.webhookId && user.isNonUserBot(); @@ -188,17 +187,14 @@ export default definePlugin({ patches: [ // add tags to the tag list { - find: '.BOT=0]="BOT"', - replacement: [ - // add tags to the exported tags list (Tag.Types) - { - match: /(\i)\[.\.BOT=0\]="BOT";/, - replace: "$&$1=$self.addTagVariants($1);" - } - ] + find: "BotTagTypes:", + replacement: { + match: /\((\i)=\{\}\)\)\[(\i)\.BOT/, + replace: "($1=$self.getTagTypes()))[$2.BOT" + } }, { - find: ".DISCORD_SYSTEM_MESSAGE_BOT_TAG_TOOLTIP;", + find: ".DISCORD_SYSTEM_MESSAGE_BOT_TAG_TOOLTIP,", replacement: [ // make the tag show the right text { @@ -213,25 +209,25 @@ export default definePlugin({ }, // add HTML data attributes (for easier theming) { - match: /children:\[(?=\i\?null:\i,\i,\(0,\i\.jsx\)\("span",{className:\i\(\)\.botText,children:(\i)}\)\])/, - replace: "'data-tag':$1.toLowerCase(),children:[" + match: /.botText,children:(\i)}\)]/, + replace: "$&,'data-tag':$1.toLowerCase()" } ], }, // in messages { - find: ".Types.ORIGINAL_POSTER", + find: "renderSystemTag:", replacement: { - match: /return null==(\i)\?null:\(0,/, - replace: "$1=$self.getTag({...arguments[0],origType:$1,location:'chat'});$&" + match: /;return\((\(null==\i\?void 0:\i\.isSystemDM\(\).+?.Types.ORIGINAL_POSTER\)),null==(\i)\)/, + replace: ";$1;$2=$self.getTag({...arguments[0],origType:$2,location:'chat'});return $2 == null" } }, // in the member list { find: ".Messages.GUILD_OWNER,", replacement: { - match: /(?\i)=\(null==.{0,50}\.BOT,null!=(?\i)&&\i\.bot/, - replace: "$ = $self.getTag({user: $, channel: arguments[0].channel, origType: $.bot ? 0 : null, location: 'not-chat' }), typeof $ === 'number'" + match: /(?\i)=\(null==.{0,100}\.BOT;return null!=(?\i)&&\i\.bot/, + replace: "$ = $self.getTag({user: $, channel: arguments[0].channel, origType: $.bot ? 0 : null, location: 'not-chat' }); return typeof $ === 'number'" } }, // pass channel id down props to be used in profiles @@ -251,11 +247,18 @@ export default definePlugin({ }, // in profiles { - find: "showStreamerModeTooltip:", - replacement: { - match: /,botType:(\i\((\i)\)),/g, - replace: ",botType:$self.getTag({user:$2,channelId:arguments[0].moreTags_channelId,origType:$1,location:'not-chat'})," - } + find: ",overrideDiscriminator:", + replacement: [ + { + // prevent channel id from getting ghosted + // it's either this or extremely long lookbehind + match: /user:\i,nick:\i,/, + replace: "$&moreTags_channelId," + }, { + match: /,botType:(\i\((\i)\)),/g, + replace: ",botType:$self.getTag({user:$2,channelId:moreTags_channelId,origType:$1,location:'not-chat'})," + } + ] }, ], @@ -295,24 +298,25 @@ export default definePlugin({ if (!guild) return []; const permissions = PermissionUtil.computePermissions({ user, context: guild, overwrites: channel.permissionOverwrites }); - return Object.entries(Permissions) + return Object.entries(PermissionsBits) .map(([perm, permInt]) => permissions & permInt ? perm : "" ) .filter(Boolean); }, - addTagVariants(tagConstant) { + getTagTypes() { + const obj = {}; let i = 100; tags.forEach(({ name }) => { - tagConstant[name] = ++i; - tagConstant[i] = name; - tagConstant[`${name}-BOT`] = ++i; - tagConstant[i] = `${name}-BOT`; - tagConstant[`${name}-OP`] = ++i; - tagConstant[i] = `${name}-OP`; + obj[name] = ++i; + obj[i] = name; + obj[`${name}-BOT`] = ++i; + obj[i] = `${name}-BOT`; + obj[`${name}-OP`] = ++i; + obj[i] = `${name}-OP`; }); - return tagConstant; + return obj; }, isOPTag: (tag: number) => tag === Tag.Types.ORIGINAL_POSTER || tags.some(t => tag === Tag.Types[`${t.name}-OP`]), @@ -377,7 +381,6 @@ export default definePlugin({ break; } } - return type; } }); diff --git a/src/webpack/common/index.ts b/src/webpack/common/index.ts index 2ad9c54ec..5da3cc68b 100644 --- a/src/webpack/common/index.ts +++ b/src/webpack/common/index.ts @@ -20,6 +20,7 @@ export * from "./classes"; export * from "./components"; export * from "./menu"; export * from "./react"; +export * from "./settingsStores"; export * from "./stores"; export * as ComponentTypes from "./types/components.d"; export * as MenuTypes from "./types/menu.d"; diff --git a/src/webpack/common/settingsStores.ts b/src/webpack/common/settingsStores.ts new file mode 100644 index 000000000..ab281e569 --- /dev/null +++ b/src/webpack/common/settingsStores.ts @@ -0,0 +1,9 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2023 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import { findByPropsLazy } from "@webpack"; + +export const TextAndImagesSettingsStores = findByPropsLazy("MessageDisplayCompact");