feat(MessagePeek): add settings & small fix (#83)

* added settings to disable or enable guild / dm peeking, fixed it so you dont have to use any for globalName

* Update index.tsx
This commit is contained in:
Creation's 2024-10-27 14:03:16 -04:00 committed by GitHub
parent c87a69193e
commit a019187f19
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 41 additions and 3 deletions

View file

@ -15,6 +15,12 @@ import { MessagePeekProps } from "../types";
const ChannelWrapperStyles = findByPropsLazy("muted", "subText"); const ChannelWrapperStyles = findByPropsLazy("muted", "subText");
const ChannelStyles = findByPropsLazy("closeButton", "subtext"); const ChannelStyles = findByPropsLazy("closeButton", "subtext");
declare module "discord-types/general" {
interface User {
globalName?: string;
}
}
export default function MessagePeek(props: MessagePeekProps) { export default function MessagePeek(props: MessagePeekProps) {
const { channel, channel_url } = props; const { channel, channel_url } = props;
if (!channel && !channel_url) return null; if (!channel && !channel_url) return null;
@ -38,7 +44,7 @@ export default function MessagePeek(props: MessagePeekProps) {
> >
<TooltipContainer text={content.length > 256 ? Parser.parse(content.slice(0, 256).trim()) : Parser.parse(content)}> <TooltipContainer text={content.length > 256 ? Parser.parse(content.slice(0, 256).trim()) : Parser.parse(content)}>
<div className={ChannelStyles.subtext}> <div className={ChannelStyles.subtext}>
{`${(lastMessage.author as any).globalName || lastMessage.author.username}: `} {`${lastMessage.author.globalName || lastMessage.author.username}: `}
{Parser.parseInlineReply(content)} {Parser.parseInlineReply(content)}
</div> </div>
</TooltipContainer> </TooltipContainer>

View file

@ -9,12 +9,16 @@ import { EquicordDevs } from "@utils/constants";
import definePlugin from "@utils/types"; import definePlugin from "@utils/types";
import MessagePeek from "./components/MessagePeek"; import MessagePeek from "./components/MessagePeek";
import { settings } from "./settings";
import { MessagePeekProps } from "./types"; import { MessagePeekProps } from "./types";
export default definePlugin({ export default definePlugin({
name: "MessagePeek", name: "MessagePeek",
description: "See the last message in a Channel like on mobile", description: "See the last message in a Channel like on mobile",
authors: [EquicordDevs.HypedDomi], authors: [EquicordDevs.HypedDomi],
settings: settings,
patches: [ patches: [
{ {
// DMs // DMs
@ -28,7 +32,8 @@ export default definePlugin({
$self.renderMessagePeek({ channel_url: $1.children.props.children[0].props.to }) $self.renderMessagePeek({ channel_url: $1.children.props.children[0].props.to })
]; ];
`.replace(/\s+/g, "") `.replace(/\s+/g, "")
} },
predicate: () => settings.store.dms === true
}, },
{ {
// Guild channels // Guild channels
@ -40,7 +45,8 @@ export default definePlugin({
$1[0].props.children[1].props.children, $1[0].props.children[1].props.children,
$self.renderMessagePeek({ channel: $1[0].props.children[0].props.channel }) $self.renderMessagePeek({ channel: $1[0].props.children[0].props.channel })
];`.replace(/\s+/g, "") ];`.replace(/\s+/g, "")
} },
predicate: () => settings.store.guildChannels === true
} }
], ],
renderMessagePeek: (props: MessagePeekProps) => { renderMessagePeek: (props: MessagePeekProps) => {

View file

@ -0,0 +1,26 @@
/*
* Vencord, a Discord client mod
* Copyright (c) 2024 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import { definePluginSettings } from "@api/Settings";
import { OptionType } from "@utils/types";
const settings = definePluginSettings({
guildChannels: {
description: "Show message peek in guild channels",
type: OptionType.BOOLEAN,
default: true,
restartNeeded: true
},
dms: {
description: "Show message peek in DMs",
type: OptionType.BOOLEAN,
default: true,
restartNeeded: true
}
});
export default settings;
export { settings };