@@ -3,6 +3,7 @@ import { access, constants, readdir } from "node:fs"
3
3
import { type GuildMember , EmbedBuilder , ApplicationCommandOptionType } from "discord.js"
4
4
5
5
import { colors , ids } from "../../config.json"
6
+ import { client } from "../../index"
6
7
import { db , type DbUser } from "../../lib/dbclient"
7
8
import { generateTip , type MongoLanguage , transformDiscordLocale , botLocales } from "../../lib/util"
8
9
@@ -63,24 +64,22 @@ const command: Command = {
63
64
let language = interaction . options . getString ( "language" , [ "set" , "stats" ] . includes ( subCommand ) )
64
65
65
66
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
80
73
} )
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 ] } )
84
83
} else if ( subCommand === "stats" ) {
85
84
if ( ! member ?. roles . cache . has ( ids . roles . admin ) )
86
85
return void ( await interaction . reply ( { content : getString ( "errors.noAccess" , { file : "global" } ) , ephemeral : true } ) )
0 commit comments