From 86f16f68d76a0b4ea146dd5fde2d5ea5834dd6cb Mon Sep 17 00:00:00 2001 From: "Nick H." <5614680+hideki2k02@users.noreply.github.com> Date: Sun, 1 Sep 2024 12:03:30 -0300 Subject: [PATCH 1/2] Attempt to fix all inconsistencies; DM Support --- src/plugins/showMeYourName/index.tsx | 112 +++++++++++++++++++++------ 1 file changed, 89 insertions(+), 23 deletions(-) diff --git a/src/plugins/showMeYourName/index.tsx b/src/plugins/showMeYourName/index.tsx index 4f9fcf304..be675cb3e 100644 --- a/src/plugins/showMeYourName/index.tsx +++ b/src/plugins/showMeYourName/index.tsx @@ -4,20 +4,26 @@ * SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * Vencord, a Discord client mod + * Copyright (c) 2023 rini + * SPDX-License-Identifier: GPL-3.0-or-later + */ + import "./styles.css"; +import { ChannelStore } from "@webpack/common"; import { definePluginSettings } from "@api/Settings"; import ErrorBoundary from "@components/ErrorBoundary"; import { Devs } from "@utils/constants"; import definePlugin, { OptionType } from "@utils/types"; -import { Message, User } from "discord-types/general"; +import { Message } from "discord-types/general"; interface UsernameProps { author: { nick: string; }; message: Message; withMentionPrefix?: boolean; isRepliedMessage: boolean; - userOverride?: User; } const settings = definePluginSettings({ @@ -28,18 +34,27 @@ const settings = definePluginSettings({ { label: "Username then nickname", value: "user-nick", default: true }, { label: "Nickname then username", value: "nick-user" }, { label: "Username only", value: "user" }, + { label: "Vanilla (Nickname prioritized)", value: "nick" }, ], }, - displayNames: { - type: OptionType.BOOLEAN, - description: "Use display names in place of usernames", - default: false - }, + inReplies: { type: OptionType.BOOLEAN, default: false, description: "Also apply functionality to reply previews", }, + + inDirectMessages: { + type: OptionType.BOOLEAN, + default: false, + description: "Also apply functionality to direct messages", + }, + + inDirectGroups: { + type: OptionType.BOOLEAN, + default: false, + description: "Also apply functionality to direct messages on groups", + }, }); export default definePlugin({ @@ -57,28 +72,79 @@ export default definePlugin({ ], settings, - renderUsername: ErrorBoundary.wrap(({ author, message, isRepliedMessage, withMentionPrefix, userOverride }: UsernameProps) => { + renderUsername: ErrorBoundary.wrap(({ author, message, isRepliedMessage, withMentionPrefix }: UsernameProps) => { try { - const user = userOverride ?? message.author; - let { username } = user; - if (settings.store.displayNames) - username = (user as any).globalName || username; + // Discord by default will display the username unless the user has set an nickname + // The code will also do the same if certain settings are turned off - const { nick } = author; - const prefix = withMentionPrefix ? "@" : ""; + // There is no way to get the nick from the message for some reason so this had to stay + const nickname: string = author.nick; - if (isRepliedMessage && !settings.store.inReplies || username.toLowerCase() === nick.toLowerCase()) - return <>{prefix}{nick}; + const userObj = message.author; + const prefix: string = withMentionPrefix ? "@" : ""; + const username: string = userObj.username; + const isRedundantDoubleUsername = (username.toLowerCase() === nickname.toLowerCase()); + let display_name = nickname; - if (settings.store.mode === "user-nick") - return <>{prefix}{username} {nick}; + switch (settings.store.mode) { + case "user-nick": + if (!isRedundantDoubleUsername) { + display_name = <>{prefix}{username} {nickname}; + } - if (settings.store.mode === "nick-user") - return <>{prefix}{nick} {username}; + break; + // the makes the text gray - return <>{prefix}{username}; - } catch { - return <>{author?.nick}; + case "nick-user": + if (!isRedundantDoubleUsername) { + display_name = <>{prefix}{nickname} {username}; + } + + break; + + case "user": + display_name = <>{prefix}{username}; + break; + + case "vanilla": + display_name = <>{prefix}{nickname}; + break; + } + + const current_channel = ChannelStore.getChannel(message.channel_id); + const isDM = (current_channel.guild_id === null); + + if (isDM) { + const isGroupChat = (current_channel.recipients.length > 1); + const shouldDisplayDM = !isGroupChat && settings.store.inDirectMessages; + const shouldDisplayGroup = isGroupChat && settings.store.inDirectGroups; + + if (shouldDisplayDM || shouldDisplayGroup) { + if (isRepliedMessage) { + if (settings.store.inReplies) return display_name; + + return nickname; + } + + return display_name; + } + + return nickname; + } + + // Servers + if (isRepliedMessage) { + if (settings.store.inReplies) return display_name; + + return nickname; + } + + // Unless any of the functions above changed it, it will be the nickname + return display_name; + + } catch (errorMsg) { + console.log(`ShowMeYourName ERROR: ${errorMsg}`); + return <>{message?.author.username}; } }, { noop: true }), }); From 20f2bb9045d9b2f836b339ac878b3fe013143223 Mon Sep 17 00:00:00 2001 From: "Nick H." <5614680+hideki2k02@users.noreply.github.com> Date: Sun, 1 Sep 2024 15:39:06 -0300 Subject: [PATCH 2/2] Fixed Header --- src/plugins/showMeYourName/index.tsx | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/plugins/showMeYourName/index.tsx b/src/plugins/showMeYourName/index.tsx index be675cb3e..4ddbcc769 100644 --- a/src/plugins/showMeYourName/index.tsx +++ b/src/plugins/showMeYourName/index.tsx @@ -4,12 +4,6 @@ * SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * Vencord, a Discord client mod - * Copyright (c) 2023 rini - * SPDX-License-Identifier: GPL-3.0-or-later - */ - import "./styles.css"; import { ChannelStore } from "@webpack/common";