Skip to content

Commit

Permalink
new plugin FullUserInChatbox (#2766)
Browse files Browse the repository at this point in the history
  • Loading branch information
sadan4 authored Dec 30, 2024
1 parent 0fd76ab commit 20ed7dc
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/components/ErrorBoundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ interface Props<T = any> {
/** Render nothing if an error occurs */
noop?: boolean;
/** Fallback component to render if an error occurs */
fallback?: React.ComponentType<React.PropsWithChildren<{ error: any; message: string; stack: string; }>>;
fallback?: React.ComponentType<React.PropsWithChildren<{ error: any; message: string; stack: string; wrappedProps: T; }>>;
/** called when an error occurs. The props property is only available if using .wrap */
onError?(data: { error: Error, errorInfo: React.ErrorInfo, props: T; }): void;
/** Custom error message */
Expand Down Expand Up @@ -81,6 +81,7 @@ const ErrorBoundary = LazyComponent(() => {

if (this.props.fallback)
return <this.props.fallback
wrappedProps={this.props.wrappedProps}
children={this.props.children}
{...this.state}
/>;
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/accountPanelServerProfile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export default definePlugin({
replace: "$&onRequestClose:$self.onPopoutClose,"
},
{
match: /(?<=.avatarWrapper,)/,
match: /(?<=\.avatarWrapper,)/,
replace: "ref:$self.accountPanelRef,onContextMenu:$self.openAccountPanelContextMenu,"
}
]
Expand Down
9 changes: 9 additions & 0 deletions src/plugins/fullUserInChatbox/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Full User In Chatbox

Adds the full user mention to the textbox

Adds the avatar if you have mentioned avatars enabled

Provides the full context menu to make it easy to access the users profile, and other common actions

https://github.com/user-attachments/assets/cd9edb33-99c8-4c8d-b669-8cddd05f4b45
47 changes: 47 additions & 0 deletions src/plugins/fullUserInChatbox/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Vencord, a Discord client mod
* Copyright (c) 2024 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/

import ErrorBoundary from "@components/ErrorBoundary";
import { Devs } from "@utils/constants";
import definePlugin from "@utils/types";
import { findComponentByCodeLazy } from "@webpack";
import { ReactNode } from "react";

const UserMentionComponent = findComponentByCodeLazy(".USER_MENTION)");

interface UserMentionComponentProps {
id: string;
channelId: string;
guildId: string;
OriginalComponent: ReactNode;
}

export default definePlugin({
name: "FullUserInChatbox",
description: "Makes the user mention in the chatbox have more functionalities, like left/right clicking",
authors: [Devs.sadan],

patches: [
{
find: ':"text":',
replacement: {
match: /(hidePersonalInformation\).+?)(if\(null!=\i\){.+?return \i)(?=})/,
replace: "$1return $self.UserMentionComponent({...arguments[0],OriginalComponent:(()=>{$2})()});"
}
}
],

UserMentionComponent: ErrorBoundary.wrap((props: UserMentionComponentProps) => (
<UserMentionComponent
// This seems to be constant
className="mention"
userId={props.id}
channelId={props.channelId}
/>
), {
fallback: ({ wrappedProps }) => wrappedProps.OriginalComponent
})
});

0 comments on commit 20ed7dc

Please sign in to comment.