ShowMeYourName: Fix username being wrong on slash commands (#1690)

Co-authored-by: V <vendicated@riseup.net>
This commit is contained in:
Cynthia Foxwell 2023-08-30 17:01:29 -06:00 committed by GitHub
parent d6efd99849
commit d88524e8cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -21,13 +21,14 @@ import "./styles.css";
import { definePluginSettings } from "@api/Settings"; import { definePluginSettings } from "@api/Settings";
import { Devs } from "@utils/constants"; import { Devs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types"; import definePlugin, { OptionType } from "@utils/types";
import { Message } from "discord-types/general"; import { Message, User } from "discord-types/general";
interface UsernameProps { interface UsernameProps {
author: { nick: string; }; author: { nick: string; };
message: Message; message: Message;
withMentionPrefix?: boolean; withMentionPrefix?: boolean;
isRepliedMessage: boolean; isRepliedMessage: boolean;
userOverride?: User;
} }
const settings = definePluginSettings({ const settings = definePluginSettings({
@ -67,11 +68,12 @@ export default definePlugin({
], ],
settings, settings,
renderUsername: ({ author, message, isRepliedMessage, withMentionPrefix }: UsernameProps) => { renderUsername: ({ author, message, isRepliedMessage, withMentionPrefix, userOverride }: UsernameProps) => {
try { try {
let { username } = message.author; const user = userOverride ?? message.author;
let { username } = user;
if (settings.store.displayNames) if (settings.store.displayNames)
username = (message.author as any).globalName || username; username = (user as any).globalName || username;
const { nick } = author; const { nick } = author;
const prefix = withMentionPrefix ? "@" : ""; const prefix = withMentionPrefix ? "@" : "";