Update i18n (and fix commands)

This commit is contained in:
Isaac
2021-04-27 11:34:34 +01:00
parent 0991a48d3d
commit fba2b579fb
10 changed files with 31 additions and 21 deletions

View File

@@ -3,7 +3,7 @@ const Command = require('../modules/commands/command');
module.exports = class BlacklistCommand extends Command {
constructor(client) {
const i18n = client.i18n.get(client.config.locale);
const i18n = client.i18n.getLocale(client.config.locale);
super(client, {
internal: true,
name: i18n('commands.blacklist.name'),
@@ -27,7 +27,7 @@ module.exports = class BlacklistCommand extends Command {
async execute(message, args) {
let settings = await message.guild.settings;
const i18n = this.client.i18n.get(settings.locale);
const i18n = this.client.i18n.getLocale(settings.locale);
let member = message.mentions.members.first();

View File

@@ -4,7 +4,7 @@ const { footer } = require('../utils/discord');
module.exports = class CloseCommand extends Command {
constructor(client) {
const i18n = client.i18n.get(client.config.locale);
const i18n = client.i18n.getLocale(client.config.locale);
super(client, {
internal: true,
name: i18n('commands.close.name'),
@@ -27,7 +27,7 @@ module.exports = class CloseCommand extends Command {
async execute(message, args) {
let settings = await message.guild.settings;
const i18n = this.client.i18n.get(settings.locale);
const i18n = this.client.i18n.getLocale(settings.locale);
}
};

View File

@@ -6,7 +6,7 @@ const { wait } = require('../utils');
module.exports = class NewCommand extends Command {
constructor(client) {
const i18n = client.i18n.get(client.config.locale);
const i18n = client.i18n.getLocale(client.config.locale);
super(client, {
internal: true,
name: i18n('commands.new.name'),
@@ -30,7 +30,7 @@ module.exports = class NewCommand extends Command {
async execute(message, args) {
let settings = await message.guild.settings;
const i18n = this.client.i18n.get(settings.locale);
const i18n = this.client.i18n.getLocale(settings.locale);
const editOrSend = async (msg, content) => {
if (msg) return await msg.edit(content);

View File

@@ -4,7 +4,7 @@ const { MessageAttachment } = require('discord.js');
module.exports = class SettingsCommand extends Command {
constructor(client) {
const i18n = client.i18n.get(client.config.locale);
const i18n = client.i18n.getLocale(client.config.locale);
super(client, {
internal: true,
name: i18n('commands.settings.name'),
@@ -19,7 +19,7 @@ module.exports = class SettingsCommand extends Command {
async execute(message) {
let settings = await message.guild.settings;
const i18n = this.client.i18n.get(settings.locale);
const i18n = this.client.i18n.getLocale(settings.locale);
let attachments = [ ...message.attachments.values() ];

View File

@@ -130,8 +130,19 @@ class Bot extends Client {
/** A [Cryptr](https://www.npmjs.com/package/cryptr) instance */
this.cryptr = new Cryptr(process.env.DB_ENCRYPTION_KEY);
let locales = {};
fs.readdirSync(path('./src/locales'))
.filter(file => file.endsWith('.json'))
.forEach(file => {
let data = fs.readFileSync(path(`./src/locales/${file}`), {
encoding: 'utf8'
});
let name = file.slice(0, file.length - 5);
locales[name] = JSON.parse(data);
});
/** An [@eartharoid/i18n](https://github.com/eartharoid/i18n) instance */
this.i18n = new I18n(path('./src/locales'), 'en-GB');
this.i18n = new I18n('en-GB', locales);
/** A sequelize instance */
this.db = await require('./database')(this), // this.db.models.Ticket...

View File

@@ -128,7 +128,7 @@ module.exports = class Command {
if (!cmd_name) cmd_name = this.name;
const prefix = settings.command_prefix;
const i18n = this.client.i18n.get(settings.locale);
const i18n = this.client.i18n.getLocale(settings.locale);
const addArgs = (embed, arg) => {
let required = arg.required ? '`❗` ' : '';

View File

@@ -61,6 +61,9 @@ module.exports = class CommandManager {
* @param {Message} message - Command message
*/
async handle(message) {
let settings = await message.guild.settings;
const i18n = this.client.i18n.getLocale(settings.locale);
let is_blacklisted = false;
if (settings.blacklist.includes(message.author.id)) {
is_blacklisted = true;
@@ -82,10 +85,6 @@ module.exports = class CommandManager {
}
}
let settings = await message.guild.settings;
const i18n = this.client.i18n.get(settings.locale);
const prefix = settings.command_prefix;
const escaped_prefix = prefix.toLowerCase().replace(/(?=\W)/g, '\\'); // (lazy) escape every character so it can be used in a RexExp
const client_mention = `<@!?${this.client.user.id}>`;

View File

@@ -30,7 +30,7 @@ module.exports = class TicketManager extends EventEmitter {
let guild = this.client.guilds.cache.get(cat_row.guild);
let settings = await guild.settings;
const i18n = this.client.i18n.get(settings.locale);
const i18n = this.client.i18n.getLocale(settings.locale);
let member = guild.members.cache.get(t_row.creator);
let t_channel = this.client.channels.cache.get(t_row.id);
@@ -218,7 +218,7 @@ module.exports = class TicketManager extends EventEmitter {
let guild = this.client.guilds.cache.get(t_row.guild);
let settings = await guild.settings;
const i18n = this.client.i18n.get(settings.locale);
const i18n = this.client.i18n.getLocale(settings.locale);
let channel = await this.client.channels.fetch(t_row.channel);
if (closer_id) {