fix messageLinkEmbeds, moreUserTags (#1859)
This commit is contained in:
parent
131e91a37c
commit
c5dd50ad8f
@ -18,7 +18,6 @@
|
|||||||
|
|
||||||
import { addAccessory } from "@api/MessageAccessories";
|
import { addAccessory } from "@api/MessageAccessories";
|
||||||
import { definePluginSettings } from "@api/Settings";
|
import { definePluginSettings } from "@api/Settings";
|
||||||
import { getSettingStoreLazy } from "@api/SettingsStore";
|
|
||||||
import ErrorBoundary from "@components/ErrorBoundary";
|
import ErrorBoundary from "@components/ErrorBoundary";
|
||||||
import { Devs } from "@utils/constants.js";
|
import { Devs } from "@utils/constants.js";
|
||||||
import { classes } from "@utils/misc";
|
import { classes } from "@utils/misc";
|
||||||
@ -36,6 +35,7 @@ import {
|
|||||||
PermissionStore,
|
PermissionStore,
|
||||||
RestAPI,
|
RestAPI,
|
||||||
Text,
|
Text,
|
||||||
|
TextAndImagesSettingsStores,
|
||||||
UserStore
|
UserStore
|
||||||
} from "@webpack/common";
|
} from "@webpack/common";
|
||||||
import { Channel, Guild, Message } from "discord-types/general";
|
import { Channel, Guild, Message } from "discord-types/general";
|
||||||
@ -46,12 +46,11 @@ const messageCache = new Map<string, {
|
|||||||
}>();
|
}>();
|
||||||
|
|
||||||
const Embed = LazyComponent(() => findByCode(".inlineMediaEmbed"));
|
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");
|
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 messageLinkRegex = /(?<!<)https?:\/\/(?:\w+\.)?discord(?:app)?\.com\/channels\/(\d{17,20}|@me)\/(\d{17,20})\/(\d{17,20})/g;
|
||||||
const tenorRegex = /^https:\/\/(?:www\.)?tenor\.com\//;
|
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 {
|
function AutomodEmbedAccessory(props: MessageEmbedProps): JSX.Element | null {
|
||||||
const { message, channel, guildID } = props;
|
const { message, channel, guildID } = props;
|
||||||
|
const compact = TextAndImagesSettingsStores.MessageDisplayCompact.useSetting();
|
||||||
const isDM = guildID === "@me";
|
const isDM = guildID === "@me";
|
||||||
const images = getImages(message);
|
const images = getImages(message);
|
||||||
const { parse } = Parser;
|
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>
|
<span>{isDM ? " - Direct Message" : " - " + GuildStore.getGuild(channel.guild_id)?.name}</span>
|
||||||
</Text>
|
</Text>
|
||||||
}
|
}
|
||||||
compact={compactModeEnabled.getSetting()}
|
compact={compact}
|
||||||
content={
|
content={
|
||||||
<>
|
<>
|
||||||
{message.content || message.attachments.length <= images.length
|
{message.content || message.attachments.length <= images.length
|
||||||
@ -365,20 +363,7 @@ export default definePlugin({
|
|||||||
name: "MessageLinkEmbeds",
|
name: "MessageLinkEmbeds",
|
||||||
description: "Adds a preview to messages that link another message",
|
description: "Adds a preview to messages that link another message",
|
||||||
authors: [Devs.TheSun, Devs.Ven, Devs.RyanCaoDev],
|
authors: [Devs.TheSun, Devs.Ven, Devs.RyanCaoDev],
|
||||||
dependencies: ["MessageAccessoriesAPI", "SettingsStoreAPI"],
|
dependencies: ["MessageAccessoriesAPI"],
|
||||||
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;
|
|
||||||
},
|
|
||||||
|
|
||||||
settings,
|
settings,
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ import { Devs } from "@utils/constants";
|
|||||||
import { Margins } from "@utils/margins";
|
import { Margins } from "@utils/margins";
|
||||||
import definePlugin, { OptionType } from "@utils/types";
|
import definePlugin, { OptionType } from "@utils/types";
|
||||||
import { findByPropsLazy, findLazy } from "@webpack";
|
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 { RC } from "@webpack/types";
|
||||||
import { Channel, Message, User } from "discord-types/general";
|
import { Channel, Message, User } from "discord-types/general";
|
||||||
|
|
||||||
@ -58,7 +58,6 @@ const PermissionUtil = findByPropsLazy("computePermissions", "canEveryoneRole")
|
|||||||
computePermissions({ ...args }): bigint;
|
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 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();
|
const isWebhook = (message: Message, user: User) => !!message?.webhookId && user.isNonUserBot();
|
||||||
@ -188,17 +187,14 @@ export default definePlugin({
|
|||||||
patches: [
|
patches: [
|
||||||
// add tags to the tag list
|
// add tags to the tag list
|
||||||
{
|
{
|
||||||
find: '.BOT=0]="BOT"',
|
find: "BotTagTypes:",
|
||||||
replacement: [
|
replacement: {
|
||||||
// add tags to the exported tags list (Tag.Types)
|
match: /\((\i)=\{\}\)\)\[(\i)\.BOT/,
|
||||||
{
|
replace: "($1=$self.getTagTypes()))[$2.BOT"
|
||||||
match: /(\i)\[.\.BOT=0\]="BOT";/,
|
|
||||||
replace: "$&$1=$self.addTagVariants($1);"
|
|
||||||
}
|
}
|
||||||
]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
find: ".DISCORD_SYSTEM_MESSAGE_BOT_TAG_TOOLTIP;",
|
find: ".DISCORD_SYSTEM_MESSAGE_BOT_TAG_TOOLTIP,",
|
||||||
replacement: [
|
replacement: [
|
||||||
// make the tag show the right text
|
// make the tag show the right text
|
||||||
{
|
{
|
||||||
@ -213,25 +209,25 @@ export default definePlugin({
|
|||||||
},
|
},
|
||||||
// add HTML data attributes (for easier theming)
|
// add HTML data attributes (for easier theming)
|
||||||
{
|
{
|
||||||
match: /children:\[(?=\i\?null:\i,\i,\(0,\i\.jsx\)\("span",{className:\i\(\)\.botText,children:(\i)}\)\])/,
|
match: /.botText,children:(\i)}\)]/,
|
||||||
replace: "'data-tag':$1.toLowerCase(),children:["
|
replace: "$&,'data-tag':$1.toLowerCase()"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
// in messages
|
// in messages
|
||||||
{
|
{
|
||||||
find: ".Types.ORIGINAL_POSTER",
|
find: "renderSystemTag:",
|
||||||
replacement: {
|
replacement: {
|
||||||
match: /return null==(\i)\?null:\(0,/,
|
match: /;return\((\(null==\i\?void 0:\i\.isSystemDM\(\).+?.Types.ORIGINAL_POSTER\)),null==(\i)\)/,
|
||||||
replace: "$1=$self.getTag({...arguments[0],origType:$1,location:'chat'});$&"
|
replace: ";$1;$2=$self.getTag({...arguments[0],origType:$2,location:'chat'});return $2 == null"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// in the member list
|
// in the member list
|
||||||
{
|
{
|
||||||
find: ".Messages.GUILD_OWNER,",
|
find: ".Messages.GUILD_OWNER,",
|
||||||
replacement: {
|
replacement: {
|
||||||
match: /(?<type>\i)=\(null==.{0,50}\.BOT,null!=(?<user>\i)&&\i\.bot/,
|
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' }), typeof $<type> === 'number'"
|
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
|
// pass channel id down props to be used in profiles
|
||||||
@ -251,11 +247,18 @@ export default definePlugin({
|
|||||||
},
|
},
|
||||||
// in profiles
|
// in profiles
|
||||||
{
|
{
|
||||||
find: "showStreamerModeTooltip:",
|
find: ",overrideDiscriminator:",
|
||||||
replacement: {
|
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,
|
match: /,botType:(\i\((\i)\)),/g,
|
||||||
replace: ",botType:$self.getTag({user:$2,channelId:arguments[0].moreTags_channelId,origType:$1,location:'not-chat'}),"
|
replace: ",botType:$self.getTag({user:$2,channelId:moreTags_channelId,origType:$1,location:'not-chat'}),"
|
||||||
}
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
||||||
@ -295,24 +298,25 @@ export default definePlugin({
|
|||||||
if (!guild) return [];
|
if (!guild) return [];
|
||||||
|
|
||||||
const permissions = PermissionUtil.computePermissions({ user, context: guild, overwrites: channel.permissionOverwrites });
|
const permissions = PermissionUtil.computePermissions({ user, context: guild, overwrites: channel.permissionOverwrites });
|
||||||
return Object.entries(Permissions)
|
return Object.entries(PermissionsBits)
|
||||||
.map(([perm, permInt]) =>
|
.map(([perm, permInt]) =>
|
||||||
permissions & permInt ? perm : ""
|
permissions & permInt ? perm : ""
|
||||||
)
|
)
|
||||||
.filter(Boolean);
|
.filter(Boolean);
|
||||||
},
|
},
|
||||||
|
|
||||||
addTagVariants(tagConstant) {
|
getTagTypes() {
|
||||||
|
const obj = {};
|
||||||
let i = 100;
|
let i = 100;
|
||||||
tags.forEach(({ name }) => {
|
tags.forEach(({ name }) => {
|
||||||
tagConstant[name] = ++i;
|
obj[name] = ++i;
|
||||||
tagConstant[i] = name;
|
obj[i] = name;
|
||||||
tagConstant[`${name}-BOT`] = ++i;
|
obj[`${name}-BOT`] = ++i;
|
||||||
tagConstant[i] = `${name}-BOT`;
|
obj[i] = `${name}-BOT`;
|
||||||
tagConstant[`${name}-OP`] = ++i;
|
obj[`${name}-OP`] = ++i;
|
||||||
tagConstant[i] = `${name}-OP`;
|
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`]),
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -20,6 +20,7 @@ export * from "./classes";
|
|||||||
export * from "./components";
|
export * from "./components";
|
||||||
export * from "./menu";
|
export * from "./menu";
|
||||||
export * from "./react";
|
export * from "./react";
|
||||||
|
export * from "./settingsStores";
|
||||||
export * from "./stores";
|
export * from "./stores";
|
||||||
export * as ComponentTypes from "./types/components.d";
|
export * as ComponentTypes from "./types/components.d";
|
||||||
export * as MenuTypes from "./types/menu.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…
Reference in New Issue
Block a user