feat(lib): The placeholder handler is now part of the lib
This commit is contained in:
parent
d447937c1b
commit
9493cb7cd9
1 changed files with 19 additions and 0 deletions
19
src/lib/placeholder.ts
Normal file
19
src/lib/placeholder.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
import { Guild, GuildMember, User } from 'discord.js';
|
||||||
|
|
||||||
|
export function placeholder(text: string, member: GuildMember): string {
|
||||||
|
const user: User = member.user;
|
||||||
|
const guild: Guild = member.guild;
|
||||||
|
|
||||||
|
const replacements: Record<string, string> = {
|
||||||
|
'{user.mention}': user.toString(),
|
||||||
|
'{user.name}': user.username,
|
||||||
|
'{user.tag}': `${user.username}#${user.discriminator}`,
|
||||||
|
'{guild.name}': guild.name,
|
||||||
|
'{guild.count}': guild.memberCount.toString(),
|
||||||
|
};
|
||||||
|
let output: string = text;
|
||||||
|
for (const key in replacements) {
|
||||||
|
output = output.replaceAll(key, replacements[key]);
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue