/* * Vencord, a Discord client mod * Copyright (c) 2024 Vendicated and contributors * SPDX-License-Identifier: GPL-3.0-or-later */ import "./styles.css"; import { isPluginEnabled } from "@api/PluginManager"; import { definePluginSettings } from "@api/Settings"; import ErrorBoundary from "@components/ErrorBoundary"; import showMeYourName from "@plugins/showMeYourName"; import { Devs } from "@utils/constants"; import definePlugin, { OptionType } from "@utils/types"; import { User } from "@vencord/discord-types"; import { GuildRoleStore, SelectedGuildStore, useState } from "@webpack/common"; import { JSX } from "react"; const settings = definePluginSettings({ showAtSymbol: { type: OptionType.BOOLEAN, description: "Whether the the @ symbol should be displayed on user mentions", default: true } }); function DefaultRoleIcon() { return ( ); } export default definePlugin({ name: "MentionAvatars", description: "Shows user avatars and role icons inside mentions", tags: ["Appearance", "Customisation"], authors: [Devs.Ven, Devs.SerStars], patches: [{ // HEY THOR UPDATE SHOW ME YOUR NAME IF THIS SHIT CHANGES TY :) find: ".USER_MENTION)", replacement: { match: /children:`@\$\{(\i\?\?\i)\}`(?<=\.useName\((\i)\).+?)/, replace: "children:$self.renderUsername({username:$1,user:$2,showMeYourNameMention:typeof showMeYourNameMention!=='undefined'?showMeYourNameMention:undefined})" } }, { find: ".ROLE_MENTION)", replacement: { match: /children:\[\i&&.{0,100}className:\i.\i,background:!1,.{0,50}?,\i(?=\])/, replace: "$&,$self.renderRoleIcon(arguments[0])" } }, { // show avatar in the chat input box find: ".hasUniqueUsername()?null:`#", replacement: { match: /(?<=,(\i)\).{0,55})`@\$\{(\i)\}`/, replace: "$self.renderInputMention($2,$1)" } }], settings, renderUsername: ErrorBoundary.wrap(({ user, username, showMeYourNameMention }: { user: User, username: string, showMeYourNameMention: JSX.Element | null | undefined; }) => { const [isHovering, setIsHovering] = useState(false); const nameContent = isPluginEnabled(showMeYourName.name) && showMeYourNameMention ? showMeYourNameMention : <>{getUsernameString(username)}; return ( setIsHovering(true)} onMouseLeave={() => setIsHovering(false)} className="vc-mentionAvatars-container" > {user && ( )} {nameContent} ); }, { noop: true }), renderInputMention(username: string, user: User) { if (!user) return getUsernameString(username); return ( <> {getUsernameString(username)} ); }, renderRoleIcon: ErrorBoundary.wrap(({ roleId, guildId }: { roleId: string, guildId: string; }) => { // Discord uses Role Mentions for uncached users because .... idk if (!roleId) return null; const role = GuildRoleStore.getRole(guildId, roleId); if (!role?.icon) return ; return ( ); }, { noop: true }), }); function getUsernameString(username: string) { return settings.store.showAtSymbol ? `@${username}` : username; }