From 16a3e1f0d9c1db57539a9ee06c2e3f990f2cf03e Mon Sep 17 00:00:00 2001 From: toast-ts <96593068+toast-ts@users.noreply.github.com> Date: Mon, 8 Apr 2024 17:24:18 +1000 Subject: [PATCH] Add PluralRules to the `/mp pallets` command --- src/commands/mp.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/commands/mp.ts b/src/commands/mp.ts index b0ee97c..a388c9e 100644 --- a/src/commands/mp.ts +++ b/src/commands/mp.ts @@ -95,18 +95,24 @@ export default class MP { DSS.server ? await interaction.reply({embeds: [new client.embed().setColor(client.config.embedColor).addFields( {name: 'Name', value: DSS.server?.name?.length < 1 ? '*`Offline`*' : `\`${DSS?.server?.name}\``}, {name: 'Players', value: `${DSS?.slots.used}/${DSS?.slots.capacity}`}, - {name: 'Map', value: DSS?.server.mapName} + {name: 'Map', value: DSS?.server.mapName ?? 'Unavailable'} ).setFooter({text: `Version: ${DSS?.server?.version} | Time: ${`${('0'+Math.floor((DSS?.server.dayTime/3600/1000))).slice(-2)}:${('0'+Math.floor((DSS?.server.dayTime/60/1000)%60)).slice(-2)}`}`})]}) : null }, pallets: async()=>{ const DSS = await fetchData(client, interaction, choiceSelector) as FSData; if (!DSS) return console.log('Endpoint failed - pallets'); const filter = DSS?.vehicles.filter(x=>x.category === 'PALLETS'); + const rules = { + one: 'single pallet', + two: 'pallets', + few: 'pallets', + other: 'pallets' + }[new Intl.PluralRules('en', {type: 'ordinal'}).select(filter.length)]; if (filter.length < 1) return interaction.reply('No pallets found on the server.'); else { const getLongestName = Object.entries(PalletLibrary(DSS)).map(([name, _])=>name.length).sort((a,b)=>b-a)[0]; await interaction.reply(MessageTool.concatMessage( - `There are currently **${filter.length}** pallets on the server. Here\'s the breakdown:\`\`\`ansi`, + `There are currently **${filter.length}** ${rules} on the server. Here\'s the breakdown:\`\`\`ansi`, Object.entries(PalletLibrary(DSS)).map(([name, count])=>`${ansi.blue(name.padEnd(getLongestName+3))}${ansi.yellow(count.toString())}`).join('\n'), '```' ))