blob: 5d2c23d8edfd3bd5b7afc3dfe4927b363136f452 [file] [log] [blame]
pineafan3a02ea32022-08-11 21:35:04 +01001import type { GuildMember, GuildMemberManager } from "discord.js";
2
3async function convertCurlyBracketString(
4 str: string,
5 memberID: string,
6 memberName: string,
7 serverName: string,
8 members: GuildMemberManager
9): Promise<string> {
pineafan63fc5e22022-08-04 22:04:10 +010010 const memberCount = (await members.fetch()).size;
pineafan3a02ea32022-08-11 21:35:04 +010011 const bots = (await members.fetch()).filter((m: GuildMember) => m.user.bot).size;
pineafan32767212022-03-14 21:27:39 +000012 str = str
Skyler Grey11236ba2022-08-08 21:13:33 +010013 .replace("{member:mention}", memberID ? `<@${memberID}>` : "{member:mention}")
14 .replace("{member:name}", memberName ? `${memberName}` : "{member:name}")
pineafan02ba0232022-07-24 22:16:15 +010015 .replace("{serverName}", serverName ? `${serverName}` : "{serverName}")
Skyler Grey11236ba2022-08-08 21:13:33 +010016 .replace("{memberCount}", memberCount ? `${memberCount}` : "{memberCount}")
pineafan02ba0232022-07-24 22:16:15 +010017 .replace("{memberCount:bots}", bots ? `${bots}` : "{memberCount:bots}")
Skyler Grey11236ba2022-08-08 21:13:33 +010018 .replace("{memberCount:humans}", memberCount && bots ? `${memberCount - bots}` : "{memberCount:humans}");
pineafan32767212022-03-14 21:27:39 +000019
pineafan63fc5e22022-08-04 22:04:10 +010020 return str;
pineafan32767212022-03-14 21:27:39 +000021}
22
pineafanc6158ab2022-06-17 16:34:07 +010023export default convertCurlyBracketString;