Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
refact0r committed Apr 3, 2024
1 parent 650f405 commit fb212d1
Showing 1 changed file with 49 additions and 2 deletions.
51 changes: 49 additions & 2 deletions src/plugins/showMeYourName/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ import { Message, User } from "discord-types/general";

interface UsernameProps {
author: { nick: string; };
message: Message;
message?: Message;
withMentionPrefix?: boolean;
isRepliedMessage: boolean;
userOverride?: User;
}

interface NickUser extends User {
nick: string;
}

const settings = definePluginSettings({
mode: {
type: OptionType.SELECT,
Expand Down Expand Up @@ -53,12 +57,29 @@ export default definePlugin({
replace: "$self.renderUsername(arguments[0])}"
}
},
// Keep the user object and nick when creating the list of typing users
{
find: "getCooldownTextStyle",
replacement: {
match: /\.map\((\i)=>(\i)\.(\i)\.getName\((\i),this\.props\.channel\.id,(\i)\)\)/,
replace: ".map($1 => { let user = $1; user.nick = $2.$3.getName($4, this.props.channel.id, $5); return user; })"
}
},
// Style the indicator and add function call to modify the children before rendering
{
find: "getCooldownTextStyle",
replacement: {
match: /(?<=children:\[(\i)\.length>0.{0,200}?"aria-atomic":!0,children:)\i/,
replace: "$self.renderTypingNames(this.props, $1, $&)"
}
},
],
settings,

renderUsername: ({ author, message, isRepliedMessage, withMentionPrefix, userOverride }: UsernameProps) => {
try {
const user = userOverride ?? message.author;
const user = userOverride ?? message?.author;
if (!user) return author?.nick;
let { username } = user;
if (settings.store.displayNames)
username = (user as any).globalName || username;
Expand All @@ -76,4 +97,30 @@ export default definePlugin({
return author?.nick;
}
},

renderTypingNames(props: any, users: NickUser[], children: any) {
if (!Array.isArray(children)) return children;

let index = 0;

console.log("children", children);
console.log("props", props);
console.log("users", users);

return children.map(c => {
if (c.type === "strong") {
const user = users[index++];
console.log("user", user);
if (!user) return c;
return <><strong>{this.renderUsername({
author: { nick: user.nick },
message: undefined,
isRepliedMessage: false,
withMentionPrefix: false,
userOverride: user
})}</strong></>;
}
return c;
});
},
});

0 comments on commit fb212d1

Please sign in to comment.