fix locale command

This commit is contained in:
Lio Young 2021-07-10 20:59:18 +02:00
parent a43cffa708
commit 21673301d9
2 changed files with 26 additions and 11 deletions

View File

@ -2,9 +2,12 @@
import Command from '../../handler/structures/Command';
import { Context, Server } from '../../utils/types';
import database from "../../utils/database"
import lingua from '../../utils/lingua';
import path from 'path'
import langs from '../../utils/language';
import { MessageEmbed } from 'discord.js';
import replace from '../../utils/replace';
import fs from 'fs'
import path from 'path'
function enabled(a: boolean, lang: string) {
// @ts-ignore
@ -14,6 +17,18 @@ function user(ctx: Context, id: string) {
let x = ctx.client.users.cache.get(id)
return x
}
function listFiles(dir: string) {
let files = fs.readdirSync(dir)
let list = []
for (let i = 0; i < files.length; i++) {
let name = path.join(dir, files[i])
let isDirectory = fs.statSync(name).isDirectory()
list.push({ name, isDirectory })
}
return list
}
export = class Locale extends Command {
constructor() {
super({
@ -28,29 +43,29 @@ export = class Locale extends Command {
let sub = ctx.args[0]
ctx.args.shift()
let language = ctx.settings.locale
let validLangs = Object.entries(lingua).map(([key, value]) => (key))
let validLangs = langs.langs()
const Embed = new MessageEmbed().setColor(ctx.config.variables.color).setFooter(`${ctx.config.variables.name}`, ctx.config.variables.avatar)
switch (sub) {
case "list": {
let langs = Object.entries(lingua).map(([key, value]) => (`${replace(/LANGUAGE/gi, `**${value.META.name} (${value.META.locale})**`, replace(/TRANSLATOR/gi, `**${user(ctx, value.META.tranlators[0]).tag}**`, lingua[language].LOCALE.TITLE))}\n${replace(/AMOUNT/gi, value.META.tranlators.length, lingua[language].LOCALE.CONTRIBUTORS)}\n\`${ctx.config.variables.prefix[0]} locale set ${value.META.locale}\``))
let topdesc = replace(/BOT/gi, ctx.config.variables.name, replace(/AMOUNT/gi, langs.length, replace(/PREFIX/gi, ctx.config.variables.prefix[0], lingua[language].LOCALE.COMMAND_DESC)))
Embed.setTitle(lingua[language].LOCALE.DEFAULT.LANGUAGES).setDescription(`${topdesc}\n\n${langs.join(`\n\n`)}`)
let alllangs = langs.langs().map(x => (`${replace(/LANGUAGE/gi, `**${langs.get(x).meta.name} (${langs.get(x).meta.locale})**`, replace(/TRANSLATOR/gi, `**${user(ctx, langs.get(language).meta.translators[0]).tag}**`, `${langs.get(language).locale.title}`))}\n${replace(/AMOUNT/gi, langs.get(x).meta.translators.length, langs.get(x).locale.translators)}\n\`${ctx.config.variables.prefix[0]} locale set ${langs.get(x).meta.locale}\``))
let topdesc = replace(/BOT/gi, ctx.config.variables.name, replace(/AMOUNT/gi, validLangs.length, replace(/PREFIX/gi, ctx.config.variables.prefix[0], langs.get(language).locale.amount)))
Embed.setTitle(langs.get(language).locale.language).setDescription(`${topdesc}\n\n${alllangs.join(`\n\n`)}`)
return ctx.channel.send(Embed)
}
case "set": {
console.log(validLangs)
if (ctx.args === [] || ctx.args.join(' ').trim() === '') return ctx.channel.send(lingua[language].MISSING.VALUE.COUNTRY);
if (!validLangs.includes(ctx.args[0])) return ctx.channel.send(replace(/BOT/gi, ctx.config.variables.name, replace(/VALUE/gi, ctx.args.join(" "), lingua[language].LOCALE.UNSUPPORTED)))
if (ctx.args === [] || ctx.args.join(' ').trim() === '') return ctx.channel.send(langs.get(language).missing.values.country);
if (!validLangs.includes(ctx.args[0])) return ctx.channel.send(replace(/BOT/gi, ctx.config.variables.name, replace(/VALUE/gi, ctx.args.join(" "), langs.get(language).locale.unsupported)))
let { data, error } = await database.from<Server>('servers').update({ locale: ctx.args[0] }).match({ server_id: ctx.guild?.id })
if (error) throw new Error(error)
Embed.setTitle(replace(/SETTING/gi, lingua[ctx.args[0]].LOCALE.DEFAULT.LANGUAGE, replace(/VALUE/gi, ctx.args[0], lingua[ctx.args[0]].LOCALE.UPDATED_SETTING)))
Embed.setTitle(replace(/SETTING/gi, lingua[ctx.args[0]].LOCALE.DEFAULT.LANGUAGE, replace(/VALUE/gi, ctx.args[0], langs.get(language).locale.updated)))
return ctx.channel.send(Embed)
}
default: {
Embed.setTitle(lingua[language].LOCALE.DEFAULT.LOCALIZATION)
Embed.setTitle(langs.get(language).locale.language)
.setDescription(
`**${lingua[language].LOCALE.DEFAULT.CURRENT}**\n\`${language}\`\n\n${replace(/PREFIX/gi, ctx.config.variables.prefix[0], lingua[language].LOCALE.DEFAULT.SUB)}`
`**${langs.get(language).locale.current}**\n\`${language}\`\n\n${replace(/PREFIX/gi, ctx.config.variables.prefix[0], langs.get(language).locale.sub)}`
)
return ctx.channel.send(Embed)
}

@ -1 +1 @@
Subproject commit eb4dea0bf641938fbe2939ab6fb529915957fe17
Subproject commit a44f30e0f6601f58d06c56baaffc8d4b484c6a30