From ec07ba2974d35fa91bcc8ebcc55923556a7e9723 Mon Sep 17 00:00:00 2001
From: Etorix <92535668+EtorixDev@users.noreply.github.com>
Date: Thu, 28 Nov 2024 08:35:06 -0800
Subject: [PATCH 01/16] Added streamer mode detection, 15 name combinations,
custom colors & brackets.
---
src/plugins/showMeYourName/index.tsx | 276 +++++++++++++++++++++++---
src/plugins/showMeYourName/styles.css | 11 -
src/utils/constants.ts | 4 +
3 files changed, 254 insertions(+), 37 deletions(-)
delete mode 100644 src/plugins/showMeYourName/styles.css
diff --git a/src/plugins/showMeYourName/index.tsx b/src/plugins/showMeYourName/index.tsx
index bbafb58d32..b162022470 100644
--- a/src/plugins/showMeYourName/index.tsx
+++ b/src/plugins/showMeYourName/index.tsx
@@ -4,14 +4,79 @@
* SPDX-License-Identifier: GPL-3.0-or-later
*/
-import "./styles.css";
-
import { definePluginSettings } from "@api/Settings";
import ErrorBoundary from "@components/ErrorBoundary";
import { Devs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types";
+import { findStoreLazy } from "@webpack";
+import { ChannelStore, GuildMemberStore } from "@webpack/common";
import { Message, User } from "discord-types/general";
+const StreamerModeStore = findStoreLazy("StreamerModeStore");
+const colorPattern = /^#(?:[\da-f]{3}){1,2}$|^#(?:[\da-f]{4}){1,2}$|(rgb|hsl)a?\((\s*-?\d+%?\s*,){2}(\s*-?\d+%?\s*)\)|(rgb|hsl)a?\((\s*-?\d+%?\s*,){3}\s*(0|(0?\.\d+)|1)\)$/iu;
+const roleColorPattern = /^role((?:\+|-)\d{0,4})?$/iu;
+
+function validColor(color: string) {
+ if (!color.trim()) {
+ if (color.length > 0) {
+ return false;
+ }
+ return true;
+ }
+
+ if (color.trim().toLowerCase() === "role") {
+ return true;
+ } else if (color.toLowerCase().includes("role")) {
+ const percentage = roleColorPattern.exec(color)?.[1] || "";
+ if (isNaN(parseInt(percentage))) {
+ return false;
+ }
+ if (parseInt(percentage) > 100 || parseInt(percentage) < -100) {
+ return false;
+ }
+ return true;
+ }
+
+ const colorTestDiv = document.createElement("div");
+ colorTestDiv.style.borderColor = color;
+
+ const colorIsValid = colorTestDiv.style.borderColor !== "";
+ const matchesRegex = colorPattern.test(color);
+
+ colorTestDiv.remove();
+ return matchesRegex && colorIsValid;
+}
+
+function validSymbols(value: string) {
+ return value === "" || (value.length <= 3 && /^[\p{S}\p{P}]{1,3}$/u.test(value));
+}
+
+function resolveColor(channelId: string, userId: string, savedColor: string, fallbackColor: string) {
+ if (!savedColor.trim()) {
+ return { color: fallbackColor };
+ }
+
+ if (savedColor.toLowerCase().includes("role")) {
+ const percentageText = roleColorPattern.exec(savedColor)?.[1] || "";
+ if (percentageText && isNaN(parseInt(percentageText))) {
+ return { color: fallbackColor };
+ }
+
+ const percentage = percentageText ? 1 + (parseInt(percentageText) / 100) : 1;
+ const channel = ChannelStore.getChannel(channelId);
+ const member = channel ? GuildMemberStore.getMember(channel.guild_id, userId) : null;
+ const roleColor = member?.colorString;
+
+ if (!roleColor) {
+ return { color: fallbackColor };
+ }
+
+ return { color: roleColor, filter: `brightness(${percentage})` };
+ } else {
+ return { color: savedColor };
+ }
+}
+
interface UsernameProps {
author: { nick: string; };
message: Message;
@@ -21,31 +86,133 @@ interface UsernameProps {
}
const settings = definePluginSettings({
- mode: {
+ replies: {
+ type: OptionType.BOOLEAN,
+ default: false,
+ description: "Also display extra names in reply previews.",
+ },
+ respectStreamerMode: {
+ type: OptionType.BOOLEAN,
+ default: true,
+ description: "Truncate usernames in Streamer Mode as Discord does everywhere else.",
+ },
+ includedNames: {
type: OptionType.SELECT,
- description: "How to display usernames and nicks",
+ description: "The order to display usernames, nicknames, and display names. If any overlap or do not exist, they will be omitted.",
+ default: "nick_user",
options: [
- { label: "Username then nickname", value: "user-nick", default: true },
- { label: "Nickname then username", value: "nick-user" },
- { label: "Username only", value: "user" },
+ { label: "Nickname", value: "nick" },
+ { label: "Display Name", value: "display" },
+ { label: "Username", value: "user" },
+
+ { label: "Nickname (Username)", value: "nick_user", default: true },
+ { label: "Nickname (Display Name)", value: "nick_display" },
+ { label: "Display Name (Username)", value: "display_user" },
+ { label: "Display Name (Nickname)", value: "display_nick" },
+ { label: "Username (Nickname)", value: "user_nick" },
+ { label: "Username (Display Name)", value: "user_display" },
+
+ { label: "Nickname (Username) [Display Name]", value: "nick_user_display" },
+ { label: "Nickname (Display Name) [Username]", value: "nick_display_user" },
+ { label: "Display (Name Username) [Nickname]", value: "display_user_nick" },
+ { label: "Display (Name Nickname) [Username]", value: "display_nick_user" },
+ { label: "Username (Nickname) [Display Name]", value: "user_nick_display" },
+ { label: "Username (Display Name) [Nickname]", value: "user_display_nick" },
],
},
- displayNames: {
+ nicknamePrefix: {
+ type: OptionType.STRING,
+ description: "The symbol to use as a prefix for the nickname. Can be up to 3 non-alphanumeric characters long.",
+ default: "",
+ isValid: validSymbols,
+ },
+ nicknameSuffix: {
+ type: OptionType.STRING,
+ description: "The symbol to use as a suffix for the nickname. Can be up to 3 non-alphanumeric characters long.",
+ default: "",
+ isValid: validSymbols,
+ },
+ nicknameColor: {
+ type: OptionType.STRING,
+ description: "The color to use for the nickname. Accepts hex(a), rgb(a), or hsl(a) input. Will not affect the nickname if it is the only name displayed. Leave blank for default. \"Role\" to follow the user's top role color. \"Role+-#\" to adjust the brightness by that percentage (ex: \"Role+15\")",
+ default: "",
+ isValid: validColor,
+ },
+ nicknameSymbolColor: {
+ type: OptionType.STRING,
+ description: "The color to use for nickname symbols. Accepts hex(a), rgb(a), or hsl(a) input. Leave blank for default. \"Role\" to follow the user's top role color. \"Role+-#\" to adjust the brightness by that percentage (ex: \"Role+15\")",
+ default: "",
+ isValid: validColor,
+ },
+ alwaysShowNicknameSymbols: {
type: OptionType.BOOLEAN,
- description: "Use display names in place of usernames",
- default: false
+ description: "Show nickname prefix and suffix even if the nickname is the only name displayed, or is the first displayed.",
+ default: false,
+ },
+ displayNamePrefix: {
+ type: OptionType.STRING,
+ description: "The symbol to use as a prefix for the display name. Can be up to 3 non-alphanumeric characters long.",
+ default: "[",
+ isValid: validSymbols,
+ },
+ displayNameSuffix: {
+ type: OptionType.STRING,
+ description: "The symbol to use as a suffix for the display name. Can be up to 3 non-alphanumeric characters long.",
+ default: "]",
+ isValid: validSymbols,
},
- inReplies: {
+ displayNameColor: {
+ type: OptionType.STRING,
+ description: "The color to use for the display name. Accepts hex(a), rgb(a), or hsl(a) input. Will not affect the display name if it is the only name displayed. Leave blank for default. \"Role\" to follow the user's top role color. \"Role+-#\" to adjust the brightness by that percentage (ex: \"Role+15\")",
+ default: "",
+ isValid: validColor,
+ },
+ displayNameSymbolColor: {
+ type: OptionType.STRING,
+ description: "The color to use for display name symbols. Accepts hex(a), rgb(a), or hsl(a) input. Leave blank for default. \"Role\" to follow the user's top role color. \"Role+-#\" to adjust the brightness by that percentage (ex: \"Role+15\")",
+ default: "",
+ isValid: validColor,
+ },
+ alwaysShowDisplaySymbols: {
type: OptionType.BOOLEAN,
+ description: "Show display name prefix and suffix even if the display name is the only name displayed, or is the first displayed.",
default: false,
- description: "Also apply functionality to reply previews",
},
+ usernamePrefix: {
+ type: OptionType.STRING,
+ description: "The symbol to use as a prefix for the username. Can be up to 3 non-alphanumeric characters long.",
+ default: "(@",
+ isValid: validSymbols,
+ },
+ usernameSuffix: {
+ type: OptionType.STRING,
+ description: "The symbol to use as a suffix for the username. Can be up to 3 non-alphanumeric characters long.",
+ default: ")",
+ isValid: validSymbols,
+ },
+ usernameColor: {
+ type: OptionType.STRING,
+ description: "The color to use for the username. Accepts hex(a), rgb(a), or hsl(a) input. Will not affect the username if it is the only name displayed. Leave blank for default. \"Role\" to follow the user's top role color. \"Role+-#\" to adjust the brightness by that percentage (ex: \"Role+15\")",
+ default: "",
+ isValid: validColor,
+ },
+ usernameSymbolColor: {
+ type: OptionType.STRING,
+ description: "The color to use for username symbols. Accepts hex(a), rgb(a), or hsl(a) input. Leave blank for default. \"Role\" to follow the user's top role color. \"Role+-#\" to adjust the brightness by that percentage (ex: \"Role+15\")",
+ default: "",
+ isValid: validColor,
+ },
+ alwaysShowUsernameSymbols: {
+ type: OptionType.BOOLEAN,
+ description: "Show username prefix and suffix even if the username is the only name displayed, or is the first displayed.",
+ default: false,
+ }
});
export default definePlugin({
name: "ShowMeYourName",
- description: "Display usernames next to nicks, or no nicks at all",
- authors: [Devs.Rini, Devs.TheKodeToad],
+ description: "Display usernames, nicknames, display names, or any combination thereof in chat. Nicknames are per-server and display names are global. You will need to hover over old messages to update them after changing any settings.",
+ authors: [Devs.Rini, Devs.TheKodeToad, Devs.Etorix],
patches: [
{
find: '?"@":""',
@@ -60,25 +227,82 @@ export default definePlugin({
renderUsername: ErrorBoundary.wrap(({ author, message, isRepliedMessage, withMentionPrefix, userOverride }: UsernameProps) => {
try {
const user = userOverride ?? message.author;
- let { username } = user;
- if (settings.store.displayNames)
- username = (user as any).globalName || username;
-
- const { nick } = author;
+ const nick = author?.nick || "";
+ const username = StreamerModeStore.enabled && settings.store.respectStreamerMode ? user.username[0] + "..." : user.username;
+ const display = (user as any).globalName?.toLowerCase() === user.username.toLowerCase() ? "" : (user as any).globalName || "";
const prefix = withMentionPrefix ? "@" : "";
- if (isRepliedMessage && !settings.store.inReplies || username.toLowerCase() === nick.toLowerCase())
+ if (isRepliedMessage && !settings.store.replies) {
return <>{prefix}{nick}>;
+ }
+
+ const { alwaysShowUsernameSymbols, alwaysShowNicknameSymbols, alwaysShowDisplaySymbols } = settings.store;
+ const usernamePrefix = settings.store.usernamePrefix === "none" ? "" : settings.store.usernamePrefix;
+ const usernameSuffix = settings.store.usernameSuffix === "none" ? "" : settings.store.usernameSuffix;
+ const nicknamePrefix = settings.store.nicknamePrefix === "none" ? "" : settings.store.nicknamePrefix;
+ const nicknameSuffix = settings.store.nicknameSuffix === "none" ? "" : settings.store.nicknameSuffix;
+ const displayNamePrefix = settings.store.displayNamePrefix === "none" ? "" : settings.store.displayNamePrefix;
+ const displayNameSuffix = settings.store.displayNameSuffix === "none" ? "" : settings.store.displayNameSuffix;
- if (settings.store.mode === "user-nick")
- return <>{prefix}{username} {nick}>;
+ const values = {
+ "nick": { "value": nick, "prefix": nicknamePrefix, "suffix": nicknameSuffix, "alwaysShow": alwaysShowNicknameSymbols },
+ "display": { "value": display, "prefix": displayNamePrefix, "suffix": displayNameSuffix, "alwaysShow": alwaysShowDisplaySymbols },
+ "user": { "value": username, "prefix": usernamePrefix, "suffix": usernameSuffix, "alwaysShow": alwaysShowUsernameSymbols }
+ };
+ const order = settings.store.includedNames.split("_");
+ const first = order[0] || order[1] || order[2];
+ const second = first === order[0] ? order[1] || order[2] || "" : first === order[1] ? order[2] : "";
+ const third = second === order[1] ? order[2] || "" : "";
+ second && values[second].value.toLowerCase() === values[first].value.toLowerCase() ? values[second].value = "" : null;
+ third && values[third].value.toLowerCase() === values[first].value.toLowerCase() ? values[third].value = "" : third && values[third].value.toLowerCase() === values[second].value.toLowerCase() ? values[third].value = "" : null;
- if (settings.store.mode === "nick-user")
- return <>{prefix}{nick} {username}>;
+ const textMutedValue = getComputedStyle(document.documentElement)?.getPropertyValue("--text-muted")?.trim() || "#72767d";
+ const usernameColor = resolveColor(message.channel_id, user.id, settings.store.usernameColor.trim(), textMutedValue);
+ const usernameSymbolColor = resolveColor(message.channel_id, user.id, settings.store.usernameSymbolColor.trim(), textMutedValue);
+ const nicknameColor = resolveColor(message.channel_id, user.id, settings.store.nicknameColor.trim(), textMutedValue);
+ const nicknameSymbolColor = resolveColor(message.channel_id, user.id, settings.store.nicknameSymbolColor.trim(), textMutedValue);
+ const displayNameColor = resolveColor(message.channel_id, user.id, settings.store.displayNameColor.trim(), textMutedValue);
+ const displayNameSymbolColor = resolveColor(message.channel_id, user.id, settings.store.displayNameSymbolColor.trim(), textMutedValue);
+ const secondColor = second && values[second].value === nick ? nicknameColor : second && values[second].value === username ? usernameColor : displayNameColor;
+ const secondSymbolColor = second && values[second].value === nick ? nicknameSymbolColor : second && values[second].value === username ? usernameSymbolColor : displayNameSymbolColor;
+ const thirdColor = third && values[third].value === nick ? nicknameColor : third && values[third].value === username ? usernameColor : displayNameColor;
+ const thirdSymbolColor = third && values[third].value === nick ? nicknameSymbolColor : third && values[third].value === username ? usernameSymbolColor : displayNameSymbolColor;
- return <>{prefix}{username}>;
+ return (
+ <>
+ {values[first].value && (
+
+ {values[first].alwaysShow ? values[first].prefix : ""}
+ {values[first].value}
+ {values[first].alwaysShow ? values[first].suffix : ""}
+
+ )}
+ {second && values[second].value && (
+
+ {(values[first].value) ? : ""}
+
+ {values[second].alwaysShow || values[first].value ? values[second].prefix : ""}
+
+ {values[second].value}
+
+ {values[second].alwaysShow || values[first].value ? values[second].suffix : ""}
+
+ )}
+ {third && values[third].value && (
+
+ {values[first].value || values[second].value ? : ""}
+
+ {values[third].alwaysShow || (values[first].value || values[second].value) ? values[third].prefix : ""}
+
+ {values[third].value}
+
+ {values[third].alwaysShow || (values[first].value || values[second].value) ? values[third].suffix : ""}
+
+ )}
+ >
+ );
} catch {
- return <>{author?.nick}>;
+ return <>{StreamerModeStore.enabled && settings.store.respectStreamerMode ? ((author?.nick ? author.nick[0] : "") + "...") : author?.nick || ""}>;
}
}, { noop: true }),
});
diff --git a/src/plugins/showMeYourName/styles.css b/src/plugins/showMeYourName/styles.css
deleted file mode 100644
index 7a1455d908..0000000000
--- a/src/plugins/showMeYourName/styles.css
+++ /dev/null
@@ -1,11 +0,0 @@
-.vc-smyn-suffix {
- color: var(--text-muted);
-}
-
-.vc-smyn-suffix::before {
- content: "(";
-}
-
-.vc-smyn-suffix::after {
- content: ")";
-}
diff --git a/src/utils/constants.ts b/src/utils/constants.ts
index e758259125..2be25440c4 100644
--- a/src/utils/constants.ts
+++ b/src/utils/constants.ts
@@ -579,6 +579,10 @@ export const Devs = /* #__PURE__*/ Object.freeze({
name: "jamesbt365",
id: 158567567487795200n,
},
+ Etorix: {
+ name: "Etorix",
+ id: 94597845868355584n,
+ },
} satisfies Record);
// iife so #__PURE__ works correctly
From 8a871f963df819898c6a4019fb603eff90fef47b Mon Sep 17 00:00:00 2001
From: Etorix <92535668+EtorixDev@users.noreply.github.com>
Date: Fri, 29 Nov 2024 03:23:15 -0800
Subject: [PATCH 02/16] Remove inconsistent reply prefix, update name priority,
rearrange.
---
src/plugins/showMeYourName/index.tsx | 17 ++++++++---------
1 file changed, 8 insertions(+), 9 deletions(-)
diff --git a/src/plugins/showMeYourName/index.tsx b/src/plugins/showMeYourName/index.tsx
index b162022470..cde0ce82c1 100644
--- a/src/plugins/showMeYourName/index.tsx
+++ b/src/plugins/showMeYourName/index.tsx
@@ -224,16 +224,15 @@ export default definePlugin({
],
settings,
- renderUsername: ErrorBoundary.wrap(({ author, message, isRepliedMessage, withMentionPrefix, userOverride }: UsernameProps) => {
- try {
- const user = userOverride ?? message.author;
- const nick = author?.nick || "";
- const username = StreamerModeStore.enabled && settings.store.respectStreamerMode ? user.username[0] + "..." : user.username;
- const display = (user as any).globalName?.toLowerCase() === user.username.toLowerCase() ? "" : (user as any).globalName || "";
- const prefix = withMentionPrefix ? "@" : "";
+ renderUsername: ErrorBoundary.wrap(({ author, message, isRepliedMessage, userOverride }: UsernameProps) => {
+ const user = userOverride ?? message.author;
+ const nick = author?.nick || "";
+ const display = (user as any).globalName || "";
+ const username = StreamerModeStore.enabled && settings.store.respectStreamerMode ? user.username[0] + "..." : user.username;
+ try {
if (isRepliedMessage && !settings.store.replies) {
- return <>{prefix}{nick}>;
+ return <>{nick || display || username}>;
}
const { alwaysShowUsernameSymbols, alwaysShowNicknameSymbols, alwaysShowDisplaySymbols } = settings.store;
@@ -302,7 +301,7 @@ export default definePlugin({
>
);
} catch {
- return <>{StreamerModeStore.enabled && settings.store.respectStreamerMode ? ((author?.nick ? author.nick[0] : "") + "...") : author?.nick || ""}>;
+ return <>{StreamerModeStore.enabled && settings.store.respectStreamerMode ? ((nick || display || username)[0] + "...") : (nick || display || username)}>;
}
}, { noop: true }),
});
From c106d02818e873097b78e56b2830d0c1a7e6f573 Mon Sep 17 00:00:00 2001
From: Etorix <92535668+EtorixDev@users.noreply.github.com>
Date: Fri, 29 Nov 2024 03:48:01 -0800
Subject: [PATCH 03/16] Also truncate nick and display in streamer mode if they
are equivalent to the username.
---
src/plugins/showMeYourName/index.tsx | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/plugins/showMeYourName/index.tsx b/src/plugins/showMeYourName/index.tsx
index cde0ce82c1..dd51c47cd7 100644
--- a/src/plugins/showMeYourName/index.tsx
+++ b/src/plugins/showMeYourName/index.tsx
@@ -226,9 +226,9 @@ export default definePlugin({
renderUsername: ErrorBoundary.wrap(({ author, message, isRepliedMessage, userOverride }: UsernameProps) => {
const user = userOverride ?? message.author;
- const nick = author?.nick || "";
- const display = (user as any).globalName || "";
const username = StreamerModeStore.enabled && settings.store.respectStreamerMode ? user.username[0] + "..." : user.username;
+ const nick = StreamerModeStore.enabled && settings.store.respectStreamerMode && author?.nick?.toLowerCase() === user.username.toLowerCase() ? author.nick[0] + "..." : author?.nick || "";
+ const display = StreamerModeStore.enabled && settings.store.respectStreamerMode && (user as any).globalName?.toLowerCase() === user.username.toLowerCase() ? (user as any).globalName[0] + "..." : (user as any).globalName || "";
try {
if (isRepliedMessage && !settings.store.replies) {
From 2b44e3dba25d8de6cfd2f9d05e3b5acb0378b13e Mon Sep 17 00:00:00 2001
From: Etorix <92535668+EtorixDev@users.noreply.github.com>
Date: Fri, 29 Nov 2024 04:35:21 -0800
Subject: [PATCH 04/16] Nick/display duo fallback, username final fallback, +
code refactor.
---
src/plugins/showMeYourName/index.tsx | 78 ++++++++++++++--------------
1 file changed, 39 insertions(+), 39 deletions(-)
diff --git a/src/plugins/showMeYourName/index.tsx b/src/plugins/showMeYourName/index.tsx
index dd51c47cd7..6fa26d6473 100644
--- a/src/plugins/showMeYourName/index.tsx
+++ b/src/plugins/showMeYourName/index.tsx
@@ -98,7 +98,7 @@ const settings = definePluginSettings({
},
includedNames: {
type: OptionType.SELECT,
- description: "The order to display usernames, nicknames, and display names. If any overlap or do not exist, they will be omitted.",
+ description: "The order to display usernames, nicknames, and display names. If any overlap or do not exist, they will be omitted. Regardless of your selection below, if nickname or display name are missing, the other will be used. If both are missing, username will be used.",
default: "nick_user",
options: [
{ label: "Nickname", value: "nick" },
@@ -225,77 +225,77 @@ export default definePlugin({
settings,
renderUsername: ErrorBoundary.wrap(({ author, message, isRepliedMessage, userOverride }: UsernameProps) => {
- const user = userOverride ?? message.author;
+ const user: any = userOverride ?? message.author;
const username = StreamerModeStore.enabled && settings.store.respectStreamerMode ? user.username[0] + "..." : user.username;
- const nick = StreamerModeStore.enabled && settings.store.respectStreamerMode && author?.nick?.toLowerCase() === user.username.toLowerCase() ? author.nick[0] + "..." : author?.nick || "";
- const display = StreamerModeStore.enabled && settings.store.respectStreamerMode && (user as any).globalName?.toLowerCase() === user.username.toLowerCase() ? (user as any).globalName[0] + "..." : (user as any).globalName || "";
+ const display = StreamerModeStore.enabled && settings.store.respectStreamerMode && user.globalName?.toLowerCase() === user.username.toLowerCase() ? user.globalName[0] + "..." : user.globalName || "";
+ const nick = StreamerModeStore.enabled && settings.store.respectStreamerMode && author?.nick?.toLowerCase() === user.username.toLowerCase() ? author.nick[0] + "..." : author?.nick === display ? "" : author?.nick || "";
try {
if (isRepliedMessage && !settings.store.replies) {
return <>{nick || display || username}>;
}
+ const textMutedValue = getComputedStyle(document.documentElement)?.getPropertyValue("--text-muted")?.trim() || "#72767d";
const { alwaysShowUsernameSymbols, alwaysShowNicknameSymbols, alwaysShowDisplaySymbols } = settings.store;
const usernamePrefix = settings.store.usernamePrefix === "none" ? "" : settings.store.usernamePrefix;
const usernameSuffix = settings.store.usernameSuffix === "none" ? "" : settings.store.usernameSuffix;
+ const usernameColor = resolveColor(message.channel_id, user.id, settings.store.usernameColor.trim(), textMutedValue);
+ const usernameSymbolColor = resolveColor(message.channel_id, user.id, settings.store.usernameSymbolColor.trim(), textMutedValue);
const nicknamePrefix = settings.store.nicknamePrefix === "none" ? "" : settings.store.nicknamePrefix;
const nicknameSuffix = settings.store.nicknameSuffix === "none" ? "" : settings.store.nicknameSuffix;
+ const nicknameColor = resolveColor(message.channel_id, user.id, settings.store.nicknameColor.trim(), textMutedValue);
+ const nicknameSymbolColor = resolveColor(message.channel_id, user.id, settings.store.nicknameSymbolColor.trim(), textMutedValue);
const displayNamePrefix = settings.store.displayNamePrefix === "none" ? "" : settings.store.displayNamePrefix;
const displayNameSuffix = settings.store.displayNameSuffix === "none" ? "" : settings.store.displayNameSuffix;
+ const displayNameColor = resolveColor(message.channel_id, user.id, settings.store.displayNameColor.trim(), textMutedValue);
+ const displayNameSymbolColor = resolveColor(message.channel_id, user.id, settings.store.displayNameSymbolColor.trim(), textMutedValue);
const values = {
- "nick": { "value": nick, "prefix": nicknamePrefix, "suffix": nicknameSuffix, "alwaysShow": alwaysShowNicknameSymbols },
- "display": { "value": display, "prefix": displayNamePrefix, "suffix": displayNameSuffix, "alwaysShow": alwaysShowDisplaySymbols },
- "user": { "value": username, "prefix": usernamePrefix, "suffix": usernameSuffix, "alwaysShow": alwaysShowUsernameSymbols }
+ "user": { "value": username, "prefix": usernamePrefix, "suffix": usernameSuffix, "alwaysShow": alwaysShowUsernameSymbols, "color": usernameColor, "symbolColor": usernameSymbolColor },
+ "display": { "value": display, "prefix": displayNamePrefix, "suffix": displayNameSuffix, "alwaysShow": alwaysShowDisplaySymbols, "color": displayNameColor, "symbolColor": displayNameSymbolColor },
+ "nick": { "value": nick, "prefix": nicknamePrefix, "suffix": nicknameSuffix, "alwaysShow": alwaysShowNicknameSymbols, "color": nicknameColor, "symbolColor": nicknameSymbolColor }
};
- const order = settings.store.includedNames.split("_");
- const first = order[0] || order[1] || order[2];
- const second = first === order[0] ? order[1] || order[2] || "" : first === order[1] ? order[2] : "";
- const third = second === order[1] ? order[2] || "" : "";
- second && values[second].value.toLowerCase() === values[first].value.toLowerCase() ? values[second].value = "" : null;
- third && values[third].value.toLowerCase() === values[first].value.toLowerCase() ? values[third].value = "" : third && values[third].value.toLowerCase() === values[second].value.toLowerCase() ? values[third].value = "" : null;
- const textMutedValue = getComputedStyle(document.documentElement)?.getPropertyValue("--text-muted")?.trim() || "#72767d";
- const usernameColor = resolveColor(message.channel_id, user.id, settings.store.usernameColor.trim(), textMutedValue);
- const usernameSymbolColor = resolveColor(message.channel_id, user.id, settings.store.usernameSymbolColor.trim(), textMutedValue);
- const nicknameColor = resolveColor(message.channel_id, user.id, settings.store.nicknameColor.trim(), textMutedValue);
- const nicknameSymbolColor = resolveColor(message.channel_id, user.id, settings.store.nicknameSymbolColor.trim(), textMutedValue);
- const displayNameColor = resolveColor(message.channel_id, user.id, settings.store.displayNameColor.trim(), textMutedValue);
- const displayNameSymbolColor = resolveColor(message.channel_id, user.id, settings.store.displayNameSymbolColor.trim(), textMutedValue);
- const secondColor = second && values[second].value === nick ? nicknameColor : second && values[second].value === username ? usernameColor : displayNameColor;
- const secondSymbolColor = second && values[second].value === nick ? nicknameSymbolColor : second && values[second].value === username ? usernameSymbolColor : displayNameSymbolColor;
- const thirdColor = third && values[third].value === nick ? nicknameColor : third && values[third].value === username ? usernameColor : displayNameColor;
- const thirdSymbolColor = third && values[third].value === nick ? nicknameSymbolColor : third && values[third].value === username ? usernameSymbolColor : displayNameSymbolColor;
+ let order = settings.store.includedNames.split("_");
+ order.includes("nick") && !values.nick.value && !order.includes("display") && values.display.value ? order[order.indexOf("nick")] = "display" : null;
+ order.includes("display") && !values.display.value && !order.includes("user") && values.user.value ? order[order.indexOf("display")] = "user" : null;
+ order = order.filter((name: string) => values[name].value);
+
+ const first = order.shift() || "user";
+ let second = order.shift() || null;
+ let third = order.shift() || null;
+ second && third && values[third].value.toLowerCase() === values[second].value.toLowerCase() ? third = null : null;
+ second && values[second].value.toLowerCase() === values[first].value.toLowerCase() ? second = null : null;
return (
<>
- {values[first].value && (
+ {(
{values[first].alwaysShow ? values[first].prefix : ""}
{values[first].value}
{values[first].alwaysShow ? values[first].suffix : ""}
)}
- {second && values[second].value && (
+ {second && (
- {(values[first].value) ? : ""}
-
- {values[second].alwaysShow || values[first].value ? values[second].prefix : ""}
-
+
+
+ {values[second].prefix}
+
{values[second].value}
-
- {values[second].alwaysShow || values[first].value ? values[second].suffix : ""}
+
+ {values[second].suffix}
)}
- {third && values[third].value && (
+ {third && (
- {values[first].value || values[second].value ? : ""}
-
- {values[third].alwaysShow || (values[first].value || values[second].value) ? values[third].prefix : ""}
-
+
+
+ {values[third].prefix}
+
{values[third].value}
-
- {values[third].alwaysShow || (values[first].value || values[second].value) ? values[third].suffix : ""}
+
+ {values[third].suffix}
)}
>
From be2f1ce21da955df7312072250134a74378a8f9d Mon Sep 17 00:00:00 2001
From: Etorix <92535668+EtorixDev@users.noreply.github.com>
Date: Fri, 29 Nov 2024 06:44:08 -0800
Subject: [PATCH 05/16] Modify how overlap between nick, display, and usernames
are handled.
---
src/plugins/showMeYourName/index.tsx | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/src/plugins/showMeYourName/index.tsx b/src/plugins/showMeYourName/index.tsx
index 6fa26d6473..166da15486 100644
--- a/src/plugins/showMeYourName/index.tsx
+++ b/src/plugins/showMeYourName/index.tsx
@@ -228,7 +228,7 @@ export default definePlugin({
const user: any = userOverride ?? message.author;
const username = StreamerModeStore.enabled && settings.store.respectStreamerMode ? user.username[0] + "..." : user.username;
const display = StreamerModeStore.enabled && settings.store.respectStreamerMode && user.globalName?.toLowerCase() === user.username.toLowerCase() ? user.globalName[0] + "..." : user.globalName || "";
- const nick = StreamerModeStore.enabled && settings.store.respectStreamerMode && author?.nick?.toLowerCase() === user.username.toLowerCase() ? author.nick[0] + "..." : author?.nick === display ? "" : author?.nick || "";
+ const nick = StreamerModeStore.enabled && settings.store.respectStreamerMode && author?.nick?.toLowerCase() === user.username.toLowerCase() ? author.nick[0] + "..." : author?.nick || "";
try {
if (isRepliedMessage && !settings.store.replies) {
@@ -264,8 +264,14 @@ export default definePlugin({
const first = order.shift() || "user";
let second = order.shift() || null;
let third = order.shift() || null;
+ // Override the display name if it is just an alternate capitalization of the username and they are in the second and third positions.
+ second === "display" && third === "user" && values[second].value.toLowerCase() === values[third].value.toLowerCase() ? second = null : null;
+ // If third is the same as second, remove it.
second && third && values[third].value.toLowerCase() === values[second].value.toLowerCase() ? third = null : null;
+ // If second is the same as first, remove it.
second && values[second].value.toLowerCase() === values[first].value.toLowerCase() ? second = null : null;
+ // If third is the same as first, remove it. Occurs if all three names are actually set and are the same.
+ third && values[third].value.toLowerCase() === values[first].value.toLowerCase() ? third = null : null;
return (
<>
From 38acfe3920ba481d475fe812719ecd1d21abb32d Mon Sep 17 00:00:00 2001
From: Etorix <92535668+EtorixDev@users.noreply.github.com>
Date: Fri, 29 Nov 2024 07:21:44 -0800
Subject: [PATCH 06/16] Remove username override & add removeDuplicates
setting.
---
src/plugins/showMeYourName/index.tsx | 30 +++++++++++++++++-----------
1 file changed, 18 insertions(+), 12 deletions(-)
diff --git a/src/plugins/showMeYourName/index.tsx b/src/plugins/showMeYourName/index.tsx
index 166da15486..74f0894589 100644
--- a/src/plugins/showMeYourName/index.tsx
+++ b/src/plugins/showMeYourName/index.tsx
@@ -96,6 +96,11 @@ const settings = definePluginSettings({
default: true,
description: "Truncate usernames in Streamer Mode as Discord does everywhere else.",
},
+ removeDuplicates: {
+ type: OptionType.BOOLEAN,
+ default: true,
+ description: "If any of the names are equivalent, only display the unique ones.",
+ },
includedNames: {
type: OptionType.SELECT,
description: "The order to display usernames, nicknames, and display names. If any overlap or do not exist, they will be omitted. Regardless of your selection below, if nickname or display name are missing, the other will be used. If both are missing, username will be used.",
@@ -114,8 +119,8 @@ const settings = definePluginSettings({
{ label: "Nickname (Username) [Display Name]", value: "nick_user_display" },
{ label: "Nickname (Display Name) [Username]", value: "nick_display_user" },
- { label: "Display (Name Username) [Nickname]", value: "display_user_nick" },
- { label: "Display (Name Nickname) [Username]", value: "display_nick_user" },
+ { label: "Display Name (Username) [Nickname]", value: "display_user_nick" },
+ { label: "Display Name (Nickname) [Username]", value: "display_nick_user" },
{ label: "Username (Nickname) [Display Name]", value: "user_nick_display" },
{ label: "Username (Display Name) [Nickname]", value: "user_display_nick" },
],
@@ -123,13 +128,13 @@ const settings = definePluginSettings({
nicknamePrefix: {
type: OptionType.STRING,
description: "The symbol to use as a prefix for the nickname. Can be up to 3 non-alphanumeric characters long.",
- default: "",
+ default: "(",
isValid: validSymbols,
},
nicknameSuffix: {
type: OptionType.STRING,
description: "The symbol to use as a suffix for the nickname. Can be up to 3 non-alphanumeric characters long.",
- default: "",
+ default: ")",
isValid: validSymbols,
},
nicknameColor: {
@@ -264,14 +269,15 @@ export default definePlugin({
const first = order.shift() || "user";
let second = order.shift() || null;
let third = order.shift() || null;
- // Override the display name if it is just an alternate capitalization of the username and they are in the second and third positions.
- second === "display" && third === "user" && values[second].value.toLowerCase() === values[third].value.toLowerCase() ? second = null : null;
- // If third is the same as second, remove it.
- second && third && values[third].value.toLowerCase() === values[second].value.toLowerCase() ? third = null : null;
- // If second is the same as first, remove it.
- second && values[second].value.toLowerCase() === values[first].value.toLowerCase() ? second = null : null;
- // If third is the same as first, remove it. Occurs if all three names are actually set and are the same.
- third && values[third].value.toLowerCase() === values[first].value.toLowerCase() ? third = null : null;
+
+ if (settings.store.removeDuplicates) {
+ // If third is the same as second, remove it.
+ second && third && values[third].value.toLowerCase() === values[second].value.toLowerCase() ? third = null : null;
+ // If second is the same as first, remove it.
+ second && values[second].value.toLowerCase() === values[first].value.toLowerCase() ? second = null : null;
+ // If third is the same as first, remove it.
+ third && values[third].value.toLowerCase() === values[first].value.toLowerCase() ? third = null : null;
+ }
return (
<>
From 05d2307584ba2c0232f30bc0c60e80ddc80d892e Mon Sep 17 00:00:00 2001
From: Etorix <92535668+EtorixDev@users.noreply.github.com>
Date: Fri, 29 Nov 2024 18:09:40 -0800
Subject: [PATCH 07/16] Make replacing dupes optional, conditionally prioritize
username on x_x_user order.
---
src/plugins/showMeYourName/index.tsx | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/plugins/showMeYourName/index.tsx b/src/plugins/showMeYourName/index.tsx
index 74f0894589..35e92c1f55 100644
--- a/src/plugins/showMeYourName/index.tsx
+++ b/src/plugins/showMeYourName/index.tsx
@@ -99,11 +99,11 @@ const settings = definePluginSettings({
removeDuplicates: {
type: OptionType.BOOLEAN,
default: true,
- description: "If any of the names are equivalent, only display the unique ones.",
+ description: "If any of the names are equivalent, remove them, leaving only the unique names.",
},
includedNames: {
type: OptionType.SELECT,
- description: "The order to display usernames, nicknames, and display names. If any overlap or do not exist, they will be omitted. Regardless of your selection below, if nickname or display name are missing, the other will be used. If both are missing, username will be used.",
+ description: "The order to display usernames, nicknames, and display names. If any do not exist for the user, they will be omitted. Regardless of your selection below, if nickname or display name are missing, the other will replace it. If both are missing, username will be used.",
default: "nick_user",
options: [
{ label: "Nickname", value: "nick" },
@@ -271,8 +271,8 @@ export default definePlugin({
let third = order.shift() || null;
if (settings.store.removeDuplicates) {
- // If third is the same as second, remove it.
- second && third && values[third].value.toLowerCase() === values[second].value.toLowerCase() ? third = null : null;
+ // If third is the same as second, remove it, unless third is the username, then prioritize it.
+ second && third && values[third].value.toLowerCase() === values[second].value.toLowerCase() ? third === "user" ? second = null : third = null : null;
// If second is the same as first, remove it.
second && values[second].value.toLowerCase() === values[first].value.toLowerCase() ? second = null : null;
// If third is the same as first, remove it.
From 2d1edd711c33441c1060781fa3d39c9ddf048ec3 Mon Sep 17 00:00:00 2001
From: Etorix <92535668+EtorixDev@users.noreply.github.com>
Date: Fri, 29 Nov 2024 18:21:21 -0800
Subject: [PATCH 08/16] Fix prefix/suffix color of first name if alwaysShow
enabled.
---
src/plugins/showMeYourName/index.tsx | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/plugins/showMeYourName/index.tsx b/src/plugins/showMeYourName/index.tsx
index 35e92c1f55..f198bb62df 100644
--- a/src/plugins/showMeYourName/index.tsx
+++ b/src/plugins/showMeYourName/index.tsx
@@ -283,9 +283,11 @@ export default definePlugin({
<>
{(
- {values[first].alwaysShow ? values[first].prefix : ""}
+ {values[first].alwaysShow &&
+ {values[first].prefix}}
{values[first].value}
- {values[first].alwaysShow ? values[first].suffix : ""}
+ {values[first].alwaysShow &&
+ {values[first].suffix}}
)}
{second && (
From a8866cd0c48bd76e86f0fb0238828b7e2fbdb5ee Mon Sep 17 00:00:00 2001
From: Etorix <92535668+EtorixDev@users.noreply.github.com>
Date: Thu, 26 Dec 2024 02:25:33 -0800
Subject: [PATCH 09/16] Add setting to overwrite first name color + modify
defaults.
---
src/plugins/showMeYourName/index.tsx | 52 +++++++++++++++++++---------
1 file changed, 35 insertions(+), 17 deletions(-)
diff --git a/src/plugins/showMeYourName/index.tsx b/src/plugins/showMeYourName/index.tsx
index f198bb62df..d567739b7e 100644
--- a/src/plugins/showMeYourName/index.tsx
+++ b/src/plugins/showMeYourName/index.tsx
@@ -104,13 +104,13 @@ const settings = definePluginSettings({
includedNames: {
type: OptionType.SELECT,
description: "The order to display usernames, nicknames, and display names. If any do not exist for the user, they will be omitted. Regardless of your selection below, if nickname or display name are missing, the other will replace it. If both are missing, username will be used.",
- default: "nick_user",
+ default: "nick_display_user",
options: [
{ label: "Nickname", value: "nick" },
{ label: "Display Name", value: "display" },
{ label: "Username", value: "user" },
- { label: "Nickname (Username)", value: "nick_user", default: true },
+ { label: "Nickname (Username)", value: "nick_user" },
{ label: "Nickname (Display Name)", value: "nick_display" },
{ label: "Display Name (Username)", value: "display_user" },
{ label: "Display Name (Nickname)", value: "display_nick" },
@@ -118,7 +118,7 @@ const settings = definePluginSettings({
{ label: "Username (Display Name)", value: "user_display" },
{ label: "Nickname (Username) [Display Name]", value: "nick_user_display" },
- { label: "Nickname (Display Name) [Username]", value: "nick_display_user" },
+ { label: "Nickname (Display Name) [Username]", value: "nick_display_user", default: true },
{ label: "Display Name (Username) [Nickname]", value: "display_user_nick" },
{ label: "Display Name (Nickname) [Username]", value: "display_nick_user" },
{ label: "Username (Nickname) [Display Name]", value: "user_nick_display" },
@@ -139,8 +139,8 @@ const settings = definePluginSettings({
},
nicknameColor: {
type: OptionType.STRING,
- description: "The color to use for the nickname. Accepts hex(a), rgb(a), or hsl(a) input. Will not affect the nickname if it is the only name displayed. Leave blank for default. \"Role\" to follow the user's top role color. \"Role+-#\" to adjust the brightness by that percentage (ex: \"Role+15\")",
- default: "",
+ description: "The color to use for the nickname. Accepts hex(a), rgb(a), or hsl(a) input. Leave blank for default. \"Role\" to follow the user's top role color. \"Role+-#\" to adjust the brightness by that percentage (ex: \"Role+15\")",
+ default: "Role-25",
isValid: validColor,
},
nicknameSymbolColor: {
@@ -154,6 +154,11 @@ const settings = definePluginSettings({
description: "Show nickname prefix and suffix even if the nickname is the only name displayed, or is the first displayed.",
default: false,
},
+ alwaysShowNicknameColor: {
+ type: OptionType.BOOLEAN,
+ description: "Show nickname color even if the nickname is the only name displayed, or is the first displayed.",
+ default: false,
+ },
displayNamePrefix: {
type: OptionType.STRING,
description: "The symbol to use as a prefix for the display name. Can be up to 3 non-alphanumeric characters long.",
@@ -168,8 +173,8 @@ const settings = definePluginSettings({
},
displayNameColor: {
type: OptionType.STRING,
- description: "The color to use for the display name. Accepts hex(a), rgb(a), or hsl(a) input. Will not affect the display name if it is the only name displayed. Leave blank for default. \"Role\" to follow the user's top role color. \"Role+-#\" to adjust the brightness by that percentage (ex: \"Role+15\")",
- default: "",
+ description: "The color to use for the display name. Accepts hex(a), rgb(a), or hsl(a) input. Leave blank for default. \"Role\" to follow the user's top role color. \"Role+-#\" to adjust the brightness by that percentage (ex: \"Role+15\")",
+ default: "Role-25",
isValid: validColor,
},
displayNameSymbolColor: {
@@ -183,6 +188,11 @@ const settings = definePluginSettings({
description: "Show display name prefix and suffix even if the display name is the only name displayed, or is the first displayed.",
default: false,
},
+ alwaysShowDisplayColor: {
+ type: OptionType.BOOLEAN,
+ description: "Show display name color even if the display name is the only name displayed, or is the first displayed.",
+ default: false,
+ },
usernamePrefix: {
type: OptionType.STRING,
description: "The symbol to use as a prefix for the username. Can be up to 3 non-alphanumeric characters long.",
@@ -197,8 +207,8 @@ const settings = definePluginSettings({
},
usernameColor: {
type: OptionType.STRING,
- description: "The color to use for the username. Accepts hex(a), rgb(a), or hsl(a) input. Will not affect the username if it is the only name displayed. Leave blank for default. \"Role\" to follow the user's top role color. \"Role+-#\" to adjust the brightness by that percentage (ex: \"Role+15\")",
- default: "",
+ description: "The color to use for the username. Accepts hex(a), rgb(a), or hsl(a) input. Leave blank for default. \"Role\" to follow the user's top role color. \"Role+-#\" to adjust the brightness by that percentage (ex: \"Role+15\")",
+ default: "Role-25",
isValid: validColor,
},
usernameSymbolColor: {
@@ -211,12 +221,17 @@ const settings = definePluginSettings({
type: OptionType.BOOLEAN,
description: "Show username prefix and suffix even if the username is the only name displayed, or is the first displayed.",
default: false,
+ },
+ alwaysShowUsernameColor: {
+ type: OptionType.BOOLEAN,
+ description: "Show username color even if the username is the only name displayed, or is the first displayed.",
+ default: false,
}
});
export default definePlugin({
name: "ShowMeYourName",
- description: "Display usernames, nicknames, display names, or any combination thereof in chat. Nicknames are per-server and display names are global. You will need to hover over old messages to update them after changing any settings.",
+ description: "Display usernames, nicknames, display names, or any permutation thereof in chat. Nicknames are per-server and display names are global. You will need to hover over old messages to update them after changing any settings.",
authors: [Devs.Rini, Devs.TheKodeToad, Devs.Etorix],
patches: [
{
@@ -241,7 +256,7 @@ export default definePlugin({
}
const textMutedValue = getComputedStyle(document.documentElement)?.getPropertyValue("--text-muted")?.trim() || "#72767d";
- const { alwaysShowUsernameSymbols, alwaysShowNicknameSymbols, alwaysShowDisplaySymbols } = settings.store;
+ const { alwaysShowUsernameSymbols, alwaysShowNicknameSymbols, alwaysShowDisplaySymbols, alwaysShowUsernameColor, alwaysShowNicknameColor, alwaysShowDisplayColor } = settings.store;
const usernamePrefix = settings.store.usernamePrefix === "none" ? "" : settings.store.usernamePrefix;
const usernameSuffix = settings.store.usernameSuffix === "none" ? "" : settings.store.usernameSuffix;
const usernameColor = resolveColor(message.channel_id, user.id, settings.store.usernameColor.trim(), textMutedValue);
@@ -256,9 +271,9 @@ export default definePlugin({
const displayNameSymbolColor = resolveColor(message.channel_id, user.id, settings.store.displayNameSymbolColor.trim(), textMutedValue);
const values = {
- "user": { "value": username, "prefix": usernamePrefix, "suffix": usernameSuffix, "alwaysShow": alwaysShowUsernameSymbols, "color": usernameColor, "symbolColor": usernameSymbolColor },
- "display": { "value": display, "prefix": displayNamePrefix, "suffix": displayNameSuffix, "alwaysShow": alwaysShowDisplaySymbols, "color": displayNameColor, "symbolColor": displayNameSymbolColor },
- "nick": { "value": nick, "prefix": nicknamePrefix, "suffix": nicknameSuffix, "alwaysShow": alwaysShowNicknameSymbols, "color": nicknameColor, "symbolColor": nicknameSymbolColor }
+ "user": { "value": username, "prefix": usernamePrefix, "suffix": usernameSuffix, "alwaysShowSymbols": alwaysShowUsernameSymbols, "alwaysShowColor": alwaysShowUsernameColor, "color": usernameColor, "symbolColor": usernameSymbolColor },
+ "display": { "value": display, "prefix": displayNamePrefix, "suffix": displayNameSuffix, "alwaysShowSymbols": alwaysShowDisplaySymbols, "alwaysShowColor": alwaysShowDisplayColor, "color": displayNameColor, "symbolColor": displayNameSymbolColor },
+ "nick": { "value": nick, "prefix": nicknamePrefix, "suffix": nicknameSuffix, "alwaysShowSymbols": alwaysShowNicknameSymbols, "alwaysShowColor": alwaysShowNicknameColor, "color": nicknameColor, "symbolColor": nicknameSymbolColor }
};
let order = settings.store.includedNames.split("_");
@@ -283,10 +298,13 @@ export default definePlugin({
<>
{(
- {values[first].alwaysShow &&
+ {values[first].alwaysShowSymbols &&
{values[first].prefix}}
- {values[first].value}
- {values[first].alwaysShow &&
+ {values[first].alwaysShowColor &&
+ {values[first].value}}
+ {!values[first].alwaysShowColor &&
+ {values[first].value}}
+ {values[first].alwaysShowSymbols &&
{values[first].suffix}}
)}
From e774de202f82f9c9077378b57af690b2763c853f Mon Sep 17 00:00:00 2001
From: Etorix <92535668+EtorixDev@users.noreply.github.com>
Date: Thu, 26 Dec 2024 04:38:49 -0800
Subject: [PATCH 10/16] Borrow sadan's mention feature + fix affix oversight.
---
src/plugins/showMeYourName/index.tsx | 78 +++++++++++++++++-----------
1 file changed, 48 insertions(+), 30 deletions(-)
diff --git a/src/plugins/showMeYourName/index.tsx b/src/plugins/showMeYourName/index.tsx
index d567739b7e..9dd34ab3e2 100644
--- a/src/plugins/showMeYourName/index.tsx
+++ b/src/plugins/showMeYourName/index.tsx
@@ -9,8 +9,8 @@ import ErrorBoundary from "@components/ErrorBoundary";
import { Devs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types";
import { findStoreLazy } from "@webpack";
-import { ChannelStore, GuildMemberStore } from "@webpack/common";
-import { Message, User } from "discord-types/general";
+import { ChannelStore, GuildMemberStore, UserStore } from "@webpack/common";
+import { GuildMember, User } from "discord-types/general";
const StreamerModeStore = findStoreLazy("StreamerModeStore");
const colorPattern = /^#(?:[\da-f]{3}){1,2}$|^#(?:[\da-f]{4}){1,2}$|(rgb|hsl)a?\((\s*-?\d+%?\s*,){2}(\s*-?\d+%?\s*)\)|(rgb|hsl)a?\((\s*-?\d+%?\s*,){3}\s*(0|(0?\.\d+)|1)\)$/iu;
@@ -51,7 +51,7 @@ function validSymbols(value: string) {
return value === "" || (value.length <= 3 && /^[\p{S}\p{P}]{1,3}$/u.test(value));
}
-function resolveColor(channelId: string, userId: string, savedColor: string, fallbackColor: string) {
+function resolveColor(user: User | GuildMember, savedColor: string, fallbackColor: string) {
if (!savedColor.trim()) {
return { color: fallbackColor };
}
@@ -63,9 +63,7 @@ function resolveColor(channelId: string, userId: string, savedColor: string, fal
}
const percentage = percentageText ? 1 + (parseInt(percentageText) / 100) : 1;
- const channel = ChannelStore.getChannel(channelId);
- const member = channel ? GuildMemberStore.getMember(channel.guild_id, userId) : null;
- const roleColor = member?.colorString;
+ const roleColor = (user as GuildMember)?.colorString || null;
if (!roleColor) {
return { color: fallbackColor };
@@ -77,20 +75,18 @@ function resolveColor(channelId: string, userId: string, savedColor: string, fal
}
}
-interface UsernameProps {
- author: { nick: string; };
- message: Message;
- withMentionPrefix?: boolean;
- isRepliedMessage: boolean;
- userOverride?: User;
-}
-
const settings = definePluginSettings({
replies: {
type: OptionType.BOOLEAN,
default: false,
description: "Also display extra names in reply previews.",
},
+ mentions: {
+ type: OptionType.BOOLEAN,
+ default: true,
+ description: "Also display extra names in mentions.",
+ restartNeeded: true
+ },
respectStreamerMode: {
type: OptionType.BOOLEAN,
default: true,
@@ -232,7 +228,7 @@ const settings = definePluginSettings({
export default definePlugin({
name: "ShowMeYourName",
description: "Display usernames, nicknames, display names, or any permutation thereof in chat. Nicknames are per-server and display names are global. You will need to hover over old messages to update them after changing any settings.",
- authors: [Devs.Rini, Devs.TheKodeToad, Devs.Etorix],
+ authors: [Devs.Rini, Devs.TheKodeToad, Devs.Etorix, Devs.sadan],
patches: [
{
find: '?"@":""',
@@ -241,11 +237,37 @@ export default definePlugin({
replace: "$self.renderUsername(arguments[0])}"
}
},
+ {
+ find: "missing user\"",
+ predicate: () => settings.store.mentions,
+ replacement: {
+ match: /"@"\.concat\(null!=(\i)\?\i:(\i)\)/,
+ replace: "$self.renderUsername(arguments[0])"
+ }
+ },
],
settings,
- renderUsername: ErrorBoundary.wrap(({ author, message, isRepliedMessage, userOverride }: UsernameProps) => {
- const user: any = userOverride ?? message.author;
+ renderUsername: ErrorBoundary.wrap((props: any) => {
+ const renderType = props.className === "mention" ? "mention" : "message";
+ let author, isRepliedMessage;
+
+ if (renderType === "mention") {
+ const channel = ChannelStore.getChannel(props.channelId) || {};
+ const usr = UserStore.getUser(props.userId) || {};
+ const mem = GuildMemberStore.getMember(channel.guild_id, props.userId) || {};
+ author = { ...usr, ...mem };
+ isRepliedMessage = false;
+ } else if (renderType === "message") {
+ author = props.userOverride || { ...props.message.author, ...props.author };
+ isRepliedMessage = props.isRepliedMessage;
+ }
+
+ if (!author) {
+ return <>Unknown>;
+ }
+
+ const user: any = author;
const username = StreamerModeStore.enabled && settings.store.respectStreamerMode ? user.username[0] + "..." : user.username;
const display = StreamerModeStore.enabled && settings.store.respectStreamerMode && user.globalName?.toLowerCase() === user.username.toLowerCase() ? user.globalName[0] + "..." : user.globalName || "";
const nick = StreamerModeStore.enabled && settings.store.respectStreamerMode && author?.nick?.toLowerCase() === user.username.toLowerCase() ? author.nick[0] + "..." : author?.nick || "";
@@ -257,18 +279,13 @@ export default definePlugin({
const textMutedValue = getComputedStyle(document.documentElement)?.getPropertyValue("--text-muted")?.trim() || "#72767d";
const { alwaysShowUsernameSymbols, alwaysShowNicknameSymbols, alwaysShowDisplaySymbols, alwaysShowUsernameColor, alwaysShowNicknameColor, alwaysShowDisplayColor } = settings.store;
- const usernamePrefix = settings.store.usernamePrefix === "none" ? "" : settings.store.usernamePrefix;
- const usernameSuffix = settings.store.usernameSuffix === "none" ? "" : settings.store.usernameSuffix;
- const usernameColor = resolveColor(message.channel_id, user.id, settings.store.usernameColor.trim(), textMutedValue);
- const usernameSymbolColor = resolveColor(message.channel_id, user.id, settings.store.usernameSymbolColor.trim(), textMutedValue);
- const nicknamePrefix = settings.store.nicknamePrefix === "none" ? "" : settings.store.nicknamePrefix;
- const nicknameSuffix = settings.store.nicknameSuffix === "none" ? "" : settings.store.nicknameSuffix;
- const nicknameColor = resolveColor(message.channel_id, user.id, settings.store.nicknameColor.trim(), textMutedValue);
- const nicknameSymbolColor = resolveColor(message.channel_id, user.id, settings.store.nicknameSymbolColor.trim(), textMutedValue);
- const displayNamePrefix = settings.store.displayNamePrefix === "none" ? "" : settings.store.displayNamePrefix;
- const displayNameSuffix = settings.store.displayNameSuffix === "none" ? "" : settings.store.displayNameSuffix;
- const displayNameColor = resolveColor(message.channel_id, user.id, settings.store.displayNameColor.trim(), textMutedValue);
- const displayNameSymbolColor = resolveColor(message.channel_id, user.id, settings.store.displayNameSymbolColor.trim(), textMutedValue);
+ const { usernamePrefix, usernameSuffix, nicknamePrefix, nicknameSuffix, displayNamePrefix, displayNameSuffix } = settings.store;
+ const usernameColor = resolveColor(user, settings.store.usernameColor.trim(), textMutedValue);
+ const usernameSymbolColor = resolveColor(user, settings.store.usernameSymbolColor.trim(), textMutedValue);
+ const nicknameColor = resolveColor(user, settings.store.nicknameColor.trim(), textMutedValue);
+ const nicknameSymbolColor = resolveColor(user, settings.store.nicknameSymbolColor.trim(), textMutedValue);
+ const displayNameColor = resolveColor(user, settings.store.displayNameColor.trim(), textMutedValue);
+ const displayNameSymbolColor = resolveColor(user, settings.store.displayNameSymbolColor.trim(), textMutedValue);
const values = {
"user": { "value": username, "prefix": usernamePrefix, "suffix": usernameSuffix, "alwaysShowSymbols": alwaysShowUsernameSymbols, "alwaysShowColor": alwaysShowUsernameColor, "color": usernameColor, "symbolColor": usernameSymbolColor },
@@ -332,7 +349,8 @@ export default definePlugin({
)}
>
);
- } catch {
+ } catch (e) {
+ console.error(e);
return <>{StreamerModeStore.enabled && settings.store.respectStreamerMode ? ((nick || display || username)[0] + "...") : (nick || display || username)}>;
}
}, { noop: true }),
From af1b757d3c6768a26ace6630186e5b6590a3a504 Mon Sep 17 00:00:00 2001
From: Etorix <92535668+EtorixDev@users.noreply.github.com>
Date: Thu, 26 Dec 2024 04:50:54 -0800
Subject: [PATCH 11/16] Remove mysterious userOverride.
---
src/plugins/showMeYourName/index.tsx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/plugins/showMeYourName/index.tsx b/src/plugins/showMeYourName/index.tsx
index 9dd34ab3e2..a750f56676 100644
--- a/src/plugins/showMeYourName/index.tsx
+++ b/src/plugins/showMeYourName/index.tsx
@@ -259,7 +259,7 @@ export default definePlugin({
author = { ...usr, ...mem };
isRepliedMessage = false;
} else if (renderType === "message") {
- author = props.userOverride || { ...props.message.author, ...props.author };
+ author = { ...props.message.author, ...props.author };
isRepliedMessage = props.isRepliedMessage;
}
From d8f21f81f186d078a6ef68e24e976ff4d350cfdb Mon Sep 17 00:00:00 2001
From: Etorix <92535668+EtorixDev@users.noreply.github.com>
Date: Thu, 26 Dec 2024 04:57:50 -0800
Subject: [PATCH 12/16] Reword plugin description.
---
src/plugins/showMeYourName/index.tsx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/plugins/showMeYourName/index.tsx b/src/plugins/showMeYourName/index.tsx
index a750f56676..7b167e8cbe 100644
--- a/src/plugins/showMeYourName/index.tsx
+++ b/src/plugins/showMeYourName/index.tsx
@@ -227,7 +227,7 @@ const settings = definePluginSettings({
export default definePlugin({
name: "ShowMeYourName",
- description: "Display usernames, nicknames, display names, or any permutation thereof in chat. Nicknames are per-server and display names are global. You will need to hover over old messages to update them after changing any settings.",
+ description: "Display any permutation of nicknames, display names, and usernames in chat. Nicknames are per-server and display names are global. You will need to hover over old messages to update them after changing any settings.",
authors: [Devs.Rini, Devs.TheKodeToad, Devs.Etorix, Devs.sadan],
patches: [
{
From d0e259d7e27ef601b88ec48e5675771d72016f31 Mon Sep 17 00:00:00 2001
From: Etorix <92535668+EtorixDev@users.noreply.github.com>
Date: Thu, 26 Dec 2024 06:41:11 -0800
Subject: [PATCH 13/16] Fix global name overwriting nickname bug + update
mention symbol handling.
---
src/plugins/showMeYourName/index.tsx | 29 ++++++++++++++++++++++------
1 file changed, 23 insertions(+), 6 deletions(-)
diff --git a/src/plugins/showMeYourName/index.tsx b/src/plugins/showMeYourName/index.tsx
index 7b167e8cbe..bfb0409726 100644
--- a/src/plugins/showMeYourName/index.tsx
+++ b/src/plugins/showMeYourName/index.tsx
@@ -79,14 +79,19 @@ const settings = definePluginSettings({
replies: {
type: OptionType.BOOLEAN,
default: false,
- description: "Also display extra names in reply previews.",
+ description: "Also display extra names in replies.",
},
mentions: {
type: OptionType.BOOLEAN,
- default: true,
+ default: false,
description: "Also display extra names in mentions.",
restartNeeded: true
},
+ hideDefaultAtSign: {
+ type: OptionType.BOOLEAN,
+ default: false,
+ description: "Hide the default '@' symbol before the name in mentions and replies. Only applied if either feature is enabled.",
+ },
respectStreamerMode: {
type: OptionType.BOOLEAN,
default: true,
@@ -251,6 +256,7 @@ export default definePlugin({
renderUsername: ErrorBoundary.wrap((props: any) => {
const renderType = props.className === "mention" ? "mention" : "message";
let author, isRepliedMessage;
+ let mentionSymbol = "";
if (renderType === "mention") {
const channel = ChannelStore.getChannel(props.channelId) || {};
@@ -258,13 +264,23 @@ export default definePlugin({
const mem = GuildMemberStore.getMember(channel.guild_id, props.userId) || {};
author = { ...usr, ...mem };
isRepliedMessage = false;
+ mentionSymbol = settings.store.hideDefaultAtSign ? "" : "@";
} else if (renderType === "message") {
- author = { ...props.message.author, ...props.author };
+ // props.message.author only has a globalName attribute.
+ // props.author only has a nick attribute, but it is overwritten by the globalName if no nickname is set.
+ // getUser only has a globalName attribute.
+ // getMember only has a nick attribute, and it is null if no nickname is set.
+ // Therefore just using the author props is not enough for an accurate result and we instead need to combine the results of getUser and getMember.
+ const channel = ChannelStore.getChannel(props.message.channel_id) || {};
+ const usr = UserStore.getUser(props.message.author.id) || {};
+ const mem = GuildMemberStore.getMember(channel.guild_id, props.message.author.id) || {};
+ author = { ...usr, ...mem };
isRepliedMessage = props.isRepliedMessage;
+ mentionSymbol = settings.store.hideDefaultAtSign ? "" : props.withMentionPrefix ? "@" : "";
}
if (!author) {
- return <>Unknown>;
+ return <>{mentionSymbol}Unknown>;
}
const user: any = author;
@@ -274,7 +290,7 @@ export default definePlugin({
try {
if (isRepliedMessage && !settings.store.replies) {
- return <>{nick || display || username}>;
+ return <>{mentionSymbol}{nick || display || username}>;
}
const textMutedValue = getComputedStyle(document.documentElement)?.getPropertyValue("--text-muted")?.trim() || "#72767d";
@@ -313,6 +329,7 @@ export default definePlugin({
return (
<>
+ {mentionSymbol && {mentionSymbol}}
{(
{values[first].alwaysShowSymbols &&
@@ -351,7 +368,7 @@ export default definePlugin({
);
} catch (e) {
console.error(e);
- return <>{StreamerModeStore.enabled && settings.store.respectStreamerMode ? ((nick || display || username)[0] + "...") : (nick || display || username)}>;
+ return <>{mentionSymbol}{StreamerModeStore.enabled && settings.store.respectStreamerMode ? ((nick || display || username)[0] + "...") : (nick || display || username)}>;
}
}, { noop: true }),
});
From 0025e4c4da8cad0642f1916f89f4908f750699b5 Mon Sep 17 00:00:00 2001
From: Etorix <92535668+EtorixDev@users.noreply.github.com>
Date: Thu, 26 Dec 2024 07:12:43 -0800
Subject: [PATCH 14/16] Fix some typing and typos.
---
src/plugins/showMeYourName/index.tsx | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/src/plugins/showMeYourName/index.tsx b/src/plugins/showMeYourName/index.tsx
index bfb0409726..91f5f0066e 100644
--- a/src/plugins/showMeYourName/index.tsx
+++ b/src/plugins/showMeYourName/index.tsx
@@ -255,14 +255,15 @@ export default definePlugin({
renderUsername: ErrorBoundary.wrap((props: any) => {
const renderType = props.className === "mention" ? "mention" : "message";
- let author, isRepliedMessage;
+ let author: any = null;
+ let isRepliedMessage = false;
let mentionSymbol = "";
if (renderType === "mention") {
const channel = ChannelStore.getChannel(props.channelId) || {};
const usr = UserStore.getUser(props.userId) || {};
const mem = GuildMemberStore.getMember(channel.guild_id, props.userId) || {};
- author = { ...usr, ...mem };
+ author = usr && mem ? { ...usr, ...mem } : usr || mem || null;
isRepliedMessage = false;
mentionSymbol = settings.store.hideDefaultAtSign ? "" : "@";
} else if (renderType === "message") {
@@ -274,7 +275,7 @@ export default definePlugin({
const channel = ChannelStore.getChannel(props.message.channel_id) || {};
const usr = UserStore.getUser(props.message.author.id) || {};
const mem = GuildMemberStore.getMember(channel.guild_id, props.message.author.id) || {};
- author = { ...usr, ...mem };
+ author = usr && mem ? { ...usr, ...mem } : usr || mem || null;
isRepliedMessage = props.isRepliedMessage;
mentionSymbol = settings.store.hideDefaultAtSign ? "" : props.withMentionPrefix ? "@" : "";
}
@@ -283,10 +284,10 @@ export default definePlugin({
return <>{mentionSymbol}Unknown>;
}
- const user: any = author;
+ const user = author;
const username = StreamerModeStore.enabled && settings.store.respectStreamerMode ? user.username[0] + "..." : user.username;
const display = StreamerModeStore.enabled && settings.store.respectStreamerMode && user.globalName?.toLowerCase() === user.username.toLowerCase() ? user.globalName[0] + "..." : user.globalName || "";
- const nick = StreamerModeStore.enabled && settings.store.respectStreamerMode && author?.nick?.toLowerCase() === user.username.toLowerCase() ? author.nick[0] + "..." : author?.nick || "";
+ const nick = StreamerModeStore.enabled && settings.store.respectStreamerMode && user.nick?.toLowerCase() === user.username.toLowerCase() ? user.nick[0] + "..." : user.nick || "";
try {
if (isRepliedMessage && !settings.store.replies) {
From 5f53f852dc870c8a3997361fe17ef8c68fc318aa Mon Sep 17 00:00:00 2001
From: Etorix <92535668+EtorixDev@users.noreply.github.com>
Date: Thu, 26 Dec 2024 21:52:47 -0800
Subject: [PATCH 15/16] Reduce niche settings + switch to string format over
dropdown for permutations.
---
src/plugins/showMeYourName/index.tsx | 258 +++++++++------------------
1 file changed, 83 insertions(+), 175 deletions(-)
diff --git a/src/plugins/showMeYourName/index.tsx b/src/plugins/showMeYourName/index.tsx
index 91f5f0066e..294772c686 100644
--- a/src/plugins/showMeYourName/index.tsx
+++ b/src/plugins/showMeYourName/index.tsx
@@ -15,59 +15,38 @@ import { GuildMember, User } from "discord-types/general";
const StreamerModeStore = findStoreLazy("StreamerModeStore");
const colorPattern = /^#(?:[\da-f]{3}){1,2}$|^#(?:[\da-f]{4}){1,2}$|(rgb|hsl)a?\((\s*-?\d+%?\s*,){2}(\s*-?\d+%?\s*)\)|(rgb|hsl)a?\((\s*-?\d+%?\s*,){3}\s*(0|(0?\.\d+)|1)\)$/iu;
const roleColorPattern = /^role((?:\+|-)\d{0,4})?$/iu;
+const symbolPattern = /^[\p{S}\p{P}]{1,3}$/iu;
function validColor(color: string) {
- if (!color.trim()) {
- if (color.length > 0) {
- return false;
- }
- return true;
- }
+ const trimmedColor = color.trim();
+ if (!trimmedColor) return color.length > 0;
- if (color.trim().toLowerCase() === "role") {
- return true;
- } else if (color.toLowerCase().includes("role")) {
- const percentage = roleColorPattern.exec(color)?.[1] || "";
- if (isNaN(parseInt(percentage))) {
- return false;
- }
- if (parseInt(percentage) > 100 || parseInt(percentage) < -100) {
- return false;
- }
- return true;
+ if (trimmedColor.toLowerCase() === "role") return true;
+
+ if (color.toLowerCase().includes("role")) {
+ const percentage = parseInt(roleColorPattern.exec(color)?.[1] || "");
+ return !isNaN(percentage) && percentage <= 100 && percentage >= -100;
}
const colorTestDiv = document.createElement("div");
colorTestDiv.style.borderColor = color;
- const colorIsValid = colorTestDiv.style.borderColor !== "";
- const matchesRegex = colorPattern.test(color);
-
+ const isValid = colorTestDiv.style.borderColor !== "" && colorPattern.test(color);
colorTestDiv.remove();
- return matchesRegex && colorIsValid;
-}
-function validSymbols(value: string) {
- return value === "" || (value.length <= 3 && /^[\p{S}\p{P}]{1,3}$/u.test(value));
+ return isValid;
}
function resolveColor(user: User | GuildMember, savedColor: string, fallbackColor: string) {
- if (!savedColor.trim()) {
- return { color: fallbackColor };
- }
+ if (!savedColor.trim()) return { color: fallbackColor };
if (savedColor.toLowerCase().includes("role")) {
const percentageText = roleColorPattern.exec(savedColor)?.[1] || "";
- if (percentageText && isNaN(parseInt(percentageText))) {
- return { color: fallbackColor };
- }
+ if (percentageText && isNaN(parseInt(percentageText))) return { color: fallbackColor };
const percentage = percentageText ? 1 + (parseInt(percentageText) / 100) : 1;
const roleColor = (user as GuildMember)?.colorString || null;
-
- if (!roleColor) {
- return { color: fallbackColor };
- }
+ if (!roleColor) return { color: fallbackColor };
return { color: roleColor, filter: `brightness(${percentage})` };
} else {
@@ -75,6 +54,45 @@ function resolveColor(user: User | GuildMember, savedColor: string, fallbackColo
}
}
+function validTemplate(value: string) {
+ const items = value.trim().split(/\s+/);
+ if (items.length > 3 || !items.length) return false;
+
+ const invalidItems = items.some(item => !/(?:\{(nick|display|user)\})/i.test(item));
+ if (invalidItems) return false;
+
+ const affixes = parseAffixes(value);
+ if (!affixes.order.length || affixes.order.length !== items.length) return false;
+
+ return ["nick", "display", "user"].every(name => {
+ const { prefix, suffix } = affixes[name];
+ return prefix.length <= 3 && suffix.length <= 3 && (!prefix || symbolPattern.test(prefix)) && (!suffix || symbolPattern.test(suffix));
+ });
+}
+
+function parseAffixes(template: string) {
+ const affixes = {
+ order: [] as string[],
+ nick: { included: false, prefix: "", suffix: "" },
+ display: { included: false, prefix: "", suffix: "" },
+ user: { included: false, prefix: "", suffix: "" }
+ };
+
+ const types = ["nick", "display", "user"];
+
+ template.split(/\s+/).forEach(item => {
+ types.forEach(type => {
+ if (item.includes(`{${type}}`)) {
+ const [prefix, , suffix] = item.split(/(?:\{(nick|display|user)\})/i);
+ affixes.order.push(type);
+ affixes[type] = { included: true, prefix, suffix };
+ }
+ });
+ });
+
+ return affixes;
+}
+
const settings = definePluginSettings({
replies: {
type: OptionType.BOOLEAN,
@@ -103,136 +121,34 @@ const settings = definePluginSettings({
description: "If any of the names are equivalent, remove them, leaving only the unique names.",
},
includedNames: {
- type: OptionType.SELECT,
- description: "The order to display usernames, nicknames, and display names. If any do not exist for the user, they will be omitted. Regardless of your selection below, if nickname or display name are missing, the other will replace it. If both are missing, username will be used.",
- default: "nick_display_user",
- options: [
- { label: "Nickname", value: "nick" },
- { label: "Display Name", value: "display" },
- { label: "Username", value: "user" },
-
- { label: "Nickname (Username)", value: "nick_user" },
- { label: "Nickname (Display Name)", value: "nick_display" },
- { label: "Display Name (Username)", value: "display_user" },
- { label: "Display Name (Nickname)", value: "display_nick" },
- { label: "Username (Nickname)", value: "user_nick" },
- { label: "Username (Display Name)", value: "user_display" },
-
- { label: "Nickname (Username) [Display Name]", value: "nick_user_display" },
- { label: "Nickname (Display Name) [Username]", value: "nick_display_user", default: true },
- { label: "Display Name (Username) [Nickname]", value: "display_user_nick" },
- { label: "Display Name (Nickname) [Username]", value: "display_nick_user" },
- { label: "Username (Nickname) [Display Name]", value: "user_nick_display" },
- { label: "Username (Display Name) [Nickname]", value: "user_display_nick" },
- ],
- },
- nicknamePrefix: {
type: OptionType.STRING,
- description: "The symbol to use as a prefix for the nickname. Can be up to 3 non-alphanumeric characters long.",
- default: "(",
- isValid: validSymbols,
- },
- nicknameSuffix: {
- type: OptionType.STRING,
- description: "The symbol to use as a suffix for the nickname. Can be up to 3 non-alphanumeric characters long.",
- default: ")",
- isValid: validSymbols,
+ description: "The order to display usernames, nicknames, and display names. Use the following placeholders: {nick}, {display}, {user}. You can have up to three prefixes and three suffixes per name.",
+ default: "{nick} [{display}] (@{user})",
+ isValid: validTemplate,
},
nicknameColor: {
type: OptionType.STRING,
- description: "The color to use for the nickname. Accepts hex(a), rgb(a), or hsl(a) input. Leave blank for default. \"Role\" to follow the user's top role color. \"Role+-#\" to adjust the brightness by that percentage (ex: \"Role+15\")",
+ description: "The color to use for the nickname. Leave blank for default. Accepts hex(a), rgb(a), or hsl(a) input. Use \"Role\" to follow the user's top role color. Use \"Role+-#\" to adjust the brightness by that percentage (ex: \"Role+15\")",
default: "Role-25",
isValid: validColor,
},
- nicknameSymbolColor: {
- type: OptionType.STRING,
- description: "The color to use for nickname symbols. Accepts hex(a), rgb(a), or hsl(a) input. Leave blank for default. \"Role\" to follow the user's top role color. \"Role+-#\" to adjust the brightness by that percentage (ex: \"Role+15\")",
- default: "",
- isValid: validColor,
- },
- alwaysShowNicknameSymbols: {
- type: OptionType.BOOLEAN,
- description: "Show nickname prefix and suffix even if the nickname is the only name displayed, or is the first displayed.",
- default: false,
- },
- alwaysShowNicknameColor: {
- type: OptionType.BOOLEAN,
- description: "Show nickname color even if the nickname is the only name displayed, or is the first displayed.",
- default: false,
- },
- displayNamePrefix: {
- type: OptionType.STRING,
- description: "The symbol to use as a prefix for the display name. Can be up to 3 non-alphanumeric characters long.",
- default: "[",
- isValid: validSymbols,
- },
- displayNameSuffix: {
- type: OptionType.STRING,
- description: "The symbol to use as a suffix for the display name. Can be up to 3 non-alphanumeric characters long.",
- default: "]",
- isValid: validSymbols,
- },
displayNameColor: {
type: OptionType.STRING,
- description: "The color to use for the display name. Accepts hex(a), rgb(a), or hsl(a) input. Leave blank for default. \"Role\" to follow the user's top role color. \"Role+-#\" to adjust the brightness by that percentage (ex: \"Role+15\")",
+ description: "The color to use for the display name. Leave blank for default. Accepts hex(a), rgb(a), or hsl(a) input. Use \"Role\" to follow the user's top role color. Use \"Role+-#\" to adjust the brightness by that percentage (ex: \"Role+15\")",
default: "Role-25",
isValid: validColor,
},
- displayNameSymbolColor: {
- type: OptionType.STRING,
- description: "The color to use for display name symbols. Accepts hex(a), rgb(a), or hsl(a) input. Leave blank for default. \"Role\" to follow the user's top role color. \"Role+-#\" to adjust the brightness by that percentage (ex: \"Role+15\")",
- default: "",
- isValid: validColor,
- },
- alwaysShowDisplaySymbols: {
- type: OptionType.BOOLEAN,
- description: "Show display name prefix and suffix even if the display name is the only name displayed, or is the first displayed.",
- default: false,
- },
- alwaysShowDisplayColor: {
- type: OptionType.BOOLEAN,
- description: "Show display name color even if the display name is the only name displayed, or is the first displayed.",
- default: false,
- },
- usernamePrefix: {
- type: OptionType.STRING,
- description: "The symbol to use as a prefix for the username. Can be up to 3 non-alphanumeric characters long.",
- default: "(@",
- isValid: validSymbols,
- },
- usernameSuffix: {
- type: OptionType.STRING,
- description: "The symbol to use as a suffix for the username. Can be up to 3 non-alphanumeric characters long.",
- default: ")",
- isValid: validSymbols,
- },
usernameColor: {
type: OptionType.STRING,
- description: "The color to use for the username. Accepts hex(a), rgb(a), or hsl(a) input. Leave blank for default. \"Role\" to follow the user's top role color. \"Role+-#\" to adjust the brightness by that percentage (ex: \"Role+15\")",
+ description: "The color to use for the username. Leave blank for default. Accepts hex(a), rgb(a), or hsl(a) input. Use \"Role\" to follow the user's top role color. Use \"Role+-#\" to adjust the brightness by that percentage (ex: \"Role+15\")",
default: "Role-25",
isValid: validColor,
- },
- usernameSymbolColor: {
- type: OptionType.STRING,
- description: "The color to use for username symbols. Accepts hex(a), rgb(a), or hsl(a) input. Leave blank for default. \"Role\" to follow the user's top role color. \"Role+-#\" to adjust the brightness by that percentage (ex: \"Role+15\")",
- default: "",
- isValid: validColor,
- },
- alwaysShowUsernameSymbols: {
- type: OptionType.BOOLEAN,
- description: "Show username prefix and suffix even if the username is the only name displayed, or is the first displayed.",
- default: false,
- },
- alwaysShowUsernameColor: {
- type: OptionType.BOOLEAN,
- description: "Show username color even if the username is the only name displayed, or is the first displayed.",
- default: false,
}
});
export default definePlugin({
name: "ShowMeYourName",
- description: "Display any permutation of nicknames, display names, and usernames in chat. Nicknames are per-server and display names are global. You will need to hover over old messages to update them after changing any settings.",
+ description: "Display any permutation of nicknames, display names, and usernames in chat.",
authors: [Devs.Rini, Devs.TheKodeToad, Devs.Etorix, Devs.sadan],
patches: [
{
@@ -254,6 +170,8 @@ export default definePlugin({
settings,
renderUsername: ErrorBoundary.wrap((props: any) => {
+ const { replies, hideDefaultAtSign, respectStreamerMode, removeDuplicates, includedNames, nicknameColor, displayNameColor, usernameColor } = settings.use();
+
const renderType = props.className === "mention" ? "mention" : "message";
let author: any = null;
let isRepliedMessage = false;
@@ -265,7 +183,7 @@ export default definePlugin({
const mem = GuildMemberStore.getMember(channel.guild_id, props.userId) || {};
author = usr && mem ? { ...usr, ...mem } : usr || mem || null;
isRepliedMessage = false;
- mentionSymbol = settings.store.hideDefaultAtSign ? "" : "@";
+ mentionSymbol = hideDefaultAtSign ? "" : "@";
} else if (renderType === "message") {
// props.message.author only has a globalName attribute.
// props.author only has a nick attribute, but it is overwritten by the globalName if no nickname is set.
@@ -277,7 +195,7 @@ export default definePlugin({
const mem = GuildMemberStore.getMember(channel.guild_id, props.message.author.id) || {};
author = usr && mem ? { ...usr, ...mem } : usr || mem || null;
isRepliedMessage = props.isRepliedMessage;
- mentionSymbol = settings.store.hideDefaultAtSign ? "" : props.withMentionPrefix ? "@" : "";
+ mentionSymbol = hideDefaultAtSign ? "" : props.withMentionPrefix ? "@" : "";
}
if (!author) {
@@ -285,32 +203,29 @@ export default definePlugin({
}
const user = author;
- const username = StreamerModeStore.enabled && settings.store.respectStreamerMode ? user.username[0] + "..." : user.username;
- const display = StreamerModeStore.enabled && settings.store.respectStreamerMode && user.globalName?.toLowerCase() === user.username.toLowerCase() ? user.globalName[0] + "..." : user.globalName || "";
- const nick = StreamerModeStore.enabled && settings.store.respectStreamerMode && user.nick?.toLowerCase() === user.username.toLowerCase() ? user.nick[0] + "..." : user.nick || "";
+ const username = StreamerModeStore.enabled && respectStreamerMode ? user.username[0] + "..." : user.username;
+ const display = StreamerModeStore.enabled && respectStreamerMode && user.globalName?.toLowerCase() === user.username.toLowerCase() ? user.globalName[0] + "..." : user.globalName || "";
+ const nick = StreamerModeStore.enabled && respectStreamerMode && user.nick?.toLowerCase() === user.username.toLowerCase() ? user.nick[0] + "..." : user.nick || "";
try {
- if (isRepliedMessage && !settings.store.replies) {
+ if (isRepliedMessage && !replies) {
return <>{mentionSymbol}{nick || display || username}>;
}
const textMutedValue = getComputedStyle(document.documentElement)?.getPropertyValue("--text-muted")?.trim() || "#72767d";
- const { alwaysShowUsernameSymbols, alwaysShowNicknameSymbols, alwaysShowDisplaySymbols, alwaysShowUsernameColor, alwaysShowNicknameColor, alwaysShowDisplayColor } = settings.store;
- const { usernamePrefix, usernameSuffix, nicknamePrefix, nicknameSuffix, displayNamePrefix, displayNameSuffix } = settings.store;
- const usernameColor = resolveColor(user, settings.store.usernameColor.trim(), textMutedValue);
- const usernameSymbolColor = resolveColor(user, settings.store.usernameSymbolColor.trim(), textMutedValue);
- const nicknameColor = resolveColor(user, settings.store.nicknameColor.trim(), textMutedValue);
- const nicknameSymbolColor = resolveColor(user, settings.store.nicknameSymbolColor.trim(), textMutedValue);
- const displayNameColor = resolveColor(user, settings.store.displayNameColor.trim(), textMutedValue);
- const displayNameSymbolColor = resolveColor(user, settings.store.displayNameSymbolColor.trim(), textMutedValue);
+ const affixes = parseAffixes(includedNames);
+ const resolvedUsernameColor = resolveColor(user, usernameColor.trim(), textMutedValue);
+ const resolvedNicknameColor = resolveColor(user, nicknameColor.trim(), textMutedValue);
+ const resolvedDisplayNameColor = resolveColor(user, displayNameColor.trim(), textMutedValue);
+ const affixColor = { color: getComputedStyle(document.documentElement)?.getPropertyValue("--text-muted")?.trim() || "#72767d" };
const values = {
- "user": { "value": username, "prefix": usernamePrefix, "suffix": usernameSuffix, "alwaysShowSymbols": alwaysShowUsernameSymbols, "alwaysShowColor": alwaysShowUsernameColor, "color": usernameColor, "symbolColor": usernameSymbolColor },
- "display": { "value": display, "prefix": displayNamePrefix, "suffix": displayNameSuffix, "alwaysShowSymbols": alwaysShowDisplaySymbols, "alwaysShowColor": alwaysShowDisplayColor, "color": displayNameColor, "symbolColor": displayNameSymbolColor },
- "nick": { "value": nick, "prefix": nicknamePrefix, "suffix": nicknameSuffix, "alwaysShowSymbols": alwaysShowNicknameSymbols, "alwaysShowColor": alwaysShowNicknameColor, "color": nicknameColor, "symbolColor": nicknameSymbolColor }
+ "user": { "value": username, "prefix": affixes.user.prefix, "suffix": affixes.user.suffix, "color": resolvedUsernameColor },
+ "display": { "value": display, "prefix": affixes.display.prefix, "suffix": affixes.display.suffix, "color": resolvedDisplayNameColor },
+ "nick": { "value": nick, "prefix": affixes.nick.prefix, "suffix": affixes.nick.suffix, "color": resolvedNicknameColor }
};
- let order = settings.store.includedNames.split("_");
+ let { order } = affixes;
order.includes("nick") && !values.nick.value && !order.includes("display") && values.display.value ? order[order.indexOf("nick")] = "display" : null;
order.includes("display") && !values.display.value && !order.includes("user") && values.user.value ? order[order.indexOf("display")] = "user" : null;
order = order.filter((name: string) => values[name].value);
@@ -319,7 +234,7 @@ export default definePlugin({
let second = order.shift() || null;
let third = order.shift() || null;
- if (settings.store.removeDuplicates) {
+ if (removeDuplicates) {
// If third is the same as second, remove it, unless third is the username, then prioritize it.
second && third && values[third].value.toLowerCase() === values[second].value.toLowerCase() ? third === "user" ? second = null : third = null : null;
// If second is the same as first, remove it.
@@ -333,35 +248,28 @@ export default definePlugin({
{mentionSymbol && {mentionSymbol}}
{(
- {values[first].alwaysShowSymbols &&
- {values[first].prefix}}
- {values[first].alwaysShowColor &&
- {values[first].value}}
- {!values[first].alwaysShowColor &&
- {values[first].value}}
- {values[first].alwaysShowSymbols &&
- {values[first].suffix}}
+ {values[first].value}
)}
{second && (
-
+
{values[second].prefix}
{values[second].value}
-
+
{values[second].suffix}
)}
{third && (
-
+
{values[third].prefix}
{values[third].value}
-
+
{values[third].suffix}
)}
@@ -369,7 +277,7 @@ export default definePlugin({
);
} catch (e) {
console.error(e);
- return <>{mentionSymbol}{StreamerModeStore.enabled && settings.store.respectStreamerMode ? ((nick || display || username)[0] + "...") : (nick || display || username)}>;
+ return <>{mentionSymbol}{StreamerModeStore.enabled && respectStreamerMode ? ((nick || display || username)[0] + "...") : (nick || display || username)}>;
}
}, { noop: true }),
});
From 0ad98f7c5250668af8cbee4e5e1808a231736e6b Mon Sep 17 00:00:00 2001
From: Etorix <92535668+EtorixDev@users.noreply.github.com>
Date: Tue, 31 Dec 2024 13:23:19 -0800
Subject: [PATCH 16/16] Fix: Readd userOverride, present for interactions.
---
src/plugins/showMeYourName/index.tsx | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/src/plugins/showMeYourName/index.tsx b/src/plugins/showMeYourName/index.tsx
index 294772c686..1de05201c5 100644
--- a/src/plugins/showMeYourName/index.tsx
+++ b/src/plugins/showMeYourName/index.tsx
@@ -191,8 +191,9 @@ export default definePlugin({
// getMember only has a nick attribute, and it is null if no nickname is set.
// Therefore just using the author props is not enough for an accurate result and we instead need to combine the results of getUser and getMember.
const channel = ChannelStore.getChannel(props.message.channel_id) || {};
- const usr = UserStore.getUser(props.message.author.id) || {};
- const mem = GuildMemberStore.getMember(channel.guild_id, props.message.author.id) || {};
+ const athr = props.userOverride ? props.userOverride : props.message.author;
+ const usr = UserStore.getUser(athr.id) || {};
+ const mem = GuildMemberStore.getMember(channel.guild_id, athr.id) || {};
author = usr && mem ? { ...usr, ...mem } : usr || mem || null;
isRepliedMessage = props.isRepliedMessage;
mentionSymbol = hideDefaultAtSign ? "" : props.withMentionPrefix ? "@" : "";
@@ -202,10 +203,9 @@ export default definePlugin({
return <>{mentionSymbol}Unknown>;
}
- const user = author;
- const username = StreamerModeStore.enabled && respectStreamerMode ? user.username[0] + "..." : user.username;
- const display = StreamerModeStore.enabled && respectStreamerMode && user.globalName?.toLowerCase() === user.username.toLowerCase() ? user.globalName[0] + "..." : user.globalName || "";
- const nick = StreamerModeStore.enabled && respectStreamerMode && user.nick?.toLowerCase() === user.username.toLowerCase() ? user.nick[0] + "..." : user.nick || "";
+ const username = StreamerModeStore.enabled && respectStreamerMode ? author.username[0] + "..." : author.username;
+ const display = StreamerModeStore.enabled && respectStreamerMode && author.globalName?.toLowerCase() === author.username.toLowerCase() ? author.globalName[0] + "..." : author.globalName || "";
+ const nick = StreamerModeStore.enabled && respectStreamerMode && author.nick?.toLowerCase() === author.username.toLowerCase() ? author.nick[0] + "..." : author.nick || "";
try {
if (isRepliedMessage && !replies) {
@@ -214,9 +214,9 @@ export default definePlugin({
const textMutedValue = getComputedStyle(document.documentElement)?.getPropertyValue("--text-muted")?.trim() || "#72767d";
const affixes = parseAffixes(includedNames);
- const resolvedUsernameColor = resolveColor(user, usernameColor.trim(), textMutedValue);
- const resolvedNicknameColor = resolveColor(user, nicknameColor.trim(), textMutedValue);
- const resolvedDisplayNameColor = resolveColor(user, displayNameColor.trim(), textMutedValue);
+ const resolvedUsernameColor = resolveColor(author, usernameColor.trim(), textMutedValue);
+ const resolvedNicknameColor = resolveColor(author, nicknameColor.trim(), textMutedValue);
+ const resolvedDisplayNameColor = resolveColor(author, displayNameColor.trim(), textMutedValue);
const affixColor = { color: getComputedStyle(document.documentElement)?.getPropertyValue("--text-muted")?.trim() || "#72767d" };
const values = {