Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 1 | async function convertCurlyBracketString( |
| 2 | str, |
| 3 | memberID, |
| 4 | memberName, |
| 5 | serverName, |
| 6 | members |
| 7 | ): Promise<string> { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 8 | const memberCount = (await members.fetch()).size; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 9 | const bots = (await members.fetch()).filter((m) => m.user.bot).size; |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 10 | str = str |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 11 | .replace( |
| 12 | "{member:mention}", |
| 13 | memberID ? `<@${memberID}>` : "{member:mention}" |
| 14 | ) |
| 15 | .replace( |
| 16 | "{member:name}", |
| 17 | memberName ? `${memberName}` : "{member:name}" |
| 18 | ) |
pineafan | 02ba023 | 2022-07-24 22:16:15 +0100 | [diff] [blame] | 19 | .replace("{serverName}", serverName ? `${serverName}` : "{serverName}") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 20 | .replace( |
| 21 | "{memberCount}", |
| 22 | memberCount ? `${memberCount}` : "{memberCount}" |
| 23 | ) |
pineafan | 02ba023 | 2022-07-24 22:16:15 +0100 | [diff] [blame] | 24 | .replace("{memberCount:bots}", bots ? `${bots}` : "{memberCount:bots}") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 25 | .replace( |
| 26 | "{memberCount:humans}", |
| 27 | memberCount && bots |
| 28 | ? `${memberCount - bots}` |
| 29 | : "{memberCount:humans}" |
| 30 | ); |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 31 | |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 32 | return str; |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 33 | } |
| 34 | |
pineafan | c6158ab | 2022-06-17 16:34:07 +0100 | [diff] [blame] | 35 | export default convertCurlyBracketString; |