Skip to content
This repository was archived by the owner on Nov 22, 2023. It is now read-only.

Commit 87b624d

Browse files
authored
feat(language): sort names alphabetically (#815)
* feat(language): sort names alphabetically * fix: use `HTBClient#getUser`
1 parent 0418340 commit 87b624d

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

src/commands/Utility/language.ts

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { access, constants, readdir } from "node:fs"
33
import { type GuildMember, EmbedBuilder, ApplicationCommandOptionType } from "discord.js"
44

55
import { colors, ids } from "../../config.json"
6+
import { client } from "../../index"
67
import { db, type DbUser } from "../../lib/dbclient"
78
import { generateTip, type MongoLanguage, transformDiscordLocale, botLocales } from "../../lib/util"
89

@@ -63,24 +64,22 @@ const command: Command = {
6364
let language = interaction.options.getString("language", ["set", "stats"].includes(subCommand))
6465

6566
if (subCommand === "list") {
66-
const langList: string[] = [],
67-
authorLanguage = (await collection.findOne({ id: interaction.user.id }))!.lang ?? transformDiscordLocale(interaction.locale)
68-
botLocales.forEach(async (element, index, array) => {
69-
if (element === "empty" && !member?.roles.cache.has(ids.roles.admin)) return
70-
let languageString: string
71-
if (element === "empty") languageString = "Empty"
72-
else languageString = getString(element)
73-
langList.push(authorLanguage === element ? `**${languageString}**` : languageString)
74-
if (index === array.length - 1) {
75-
const embed = new EmbedBuilder({
76-
color: colors.neutral,
77-
author: { name: getString("moduleName") },
78-
title: getString("listTitle"),
79-
description: langList.join(", "),
67+
const authorLanguage = (await client.getUser(interaction.user.id)).lang ?? transformDiscordLocale(interaction.locale),
68+
langList = botLocales
69+
.map<string | null>(locale => {
70+
if (locale === "empty" && !member?.roles.cache.has(ids.roles.admin)) return null
71+
const languageString = locale === "empty" ? "Empty" : getString(locale)
72+
return authorLanguage === locale ? `**${languageString}**` : languageString
8073
})
81-
await interaction.reply({ embeds: [embed] })
82-
}
83-
})
74+
.filter((value): value is string => Boolean(value))
75+
.sort((a, b) => a.replaceAll("**", "").localeCompare(b.replaceAll("**", ""), authorLanguage.replace("_", "-"))),
76+
embed = new EmbedBuilder({
77+
color: colors.neutral,
78+
author: { name: getString("moduleName") },
79+
title: getString("listTitle"),
80+
description: langList.join(", "),
81+
})
82+
await interaction.reply({ embeds: [embed] })
8483
} else if (subCommand === "stats") {
8584
if (!member?.roles.cache.has(ids.roles.admin))
8685
return void (await interaction.reply({ content: getString("errors.noAccess", { file: "global" }), ephemeral: true }))

0 commit comments

Comments
 (0)