From 4ff3614dc0a96ebfd825dc5fd3ef9e77de7d1da1 Mon Sep 17 00:00:00 2001 From: ayuxia Date: Tue, 2 Sep 2025 22:19:12 -0300 Subject: [PATCH] ShowMeYourName: support friend nicknames (#3639) Co-authored-by: V --- packages/discord-types/enums/channel.ts | 15 +++++++ packages/discord-types/enums/index.ts | 1 + src/plugins/noReplyMention/index.tsx | 2 +- src/plugins/onePingPerDM/index.ts | 6 +-- src/plugins/relationshipNotifier/functions.ts | 3 +- src/plugins/relationshipNotifier/types.ts | 4 -- src/plugins/relationshipNotifier/utils.ts | 3 +- src/plugins/showMeYourName/index.tsx | 45 +++++++++++++++---- src/utils/constants.ts | 6 +-- 9 files changed, 61 insertions(+), 24 deletions(-) create mode 100644 packages/discord-types/enums/channel.ts diff --git a/packages/discord-types/enums/channel.ts b/packages/discord-types/enums/channel.ts new file mode 100644 index 00000000..7aae546b --- /dev/null +++ b/packages/discord-types/enums/channel.ts @@ -0,0 +1,15 @@ +export const enum ChannelType { + GUILD_TEXT = 0, + DM = 1, + GUILD_VOICE = 2, + GROUP_DM = 3, + GUILD_CATEGORY = 4, + GUILD_ANNOUNCEMENT = 5, + ANNOUNCEMENT_THREAD = 10, + PUBLIC_THREAD = 11, + PRIVATE_THREAD = 12, + GUILD_STAGE_VOICE = 13, + GUILD_DIRECTORY = 14, + GUILD_FORUM = 15, + GUILD_MEDIA = 16 +} \ No newline at end of file diff --git a/packages/discord-types/enums/index.ts b/packages/discord-types/enums/index.ts index e2227d09..0ab49887 100644 --- a/packages/discord-types/enums/index.ts +++ b/packages/discord-types/enums/index.ts @@ -1,2 +1,3 @@ export * from "./commands"; export * from "./messages"; +export * from "./channel"; \ No newline at end of file diff --git a/src/plugins/noReplyMention/index.tsx b/src/plugins/noReplyMention/index.tsx index b4de573f..4af78ee2 100644 --- a/src/plugins/noReplyMention/index.tsx +++ b/src/plugins/noReplyMention/index.tsx @@ -53,7 +53,7 @@ const settings = definePluginSettings({ export default definePlugin({ name: "NoReplyMention", description: "Disables reply pings by default", - authors: [Devs.DustyAngel47, Devs.axyie, Devs.pylix, Devs.outfoxxed], + authors: [Devs.DustyAngel47, Devs.rae, Devs.pylix, Devs.outfoxxed], settings, shouldMention(message: Message, isHoldingShift: boolean) { diff --git a/src/plugins/onePingPerDM/index.ts b/src/plugins/onePingPerDM/index.ts index 0ef81781..b6192fb6 100644 --- a/src/plugins/onePingPerDM/index.ts +++ b/src/plugins/onePingPerDM/index.ts @@ -8,13 +8,9 @@ import { definePluginSettings } from "@api/Settings"; import { Devs } from "@utils/constants"; import definePlugin, { OptionType } from "@utils/types"; import { MessageJSON } from "@vencord/discord-types"; +import { ChannelType } from "@vencord/discord-types/enums"; import { ChannelStore, ReadStateStore, UserStore } from "@webpack/common"; -const enum ChannelType { - DM = 1, - GROUP_DM = 3 -} - const settings = definePluginSettings({ channelToAffect: { type: OptionType.SELECT, diff --git a/src/plugins/relationshipNotifier/functions.ts b/src/plugins/relationshipNotifier/functions.ts index 5bff474b..19f36086 100644 --- a/src/plugins/relationshipNotifier/functions.ts +++ b/src/plugins/relationshipNotifier/functions.ts @@ -17,10 +17,11 @@ */ import { getUniqueUsername, openUserProfile } from "@utils/discord"; +import { ChannelType } from "@vencord/discord-types/enums"; import { UserUtils } from "@webpack/common"; import settings from "./settings"; -import { ChannelDelete, ChannelType, GuildDelete, RelationshipRemove, RelationshipType } from "./types"; +import { ChannelDelete, GuildDelete, RelationshipRemove, RelationshipType } from "./types"; import { deleteGroup, deleteGuild, getGroup, getGuild, GuildAvailabilityStore, notify } from "./utils"; let manuallyRemovedFriend: string | undefined; diff --git a/src/plugins/relationshipNotifier/types.ts b/src/plugins/relationshipNotifier/types.ts index f2e482d6..5d3d12d4 100644 --- a/src/plugins/relationshipNotifier/types.ts +++ b/src/plugins/relationshipNotifier/types.ts @@ -52,10 +52,6 @@ export interface SimpleGuild { iconURL?: string; } -export const enum ChannelType { - GROUP_DM = 3, -} - export const enum RelationshipType { FRIEND = 1, BLOCKED = 2, diff --git a/src/plugins/relationshipNotifier/utils.ts b/src/plugins/relationshipNotifier/utils.ts index aaef783b..78371f13 100644 --- a/src/plugins/relationshipNotifier/utils.ts +++ b/src/plugins/relationshipNotifier/utils.ts @@ -20,11 +20,12 @@ import { DataStore, Notices } from "@api/index"; import { showNotification } from "@api/Notifications"; import { getUniqueUsername, openUserProfile } from "@utils/discord"; import { FluxStore } from "@vencord/discord-types"; +import { ChannelType } from "@vencord/discord-types/enums"; import { findStoreLazy } from "@webpack"; import { ChannelStore, GuildMemberStore, GuildStore, RelationshipStore, UserStore, UserUtils } from "@webpack/common"; import settings from "./settings"; -import { ChannelType, RelationshipType, SimpleGroupChannel, SimpleGuild } from "./types"; +import { RelationshipType, SimpleGroupChannel, SimpleGuild } from "./types"; export const GuildAvailabilityStore = findStoreLazy("GuildAvailabilityStore") as FluxStore & { totalGuilds: number; diff --git a/src/plugins/showMeYourName/index.tsx b/src/plugins/showMeYourName/index.tsx index 018fa305..623c70ca 100644 --- a/src/plugins/showMeYourName/index.tsx +++ b/src/plugins/showMeYourName/index.tsx @@ -10,10 +10,12 @@ 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 "@vencord/discord-types"; +import { Channel, Message, User } from "@vencord/discord-types"; +import { RelationshipStore } from "@webpack/common"; interface UsernameProps { - author: { nick: string; }; + author: { nick: string; authorId: string; }; + channel: Channel; message: Message; withMentionPrefix?: boolean; isRepliedMessage: boolean; @@ -30,6 +32,15 @@ const settings = definePluginSettings({ { label: "Username only", value: "user" }, ], }, + friendNicknames: { + type: OptionType.SELECT, + description: "How to prioritise friend nicknames over server nicknames", + options: [ + { label: "Show friend nicknames only in direct messages", value: "dms", default: true }, + { label: "Prefer friend nicknames over server nicknames", value: "always" }, + { label: "Prefer server nicknames over friend nicknames", value: "fallback" } + ] + }, displayNames: { type: OptionType.BOOLEAN, description: "Use display names in place of usernames", @@ -45,7 +56,7 @@ const settings = definePluginSettings({ export default definePlugin({ name: "ShowMeYourName", description: "Display usernames next to nicks, or no nicks at all", - authors: [Devs.Rini, Devs.TheKodeToad], + authors: [Devs.Rini, Devs.TheKodeToad, Devs.rae], patches: [ { find: '="SYSTEM_TAG"', @@ -58,23 +69,39 @@ export default definePlugin({ ], settings, - renderUsername: ErrorBoundary.wrap(({ author, message, isRepliedMessage, withMentionPrefix, userOverride }: UsernameProps) => { + renderUsername: ErrorBoundary.wrap(({ author, channel, message, isRepliedMessage, withMentionPrefix, userOverride }: UsernameProps) => { try { + const { mode, friendNicknames, displayNames, inReplies } = settings.store; + const user = userOverride ?? message.author; let { username } = user; - if (settings.store.displayNames) + + if (displayNames) username = user.globalName || username; - const { nick } = author; + let { nick } = author; + + const friendNickname = RelationshipStore.getNickname(author.authorId); + + if (friendNickname) { + const shouldUseFriendNickname = + friendNicknames === "always" || + (friendNicknames === "dms" && channel.isPrivate()) || + (friendNicknames === "fallback" && !nick); + + if (shouldUseFriendNickname) + nick = friendNickname; + } + const prefix = withMentionPrefix ? "@" : ""; - if (isRepliedMessage && !settings.store.inReplies || username.toLowerCase() === nick.toLowerCase()) + if (isRepliedMessage && !inReplies || username.toLowerCase() === nick.toLowerCase()) return <>{prefix}{nick}; - if (settings.store.mode === "user-nick") + if (mode === "user-nick") return <>{prefix}{username} {nick}; - if (settings.store.mode === "nick-user") + if (mode === "nick-user") return <>{prefix}{nick} {username}; return <>{prefix}{username}; diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 7c7488b6..705b1451 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -197,9 +197,9 @@ export const Devs = /* #__PURE__*/ Object.freeze({ name: "sunnie", id: 406028027768733696n }, - axyie: { - name: "'ax", - id: 929877747151548487n, + rae: { + name: "rae", + id: 1398136199503282277n }, pointy: { name: "pointy",