mirror of
https://github.com/Vendicated/Vencord.git
synced 2025-01-10 09:56:24 +00:00
Attempt to fix all inconsistencies; DM Support
This commit is contained in:
parent
968e688c10
commit
86f16f68d7
1 changed files with 89 additions and 23 deletions
|
@ -4,20 +4,26 @@
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Vencord, a Discord client mod
|
||||||
|
* Copyright (c) 2023 rini
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
import "./styles.css";
|
import "./styles.css";
|
||||||
|
|
||||||
|
import { ChannelStore } from "@webpack/common";
|
||||||
import { definePluginSettings } from "@api/Settings";
|
import { definePluginSettings } from "@api/Settings";
|
||||||
import ErrorBoundary from "@components/ErrorBoundary";
|
import ErrorBoundary from "@components/ErrorBoundary";
|
||||||
import { Devs } from "@utils/constants";
|
import { Devs } from "@utils/constants";
|
||||||
import definePlugin, { OptionType } from "@utils/types";
|
import definePlugin, { OptionType } from "@utils/types";
|
||||||
import { Message, User } from "discord-types/general";
|
import { Message } 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({
|
||||||
|
@ -28,18 +34,27 @@ const settings = definePluginSettings({
|
||||||
{ label: "Username then nickname", value: "user-nick", default: true },
|
{ label: "Username then nickname", value: "user-nick", default: true },
|
||||||
{ label: "Nickname then username", value: "nick-user" },
|
{ label: "Nickname then username", value: "nick-user" },
|
||||||
{ label: "Username only", value: "user" },
|
{ label: "Username only", value: "user" },
|
||||||
|
{ label: "Vanilla (Nickname prioritized)", value: "nick" },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
displayNames: {
|
|
||||||
type: OptionType.BOOLEAN,
|
|
||||||
description: "Use display names in place of usernames",
|
|
||||||
default: false
|
|
||||||
},
|
|
||||||
inReplies: {
|
inReplies: {
|
||||||
type: OptionType.BOOLEAN,
|
type: OptionType.BOOLEAN,
|
||||||
default: false,
|
default: false,
|
||||||
description: "Also apply functionality to reply previews",
|
description: "Also apply functionality to reply previews",
|
||||||
},
|
},
|
||||||
|
|
||||||
|
inDirectMessages: {
|
||||||
|
type: OptionType.BOOLEAN,
|
||||||
|
default: false,
|
||||||
|
description: "Also apply functionality to direct messages",
|
||||||
|
},
|
||||||
|
|
||||||
|
inDirectGroups: {
|
||||||
|
type: OptionType.BOOLEAN,
|
||||||
|
default: false,
|
||||||
|
description: "Also apply functionality to direct messages on groups",
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export default definePlugin({
|
export default definePlugin({
|
||||||
|
@ -57,28 +72,79 @@ export default definePlugin({
|
||||||
],
|
],
|
||||||
settings,
|
settings,
|
||||||
|
|
||||||
renderUsername: ErrorBoundary.wrap(({ author, message, isRepliedMessage, withMentionPrefix, userOverride }: UsernameProps) => {
|
renderUsername: ErrorBoundary.wrap(({ author, message, isRepliedMessage, withMentionPrefix }: UsernameProps) => {
|
||||||
try {
|
try {
|
||||||
const user = userOverride ?? message.author;
|
// Discord by default will display the username unless the user has set an nickname
|
||||||
let { username } = user;
|
// The code will also do the same if certain settings are turned off
|
||||||
if (settings.store.displayNames)
|
|
||||||
username = (user as any).globalName || username;
|
|
||||||
|
|
||||||
const { nick } = author;
|
// There is no way to get the nick from the message for some reason so this had to stay
|
||||||
const prefix = withMentionPrefix ? "@" : "";
|
const nickname: string = author.nick;
|
||||||
|
|
||||||
if (isRepliedMessage && !settings.store.inReplies || username.toLowerCase() === nick.toLowerCase())
|
const userObj = message.author;
|
||||||
return <>{prefix}{nick}</>;
|
const prefix: string = withMentionPrefix ? "@" : "";
|
||||||
|
const username: string = userObj.username;
|
||||||
|
const isRedundantDoubleUsername = (username.toLowerCase() === nickname.toLowerCase());
|
||||||
|
let display_name = nickname;
|
||||||
|
|
||||||
if (settings.store.mode === "user-nick")
|
switch (settings.store.mode) {
|
||||||
return <>{prefix}{username} <span className="vc-smyn-suffix">{nick}</span></>;
|
case "user-nick":
|
||||||
|
if (!isRedundantDoubleUsername) {
|
||||||
|
display_name = <>{prefix}{username} <span className="vc-smyn-suffix">{nickname}</span></>;
|
||||||
|
}
|
||||||
|
|
||||||
if (settings.store.mode === "nick-user")
|
break;
|
||||||
return <>{prefix}{nick} <span className="vc-smyn-suffix">{username}</span></>;
|
// the <span> makes the text gray
|
||||||
|
|
||||||
return <>{prefix}{username}</>;
|
case "nick-user":
|
||||||
} catch {
|
if (!isRedundantDoubleUsername) {
|
||||||
return <>{author?.nick}</>;
|
display_name = <>{prefix}{nickname} <span className="vc-smyn-suffix">{username}</span></>;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "user":
|
||||||
|
display_name = <>{prefix}{username}</>;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "vanilla":
|
||||||
|
display_name = <>{prefix}{nickname}</>;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
const current_channel = ChannelStore.getChannel(message.channel_id);
|
||||||
|
const isDM = (current_channel.guild_id === null);
|
||||||
|
|
||||||
|
if (isDM) {
|
||||||
|
const isGroupChat = (current_channel.recipients.length > 1);
|
||||||
|
const shouldDisplayDM = !isGroupChat && settings.store.inDirectMessages;
|
||||||
|
const shouldDisplayGroup = isGroupChat && settings.store.inDirectGroups;
|
||||||
|
|
||||||
|
if (shouldDisplayDM || shouldDisplayGroup) {
|
||||||
|
if (isRepliedMessage) {
|
||||||
|
if (settings.store.inReplies) return display_name;
|
||||||
|
|
||||||
|
return nickname;
|
||||||
|
}
|
||||||
|
|
||||||
|
return display_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
return nickname;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Servers
|
||||||
|
if (isRepliedMessage) {
|
||||||
|
if (settings.store.inReplies) return display_name;
|
||||||
|
|
||||||
|
return nickname;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unless any of the functions above changed it, it will be the nickname
|
||||||
|
return display_name;
|
||||||
|
|
||||||
|
} catch (errorMsg) {
|
||||||
|
console.log(`ShowMeYourName ERROR: ${errorMsg}`);
|
||||||
|
return <>{message?.author.username}</>;
|
||||||
}
|
}
|
||||||
}, { noop: true }),
|
}, { noop: true }),
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue