pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 1 | import type { GuildMember, GuildMemberManager } from "discord.js"; |
| 2 | |
| 3 | async function convertCurlyBracketString( |
| 4 | str: string, |
| 5 | memberID: string, |
| 6 | memberName: string, |
| 7 | serverName: string, |
| 8 | members: GuildMemberManager |
| 9 | ): Promise<string> { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 10 | const memberCount = (await members.fetch()).size; |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 11 | const bots = (await members.fetch()).filter((m: GuildMember) => m.user.bot).size; |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 12 | str = str |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 13 | .replace("{member:mention}", memberID ? `<@${memberID}>` : "{member:mention}") |
| 14 | .replace("{member:name}", memberName ? `${memberName}` : "{member:name}") |
pineafan | 02ba023 | 2022-07-24 22:16:15 +0100 | [diff] [blame] | 15 | .replace("{serverName}", serverName ? `${serverName}` : "{serverName}") |
Samuel Shuert | 27bf3cd | 2023-03-03 15:51:25 -0500 | [diff] [blame] | 16 | .replace("{memberCount:all}", memberCount ? `${memberCount}` : "{memberCount}") |
pineafan | 02ba023 | 2022-07-24 22:16:15 +0100 | [diff] [blame] | 17 | .replace("{memberCount:bots}", bots ? `${bots}` : "{memberCount:bots}") |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 18 | .replace("{memberCount:humans}", memberCount && bots ? `${memberCount - bots}` : "{memberCount:humans}"); |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 19 | |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 20 | return str; |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 21 | } |
| 22 | |
pineafan | c6158ab | 2022-06-17 16:34:07 +0100 | [diff] [blame] | 23 | export default convertCurlyBracketString; |