fix messageLinkEmbeds, moreUserTags (#1859)
This commit is contained in:
parent
131e91a37c
commit
c5dd50ad8f
@ -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<string, {
|
||||
}>();
|
||||
|
||||
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<any> = () => null;
|
||||
|
||||
const messageLinkRegex = /(?<!<)https?:\/\/(?:\w+\.)?discord(?:app)?\.com\/channels\/(\d{17,20}|@me)\/(\d{17,20})\/(\d{17,20})/g;
|
||||
const tenorRegex = /^https:\/\/(?:www\.)?tenor\.com\//;
|
||||
|
||||
@ -319,10 +318,9 @@ function ChannelMessageEmbedAccessory({ message, channel, guildID }: MessageEmbe
|
||||
/>;
|
||||
}
|
||||
|
||||
const compactModeEnabled = getSettingStoreLazy<boolean>("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 {
|
||||
<span>{isDM ? " - Direct Message" : " - " + GuildStore.getGuild(channel.guild_id)?.name}</span>
|
||||
</Text>
|
||||
}
|
||||
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,
|
||||
|
||||
|
@ -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<PermissionName, bigint>;
|
||||
const Tag = findLazy(m => m.Types?.[0] === "BOT") as RC<{ type?: number, className?: string, useRemSizes?: boolean; }> & { Types: Record<string, number>; };
|
||||
|
||||
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: /(?<type>\i)=\(null==.{0,50}\.BOT,null!=(?<user>\i)&&\i\.bot/,
|
||||
replace: "$<type> = $self.getTag({user: $<user>, channel: arguments[0].channel, origType: $<user>.bot ? 0 : null, location: 'not-chat' }), typeof $<type> === 'number'"
|
||||
match: /(?<type>\i)=\(null==.{0,100}\.BOT;return null!=(?<user>\i)&&\i\.bot/,
|
||||
replace: "$<type> = $self.getTag({user: $<user>, channel: arguments[0].channel, origType: $<user>.bot ? 0 : null, location: 'not-chat' }); return typeof $<type> === '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;
|
||||
}
|
||||
});
|
||||
|
@ -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";
|
||||
|
9
src/webpack/common/settingsStores.ts
Normal file
9
src/webpack/common/settingsStores.ts
Normal file
@ -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");
|
Loading…
x
Reference in New Issue
Block a user