fix(plugins): PronounDB, ViewIcons, WebhookTags, NoBlockedMessages, BetterGifAltText, MessageAccessories

This commit is contained in:
Vendicated 2022-11-11 16:14:05 +01:00
parent f3aba3edb0
commit 1176896a1b
No known key found for this signature in database
GPG Key ID: EC781ADFB93EFFA3
10 changed files with 86 additions and 44 deletions

@ -27,7 +27,7 @@ export default definePlugin({
{ {
find: "_messageAttachmentToEmbedMedia", find: "_messageAttachmentToEmbedMedia",
replacement: { replacement: {
match: /\(\)\.container\)},(.+?)\)};return/, match: /\(\)\.container,children:[[^\]]*]\)},(.+?)\)};return/,
replace: (_, accessories) => replace: (_, accessories) =>
`().container)},Vencord.Api.MessageAccessories._modifyAccessories([${accessories}],this.props))};return`, `().container)},Vencord.Api.MessageAccessories._modifyAccessories([${accessories}],this.props))};return`,
}, },

@ -29,7 +29,7 @@ export default definePlugin({
{ {
find: "onCloseImage=", find: "onCloseImage=",
replacement: { replacement: {
match: /(return .{1,2}\.createElement.{0,50}isWindowFocused)/, match: /(return.{0,10}\.jsx.{0,50}isWindowFocused)/,
replace: replace:
"Vencord.Plugins.plugins.BetterGifAltText.altify(e);$1", "Vencord.Plugins.plugins.BetterGifAltText.altify(e);$1",
}, },

@ -28,8 +28,8 @@ export default definePlugin({
find: 'safety_prompt:"DMSpamExperiment",response:"show_redacted_messages"', find: 'safety_prompt:"DMSpamExperiment",response:"show_redacted_messages"',
replacement: [ replacement: [
{ {
match: /collapsedReason;return (?=\w{1,2}.createElement)/, match: /\.collapsedReason;return/,
replace: "collapsedReason; return null;" replace: ".collapsedReason;return null;return;"
} }
] ]
} }

@ -26,8 +26,8 @@ export default definePlugin({
patches: [{ patches: [{
find: "().expandedFolderIconWrapper", find: "().expandedFolderIconWrapper",
replacement: [{ replacement: [{
match: /\(\w\|\|\w\)(&&\(\w=\w\.createElement\(\w+\.animated)/, match: /\(\w\|\|\w\)&&(\(.{0,40}\(.{1,3}\.animated)/,
replace: "true$1", replace: "$1",
}] }]
}] }]
}); });

@ -20,27 +20,28 @@ import { useAwaiter } from "../../../utils/misc";
import { Settings } from "../../../Vencord"; import { Settings } from "../../../Vencord";
import { UserStore } from "../../../webpack/common"; import { UserStore } from "../../../webpack/common";
import { fetchPronouns, formatPronouns } from "../pronoundbUtils"; import { fetchPronouns, formatPronouns } from "../pronoundbUtils";
import { PronounMapping, UserProfileProps } from "../types"; import { PronounMapping, UserProfilePronounsProps, UserProfileProps } from "../types";
export default function PronounsProfileWrapper(props: UserProfileProps, pronounsComponent: JSX.Element) { export default function PronounsProfileWrapper(PronounsComponent: React.ElementType<UserProfilePronounsProps>, props: UserProfilePronounsProps, profileProps: UserProfileProps) {
const user = UserStore.getUser(profileProps.userId) ?? {};
// Don't bother fetching bot or system users // Don't bother fetching bot or system users
if (props.user.bot || props.user.system) return null; if (user.bot || user.system) return null;
// Respect showSelf options // Respect showSelf options
if (!Settings.plugins.PronounDB.showSelf && props.user.id === UserStore.getCurrentUser().id) return null; if (!Settings.plugins.PronounDB.showSelf && user.id === UserStore.getCurrentUser().id)
return null;
const [result, , isPending] = useAwaiter( const [result, , isPending] = useAwaiter(
() => fetchPronouns(props.user.id), () => fetchPronouns(user.id),
null, null,
e => console.error("Fetching pronouns failed: ", e) e => console.error("Fetching pronouns failed: ", e)
); );
// If the promise completed, the result was not "unspecified", and there is a mapping for the code, then return a span with the pronouns // If the promise completed, the result was not "unspecified", and there is a mapping for the code, then render
if (!isPending && result && result !== "unspecified" && PronounMapping[result]) { if (!isPending && result && result !== "unspecified" && PronounMapping[result]) {
// First child is the header, second is a div with the actual text // First child is the header, second is a div with the actual text
const [, pronounsBodyComponent] = pronounsComponent.props.children as [JSX.Element, JSX.Element]; props.currentPronouns ||= formatPronouns(result);
pronounsBodyComponent.props.children = formatPronouns(result); return <PronounsComponent {...props} />;
return pronounsComponent;
} }
// Otherwise, return null so nothing else is rendered
else return null; return null;
} }

@ -44,13 +44,28 @@ export default definePlugin({
}, },
// Hijack the discord pronouns section (hidden without experiment) and add a wrapper around the text section // Hijack the discord pronouns section (hidden without experiment) and add a wrapper around the text section
{ {
find: ".headerTagUsernameNoNickname", find: "currentPronouns:",
all: true,
replacement: { replacement: {
match: /(?<=""!==(.{1,2})&&).+?children:\1.+?(?=,)/, match: /\(0,.{1,3}\.jsxs?\)\((.{1,10}),(\{[^[}]*currentPronouns:[^}]*(\w)\.pronouns[^}]*\})\)/,
replace: "Vencord.Plugins.plugins.PronounDB.PronounsProfileWrapper(e, $1)" replace: (original, PronounComponent, pronounProps, fullProps) => {
// UserSettings
if (fullProps.includes("onPronounsChange")) return original;
return `Vencord.Plugins.plugins.PronounDB.PronounsProfileWrapper(${PronounComponent}, ${pronounProps}, ${fullProps})`;
}
}
},
// Make pronouns experiment be enabled by default
{
find: "2022-01_pronouns",
replacement: {
match: "!1", // false
replace: "!0"
} }
} }
], ],
options: { options: {
pronounsFormat: { pronounsFormat: {
type: OptionType.SELECT, type: OptionType.SELECT,

@ -16,15 +16,13 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import { User } from "discord-types/general";
export interface UserProfileProps { export interface UserProfileProps {
customStatus: JSX.Element, userId: string;
displayProfile: { }
// In the future (if discord ever uses their pronouns system) this taking priority can be a plugin setting
pronouns: string; export interface UserProfilePronounsProps {
}; currentPronouns: string | null;
user: User; hidePersonalInformation: boolean;
} }
export interface PronounsResponse { export interface PronounsResponse {

@ -16,15 +16,20 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import type { Guild } from "discord-types/general";
import { Devs } from "../utils/constants"; import { Devs } from "../utils/constants";
import { LazyComponent } from "../utils/misc"; import { LazyComponent, lazyWebpack } from "../utils/misc";
import { ModalRoot, ModalSize, openModal } from "../utils/modal"; import { ModalRoot, ModalSize, openModal } from "../utils/modal";
import definePlugin from "../utils/types"; import definePlugin from "../utils/types";
import { find } from "../webpack"; import { filters, find } from "../webpack";
import { Menu } from "../webpack/common";
const ImageModal = LazyComponent(() => find(m => m.prototype?.render?.toString().includes("OPEN_ORIGINAL_IMAGE"))); const ImageModal = LazyComponent(() => find(m => m.prototype?.render?.toString().includes("OPEN_ORIGINAL_IMAGE")));
const MaskedLink = LazyComponent(() => find(m => m.type?.toString().includes("MASKED_LINK)"))); const MaskedLink = LazyComponent(() => find(m => m.type?.toString().includes("MASKED_LINK)")));
const GuildBannerStore = lazyWebpack(filters.byProps("getGuildBannerURL"));
const OPEN_URL = "Vencord.Plugins.plugins.ViewIcons.openImage("; const OPEN_URL = "Vencord.Plugins.plugins.ViewIcons.openImage(";
export default definePlugin({ export default definePlugin({
name: "ViewIcons", name: "ViewIcons",
@ -32,6 +37,10 @@ export default definePlugin({
description: "Makes Avatars/Banners in user profiles clickable, and adds Guild Context Menu Entries to View Banner/Icon.", description: "Makes Avatars/Banners in user profiles clickable, and adds Guild Context Menu Entries to View Banner/Icon.",
openImage(url: string) { openImage(url: string) {
const u = new URL(url);
u.searchParams.set("size", "512");
url = u.toString();
openModal(modalProps => ( openModal(modalProps => (
<ModalRoot size={ModalSize.DYNAMIC} {...modalProps}> <ModalRoot size={ModalSize.DYNAMIC} {...modalProps}>
<ImageModal <ImageModal
@ -50,32 +59,51 @@ export default definePlugin({
replacement: { replacement: {
// global because Discord has two components that are 99% identical with one small change ._. // global because Discord has two components that are 99% identical with one small change ._.
match: /\{src:(.{1,2}),avatarDecoration/g, match: /\{src:(.{1,2}),avatarDecoration/g,
replace: (_, src) => `{src:${src},onClick:()=>${OPEN_URL}${src}.replace(/\\?.+$/, "")+"?size=512"),avatarDecoration` replace: (_, src) => `{src:${src},onClick:()=>${OPEN_URL}${src}),avatarDecoration`
} }
}, { }, {
find: "().popoutNoBannerPremium", find: "().popoutNoBannerPremium",
replacement: { replacement: {
match: /style:.{0,10}\{\},(.{1,2})\)/, match: /style:.{0,10}\{\},(.{1,2})\)/,
replace: (m, style) => `onClick:${style}.backgroundImage&&(${style}.cursor="pointer",()=>${OPEN_URL}${style}.backgroundImage.replace("url(", "").replace(/(\\?size=.+)?\\)/, "?size=512"))),${m}` replace: (m, style) =>
`onClick:${style}.backgroundImage&&(${style}.cursor="pointer",` +
`()=>${OPEN_URL}${style}.backgroundImage.replace("url(", ""))),${m}`
} }
}, { }, {
find: '"GuildContextMenu:', find: '"GuildContextMenu:',
replacement: [ replacement: [
{ {
match: /\w=(\w)\.id/, match: /\w=(\w)\.id/,
replace: (m, guild) => `_guild=${guild},${m}` replace: "_guild=$1,$&"
}, },
{ {
match: /(?<=createElement\((.{1,5}),\{id:"leave-guild".{0,100},)(.{1,2}\.createElement)\((.{1,5}),null,(.{1,2})\)(?=\)\}function)/, match: /(id:"leave-guild".{0,200}),(\(0,.{1,3}\.jsxs?\).{0,200}function)/,
replace: (_, menu, createElement, menuGroup, copyIdElement) => replace: "$1,Vencord.Plugins.plugins.ViewIcons.buildGuildContextMenuEntries(_guild),$2"
`${createElement}(${menuGroup},null,[` +
`_guild.icon&&${createElement}(${menu},` +
`{id:"viewicons-copy-icon",label:"View Icon",action:()=>${OPEN_URL}_guild.getIconURL(void 0,true)+"size=512")}),` +
`_guild.banner&&${createElement}(${menu},` +
`{id:"viewicons-copy-banner",label:"View Banner",action:()=>${OPEN_URL}Vencord.Webpack.findByProps("getGuildBannerURL").getGuildBannerURL(_guild).replace(/\\?size=.+/, "?size=512"))})`
+ `,${copyIdElement}])`
} }
] ]
} }
] ],
buildGuildContextMenuEntries(guild: Guild) {
return (
<Menu.MenuGroup>
{guild.banner && (
<Menu.MenuItem
id="view-banner"
key="view-banner"
label="View Banner"
action={() => this.openImage(GuildBannerStore.getGuildBannerURL(guild))}
/>
)}
{guild.icon && (
<Menu.MenuItem
id="view-icon"
key="view-icon"
label="View Icon"
action={() => this.openImage(guild.getIconURL(0, true))}
/>
)}
</Menu.MenuGroup>
);
}
}); });

@ -42,7 +42,7 @@ export default definePlugin({
{ {
find: ".Types.ORIGINAL_POSTER", find: ".Types.ORIGINAL_POSTER",
replacement: { replacement: {
match: /return null==(.)\?null:.\.createElement\((.)\.Z/, match: /return null==(.)\?null:\(0,.{1,3}\.jsxs?\)\((.{1,3})\.Z/,
replace: (orig, type, BotTag) => replace: (orig, type, BotTag) =>
`if(arguments[0].message.webhookId&&arguments[0].user.isNonUserBot()){${type}=${BotTag}.Z.Types.WEBHOOK}${orig}`, `if(arguments[0].message.webhookId&&arguments[0].user.isNonUserBot()){${type}=${BotTag}.Z.Types.WEBHOOK}${orig}`,
}, },

@ -37,7 +37,7 @@ const browser = await pup.launch({
}); });
const page = await browser.newPage(); const page = await browser.newPage();
await page.setUserAgent("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36"); await page.setUserAgent("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36");
function maybeGetError(handle: JSHandle) { function maybeGetError(handle: JSHandle) {
return (handle as JSHandle<Error>)?.getProperty("message") return (handle as JSHandle<Error>)?.getProperty("message")