From 6ae3063a7a5b2ba91fb204b1fd88b1c44d93f8c1 Mon Sep 17 00:00:00 2001 From: Androz2091 Date: Thu, 17 Dec 2020 09:13:51 +0100 Subject: [PATCH] :bug: Use json file to store languages metadata --- base/Atlanta.js | 7 +- base/Guild.js | 5 +- commands/Administration/setfortniteshop.js | 2 +- commands/General/fortniteshop.js | 2 +- config.sample.js | 137 --------------------- dashboard/routes/guild-manager.js | 2 +- dashboard/views/manager/guild.ejs | 2 +- helpers/fortniteShop.js | 2 +- languages/language-meta.json | 136 ++++++++++++++++++++ 9 files changed, 148 insertions(+), 147 deletions(-) create mode 100644 languages/language-meta.json diff --git a/base/Atlanta.js b/base/Atlanta.js index e500ad3b8f..17a1c3acde 100644 --- a/base/Atlanta.js +++ b/base/Atlanta.js @@ -23,6 +23,7 @@ class Atlanta extends Client { super(options); this.config = require("../config"); // Load the config file this.customEmojis = require("../emojis.json"); // load the bot's emojis + this.languages = require("../languages/language-meta.json"); // Load the bot's languages this.commands = new Collection(); // Creates new commands collection this.aliases = new Collection(); // Creates new command aliases collection this.logger = require("../helpers/logger"); // Load the logger file @@ -138,7 +139,7 @@ class Atlanta extends Client { } get defaultLanguage(){ - return this.config.languages.find((language) => language.default).name; + return this.languages.find((language) => language.default).name; } translate(key, args, locale){ @@ -150,7 +151,7 @@ class Atlanta extends Client { printDate(date, format, locale){ if(!locale) locale = this.defaultLanguage; - const languageData = this.config.languages.find((language) => language.name === locale || language.aliases.includes(locale)); + const languageData = this.languages.find((language) => language.name === locale || language.aliases.includes(locale)); if(!format) format = languageData.defaultMomentFormat; return moment(new Date(date)) .locale(languageData.moment) @@ -160,7 +161,7 @@ class Atlanta extends Client { convertTime(time, type, noPrefix, locale){ if(!type) time = "to"; if(!locale) locale = this.defaultLanguage; - const languageData = this.config.languages.find((language) => language.name === locale || language.aliases.includes(locale)); + const languageData = this.languages.find((language) => language.name === locale || language.aliases.includes(locale)); const m = moment(time) .locale(languageData.moment); return (type === "to" ? m.toNow(noPrefix) : m.fromNow(noPrefix)); diff --git a/base/Guild.js b/base/Guild.js index 9e479e1332..9fd3e370fa 100644 --- a/base/Guild.js +++ b/base/Guild.js @@ -1,6 +1,7 @@ const mongoose = require("mongoose"), Schema = mongoose.Schema, - config = require("../config.js"); + config = require("../config.js"), + languages = require("../languages/language-meta.json"); module.exports = mongoose.model("Guild", new Schema({ @@ -12,7 +13,7 @@ module.exports = mongoose.model("Guild", new Schema({ members: [{ type: Schema.Types.ObjectId, ref: "Member" }], /* CONFIGURATION */ - language: { type: String, default: config.languages.find((l) => l.default).name }, // Language of the guild + language: { type: String, default: languages.find((l) => l.default).name }, // Language of the guild prefix: { type: String, default: config.prefix }, // Default or custom prefix of the guild plugins: { type: Object, default: { // Plugins data // Welcome messages diff --git a/commands/Administration/setfortniteshop.js b/commands/Administration/setfortniteshop.js index 5478f9f995..2ce6101d73 100644 --- a/commands/Administration/setfortniteshop.js +++ b/commands/Administration/setfortniteshop.js @@ -41,7 +41,7 @@ class Setfortniteshop extends Command { channel: channel.toString() }); - const momentName = data.config.languages.find((language) => language.name === data.guild.language || language.aliases.includes(data.guild.language)).moment; + const momentName = this.client.languages.find((language) => language.name === data.guild.language || language.aliases.includes(data.guild.language)).moment; const shop = new Canvas.FortniteShop(); const image = await shop .setToken(data.config.apiKeys.fortniteFNBR) diff --git a/commands/General/fortniteshop.js b/commands/General/fortniteshop.js index bf1ff27baf..a363990102 100644 --- a/commands/General/fortniteshop.js +++ b/commands/General/fortniteshop.js @@ -28,7 +28,7 @@ class Fortniteshop extends Command { prefixEmoji: "loading" }); - const momentName = data.config.languages.find((language) => language.name === data.guild.language || language.aliases.includes(data.guild.language)).moment; + const momentName = this.client.languages.find((language) => language.name === data.guild.language || language.aliases.includes(data.guild.language)).moment; const shop = new Canvas.FortniteShop(); const image = await shop .setToken(data.config.apiKeys.fortniteFNBR) diff --git a/config.sample.js b/config.sample.js index 9ce39ae64f..1e8b2040b4 100644 --- a/config.sample.js +++ b/config.sample.js @@ -64,142 +64,5 @@ module.exports = { name: "my website : atlanta-bot.fr", type: "PLAYING" } - ], - /* Language configuration */ - languages: [ - { - name: "en-US", - nativeName: "English", - moment: "en", - defaultMomentFormat: "MMMM Do YYYY", - default: true, - aliases: [ - "English", - "en", - "en-us", - "en_us", - "en_US" - ] - }, - { - name: "fr-FR", - nativeName: "Français", - defaultMomentFormat: "Do MMMM YYYY", - moment: "fr", - default: false, - aliases: [ - "French", - "français", - "francais", - "fr", - "fr_fr" - ] - }, - { - name: "es-ES", - nativeName: "Español", - defaultMomentFormat: "MMM Do, YYYY", - moment: "es", - default: false, - aliases: [ - "Spanish", - "es", - "es_es" - ] - }, - { - name: "it-IT", - nativeName: "Italiano", - defaultMomentFormat: "Do MMMM YYYY", - moment: "it", - default: false, - aliases: [ - "Italian", - "it", - "it_it" - ] - }, - { - name: "nl-NL", - nativeName: "Nederlands", - defaultMomentFormat: "Do MMMM YYYY", - moment: "nl", - default: false, - aliases: [ - "Dutch", - "nl", - "nl_nl" - ] - }, - { - name: "pt-PT", - nativeName: "Português", - defaultMomentFormat: "Do MMMM YYYY", - moment: "pt", - default: false, - aliases: [ - "Portuguese", - "pt", - "pt_pt" - ] - }, - { - name: "tr-TR", - nativeName: "Türk", - defaultMomentFormat: "Do MMMM YYYY", - moment: "tr", - default: false, - aliases: [ - "Turkish", - "tr", - "tr_tr" - ] - }, - { - name: "id-ID", - nativeName: "bahasa Indonesia", - defaultMomentFormat: "Do MMMM YYYY", - moment: "id", - default: false, - aliases: [ - "Indonesian", - "id", - "id_id" - ] - }, - { - name: "ro-RO", - nativeName: "Română", - moment: "ro", - default: false, - aliases: [ - "Romanian", - "ro", - "ro_ro" - ] - }, - { - name: "tr-TR", - nativeName: "Türk", - moment: "tr", - default: false, - aliases: [ - "Turkish", - "Turk", - "tr", - "tr_tr" - ] - }, - { - name: "nl-NL", - nativeName: "NEDERLAND", - moment: "nl", - default: false, - aliases: [ - "Netherland", - "nl", - "nl_nl" - ] - } ] }; diff --git a/dashboard/routes/guild-manager.js b/dashboard/routes/guild-manager.js index 988010334f..5e7f018ae1 100644 --- a/dashboard/routes/guild-manager.js +++ b/dashboard/routes/guild-manager.js @@ -44,7 +44,7 @@ router.post("/:serverID", CheckAuth, async(req, res) => { const data = req.body; if(data.language){ - const language = req.client.config.languages.find((language) => language.aliases[0].toLowerCase() === data.language.toLowerCase()); + const language = req.client.languages.find((language) => language.aliases[0].toLowerCase() === data.language.toLowerCase()); if(language){ guildData.language = language.name; } diff --git a/dashboard/views/manager/guild.ejs b/dashboard/views/manager/guild.ejs index dbcf58e0c9..ed65219d7b 100644 --- a/dashboard/views/manager/guild.ejs +++ b/dashboard/views/manager/guild.ejs @@ -67,7 +67,7 @@