diff --git a/package.json b/package.json index 86575ea..8443ed0 100644 --- a/package.json +++ b/package.json @@ -37,9 +37,9 @@ "@discord-tickets/settings": "^1.1.5", "@eartharoid/dbf": "^0.3.3", "@eartharoid/dtf": "^2.0.1", - "@eartharoid/i18n": "^1.1.0", + "@eartharoid/i18n": "^1.2.1", "@fastify/cookie": "^6.0.0", - "@fastify/cors": "^8.1.0", + "@fastify/cors": "^8.1.1", "@fastify/http-proxy": "^8.2.3", "@fastify/jwt": "^5.0.1", "@fastify/oauth2": "^5.1.0", @@ -67,7 +67,7 @@ }, "devDependencies": { "all-contributors-cli": "^6.24.0", - "eslint": "^8.25.0", + "eslint": "^8.26.0", "eslint-plugin-unused-imports": "^2.0.0", "nodemon": "^2.0.20" }, diff --git a/src/commands/slash/add.js b/src/commands/slash/add.js index ccd3894..73bd32d 100644 --- a/src/commands/slash/add.js +++ b/src/commands/slash/add.js @@ -3,48 +3,32 @@ const { ApplicationCommandOptionType } = require('discord.js'); module.exports = class AddSlashCommand extends SlashCommand { constructor(client, options) { - const descriptionLocalizations = {}; - client.i18n.locales.forEach(l => (descriptionLocalizations[l] = client.i18n.getMessage(l, 'commands.slash.add.description'))); - - const nameLocalizations = {}; - client.i18n.locales.forEach(l => (nameLocalizations[l] = client.i18n.getMessage(l, 'commands.slash.add.name'))); - - let opts = [ - { - name: 'member', - required: true, - type: ApplicationCommandOptionType.User, - }, - { - autocomplete: true, - name: 'ticket', - required: false, - type: ApplicationCommandOptionType.String, - }, - ]; - opts = opts.map(o => { - const descriptionLocalizations = {}; - client.i18n.locales.forEach(l => (descriptionLocalizations[l] = client.i18n.getMessage(l, `commands.slash.add.options.${o.name}.description`))); - - const nameLocalizations = {}; - client.i18n.locales.forEach(l => (nameLocalizations[l] = client.i18n.getMessage(l, `commands.slash.add.options.${o.name}.name`))); - - return { - ...o, - description: descriptionLocalizations['en-GB'], - descriptionLocalizations, - nameLocalizations: nameLocalizations, - }; - }); - + const name = 'add'; super(client, { ...options, - description: descriptionLocalizations['en-GB'], - descriptionLocalizations, + description: client.i18n.getMessage(null, `commands.slash.${name}.description`), + descriptionLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.description`), dmPermission: false, - name: nameLocalizations['en-GB'], - nameLocalizations, - options: opts, + name, + nameLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.name`), + options: [ + { + name: 'member', + required: true, + type: ApplicationCommandOptionType.User, + }, + { + autocomplete: true, + name: 'ticket', + required: false, + type: ApplicationCommandOptionType.String, + }, + ].map(option => { + option.descriptionLocalizations = client.i18n.getAllMessages(`commands.slash.${name}.options.${option.name}.description`); + option.description = option.descriptionLocalizations['en-GB']; + option.nameLocalizations = client.i18n.getAllMessages(`commands.slash.${name}.options.${option.name}.name`); + return option; + }), }); } diff --git a/src/commands/slash/claim.js b/src/commands/slash/claim.js index cde6c67..05fedfe 100644 --- a/src/commands/slash/claim.js +++ b/src/commands/slash/claim.js @@ -2,19 +2,14 @@ const { SlashCommand } = require('@eartharoid/dbf'); module.exports = class ClaimSlashCommand extends SlashCommand { constructor(client, options) { - const descriptionLocalizations = {}; - client.i18n.locales.forEach(l => (descriptionLocalizations[l] = client.i18n.getMessage(l, 'commands.slash.claim.description'))); - - const nameLocalizations = {}; - client.i18n.locales.forEach(l => (nameLocalizations[l] = client.i18n.getMessage(l, 'commands.slash.claim.name'))); - + const name = 'claim'; super(client, { ...options, - description: descriptionLocalizations['en-GB'], - descriptionLocalizations, + description: client.i18n.getMessage(null, `commands.slash.${name}.description`), + descriptionLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.description`), dmPermission: false, - name: nameLocalizations['en-GB'], - nameLocalizations, + name, + nameLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.name`), }); } diff --git a/src/commands/slash/close.js b/src/commands/slash/close.js index 3d7d1c2..fc94113 100644 --- a/src/commands/slash/close.js +++ b/src/commands/slash/close.js @@ -3,48 +3,32 @@ const { ApplicationCommandOptionType } = require('discord.js'); module.exports = class CloseSlashCommand extends SlashCommand { constructor(client, options) { - const descriptionLocalizations = {}; - client.i18n.locales.forEach(l => (descriptionLocalizations[l] = client.i18n.getMessage(l, 'commands.slash.close.description'))); - - const nameLocalizations = {}; - client.i18n.locales.forEach(l => (nameLocalizations[l] = client.i18n.getMessage(l, 'commands.slash.close.name'))); - - let opts = [ - { - name: 'reason', - required: false, - type: ApplicationCommandOptionType.String, - }, - { - autocomplete: true, - name: 'ticket', - required: false, - type: ApplicationCommandOptionType.String, - }, - ]; - opts = opts.map(o => { - const descriptionLocalizations = {}; - client.i18n.locales.forEach(l => (descriptionLocalizations[l] = client.i18n.getMessage(l, `commands.slash.close.options.${o.name}.description`))); - - const nameLocalizations = {}; - client.i18n.locales.forEach(l => (nameLocalizations[l] = client.i18n.getMessage(l, `commands.slash.close.options.${o.name}.name`))); - - return { - ...o, - description: descriptionLocalizations['en-GB'], - descriptionLocalizations, - nameLocalizations: nameLocalizations, - }; - }); - + const name = 'close'; super(client, { ...options, - description: descriptionLocalizations['en-GB'], - descriptionLocalizations, + description: client.i18n.getMessage(null, `commands.slash.${name}.description`), + descriptionLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.description`), dmPermission: false, - name: nameLocalizations['en-GB'], - nameLocalizations, - options: opts, + name, + nameLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.name`), + options: [ + { + name: 'reason', + required: false, + type: ApplicationCommandOptionType.String, + }, + { + autocomplete: true, + name: 'ticket', + required: false, + type: ApplicationCommandOptionType.String, + }, + ].map(option => { + option.descriptionLocalizations = client.i18n.getAllMessages(`commands.slash.${name}.options.${option.name}.description`); + option.description = option.descriptionLocalizations['en-GB']; + option.nameLocalizations = client.i18n.getAllMessages(`commands.slash.${name}.options.${option.name}.name`); + return option; + }), }); } diff --git a/src/commands/slash/force-close.js b/src/commands/slash/force-close.js index af13a34..2e16b75 100644 --- a/src/commands/slash/force-close.js +++ b/src/commands/slash/force-close.js @@ -12,59 +12,43 @@ const ms = require('ms'); module.exports = class ForceCloseSlashCommand extends SlashCommand { constructor(client, options) { - const descriptionLocalizations = {}; - client.i18n.locales.forEach(l => (descriptionLocalizations[l] = client.i18n.getMessage(l, 'commands.slash.force-close.description'))); - - const nameLocalizations = {}; - client.i18n.locales.forEach(l => (nameLocalizations[l] = client.i18n.getMessage(l, 'commands.slash.force-close.name'))); - - let opts = [ - { - autocomplete: true, - name: 'category', - required: false, - type: ApplicationCommandOptionType.Integer, - }, - { - name: 'reason', - required: false, - type: ApplicationCommandOptionType.String, - }, - { - autocomplete: true, - name: 'ticket', - required: false, - type: ApplicationCommandOptionType.String, - }, - { - name: 'time', - required: false, - type: ApplicationCommandOptionType.String, - }, - ]; - opts = opts.map(o => { - const descriptionLocalizations = {}; - client.i18n.locales.forEach(l => (descriptionLocalizations[l] = client.i18n.getMessage(l, `commands.slash.force-close.options.${o.name}.description`))); - - const nameLocalizations = {}; - client.i18n.locales.forEach(l => (nameLocalizations[l] = client.i18n.getMessage(l, `commands.slash.force-close.options.${o.name}.name`))); - - return { - ...o, - description: descriptionLocalizations['en-GB'], - descriptionLocalizations, - nameLocalizations: nameLocalizations, - }; - }); - + const name = 'force-close'; super(client, { ...options, - description: descriptionLocalizations['en-GB'], - descriptionLocalizations, + description: client.i18n.getMessage(null, `commands.slash.${name}.description`), + descriptionLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.description`), dmPermission: false, - name: nameLocalizations['en-GB'], - nameLocalizations, - options: opts, + name, + nameLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.name`), + options: [ + { + autocomplete: true, + name: 'category', + required: false, + type: ApplicationCommandOptionType.Integer, + }, + { + name: 'reason', + required: false, + type: ApplicationCommandOptionType.String, + }, + { + autocomplete: true, + name: 'ticket', + required: false, + type: ApplicationCommandOptionType.String, + }, + { + name: 'time', + required: false, + type: ApplicationCommandOptionType.String, + }, + ].map(option => { + option.descriptionLocalizations = client.i18n.getAllMessages(`commands.slash.${name}.options.${option.name}.description`); + option.description = option.descriptionLocalizations['en-GB']; + option.nameLocalizations = client.i18n.getAllMessages(`commands.slash.${name}.options.${option.name}.name`); + return option; + }), }); } diff --git a/src/commands/slash/help.js b/src/commands/slash/help.js index aaa8192..cd41fbb 100644 --- a/src/commands/slash/help.js +++ b/src/commands/slash/help.js @@ -5,19 +5,14 @@ const { version } = require('../../../package.json'); module.exports = class ClaimSlashCommand extends SlashCommand { constructor(client, options) { - const descriptionLocalizations = {}; - client.i18n.locales.forEach(l => (descriptionLocalizations[l] = client.i18n.getMessage(l, 'commands.slash.help.description'))); - - const nameLocalizations = {}; - client.i18n.locales.forEach(l => (nameLocalizations[l] = client.i18n.getMessage(l, 'commands.slash.help.name'))); - + const name = 'help'; super(client, { ...options, - description: descriptionLocalizations['en-GB'], - descriptionLocalizations, + description: client.i18n.getMessage(null, `commands.slash.${name}.description`), + descriptionLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.description`), dmPermission: false, - name: nameLocalizations['en-GB'], - nameLocalizations, + name, + nameLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.name`), }); } diff --git a/src/commands/slash/move.js b/src/commands/slash/move.js index e0c8b4f..b9fe64c 100644 --- a/src/commands/slash/move.js +++ b/src/commands/slash/move.js @@ -3,43 +3,27 @@ const { ApplicationCommandOptionType } = require('discord.js'); module.exports = class MoveSlashCommand extends SlashCommand { constructor(client, options) { - const descriptionLocalizations = {}; - client.i18n.locales.forEach(l => (descriptionLocalizations[l] = client.i18n.getMessage(l, 'commands.slash.move.description'))); - - const nameLocalizations = {}; - client.i18n.locales.forEach(l => (nameLocalizations[l] = client.i18n.getMessage(l, 'commands.slash.move.name'))); - - let opts = [ - { - autocomplete: true, - name: 'category', - required: true, - type: ApplicationCommandOptionType.Integer, - }, - ]; - opts = opts.map(o => { - const descriptionLocalizations = {}; - client.i18n.locales.forEach(l => (descriptionLocalizations[l] = client.i18n.getMessage(l, `commands.slash.move.options.${o.name}.description`))); - - const nameLocalizations = {}; - client.i18n.locales.forEach(l => (nameLocalizations[l] = client.i18n.getMessage(l, `commands.slash.move.options.${o.name}.name`))); - - return { - ...o, - description: descriptionLocalizations['en-GB'], - descriptionLocalizations, - nameLocalizations: nameLocalizations, - }; - }); - + const name = 'move'; super(client, { ...options, - description: descriptionLocalizations['en-GB'], - descriptionLocalizations, + description: client.i18n.getMessage(null, `commands.slash.${name}.description`), + descriptionLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.description`), dmPermission: false, - name: nameLocalizations['en-GB'], - nameLocalizations, - options: opts, + name, + nameLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.name`), + options: [ + { + autocomplete: true, + name: 'category', + required: true, + type: ApplicationCommandOptionType.Integer, + }, + ].map(option => { + option.descriptionLocalizations = client.i18n.getAllMessages(`commands.slash.${name}.options.${option.name}.description`); + option.description = option.descriptionLocalizations['en-GB']; + option.nameLocalizations = client.i18n.getAllMessages(`commands.slash.${name}.options.${option.name}.name`); + return option; + }), }); } diff --git a/src/commands/slash/new.js b/src/commands/slash/new.js index ccf978d..6fad360 100644 --- a/src/commands/slash/new.js +++ b/src/commands/slash/new.js @@ -4,43 +4,27 @@ const { useGuild } = require('../../lib/tickets/utils'); module.exports = class NewSlashCommand extends SlashCommand { constructor(client, options) { - const descriptionLocalizations = {}; - client.i18n.locales.forEach(l => (descriptionLocalizations[l] = client.i18n.getMessage(l, 'commands.slash.new.description'))); - - const nameLocalizations = {}; - client.i18n.locales.forEach(l => (nameLocalizations[l] = client.i18n.getMessage(l, 'commands.slash.new.name'))); - - let opts = [ - { - autocomplete: true, - name: 'references', - required: false, - type: ApplicationCommandOptionType.String, - }, - ]; - opts = opts.map(o => { - const descriptionLocalizations = {}; - client.i18n.locales.forEach(l => (descriptionLocalizations[l] = client.i18n.getMessage(l, `commands.slash.new.options.${o.name}.description`))); - - const nameLocalizations = {}; - client.i18n.locales.forEach(l => (nameLocalizations[l] = client.i18n.getMessage(l, `commands.slash.new.options.${o.name}.name`))); - - return { - ...o, - description: descriptionLocalizations['en-GB'], - descriptionLocalizations, - nameLocalizations: nameLocalizations, - }; - }); - + const name = 'new'; super(client, { ...options, - description: descriptionLocalizations['en-GB'], - descriptionLocalizations, + description: client.i18n.getMessage(null, `commands.slash.${name}.description`), + descriptionLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.description`), dmPermission: false, - name: nameLocalizations['en-GB'], - nameLocalizations, - options: opts, + name, + nameLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.name`), + options: [ + { + autocomplete: true, + name: 'references', + required: false, + type: ApplicationCommandOptionType.String, + }, + ].map(option => { + option.descriptionLocalizations = client.i18n.getAllMessages(`commands.slash.${name}.options.${option.name}.description`); + option.description = option.descriptionLocalizations['en-GB']; + option.nameLocalizations = client.i18n.getAllMessages(`commands.slash.${name}.options.${option.name}.name`); + return option; + }), }); } diff --git a/src/commands/slash/priority.js b/src/commands/slash/priority.js index 9274fc9..b46c0c8 100644 --- a/src/commands/slash/priority.js +++ b/src/commands/slash/priority.js @@ -5,55 +5,34 @@ const { logTicketEvent } = require('../../lib/logging'); module.exports = class PrioritySlashCommand extends SlashCommand { constructor(client, options) { - const descriptionLocalizations = {}; - client.i18n.locales.forEach(l => (descriptionLocalizations[l] = client.i18n.getMessage(l, 'commands.slash.priority.description'))); - - const nameLocalizations = {}; - client.i18n.locales.forEach(l => (nameLocalizations[l] = client.i18n.getMessage(l, 'commands.slash.priority.name'))); - - let opts = [ - { - choices: ['HIGH', 'MEDIUM', 'LOW'], - name: 'priority', - required: true, - type: ApplicationCommandOptionType.String, - }, - ]; - opts = opts.map(o => { - const descriptionLocalizations = {}; - client.i18n.locales.forEach(l => (descriptionLocalizations[l] = client.i18n.getMessage(l, `commands.slash.priority.options.${o.name}.description`))); - - const nameLocalizations = {}; - client.i18n.locales.forEach(l => (nameLocalizations[l] = client.i18n.getMessage(l, `commands.slash.priority.options.${o.name}.name`))); - - if (o.choices) { - o.choices = o.choices.map(c => { - const nameLocalizations = {}; - client.i18n.locales.forEach(l => (nameLocalizations[l] = client.i18n.getMessage(l, `commands.slash.priority.options.${o.name}.choices.${c}`))); - return { - name: nameLocalizations['en-GB'], - nameLocalizations: nameLocalizations, - value: c, - }; - }); - } - - return { - ...o, - description: descriptionLocalizations['en-GB'], - descriptionLocalizations, - nameLocalizations: nameLocalizations, - }; - }); - + const name = 'priority'; super(client, { ...options, - description: descriptionLocalizations['en-GB'], - descriptionLocalizations, + description: client.i18n.getMessage(null, `commands.slash.${name}.description`), + descriptionLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.description`), dmPermission: false, - name: nameLocalizations['en-GB'], - nameLocalizations, - options: opts, + name, + nameLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.name`), + options: [ + { + choices: ['HIGH', 'MEDIUM', 'LOW'], + name: 'priority', + required: true, + type: ApplicationCommandOptionType.String, + }, + ].map(option => { + option.descriptionLocalizations = client.i18n.getAllMessages(`commands.slash.${name}.options.${option.name}.description`); + option.description = option.descriptionLocalizations['en-GB']; + option.nameLocalizations = client.i18n.getAllMessages(`commands.slash.${name}.options.${option.name}.name`); + if (option.choices) { + option.choices = option.choices.map(choice => ({ + name: client.i18n.getMessage(null, `commands.slash.priority.options.${option.name}.choices.${choice}`), + nameLocalizations: client.i18n.getAllMessages(`commands.slash.priority.options.${option.name}.choices.${choice}`), + value: choice, + })); + } + return option; + }), }); } diff --git a/src/commands/slash/release.js b/src/commands/slash/release.js index 6074705..b1f43d5 100644 --- a/src/commands/slash/release.js +++ b/src/commands/slash/release.js @@ -2,19 +2,14 @@ const { SlashCommand } = require('@eartharoid/dbf'); module.exports = class ReleaseSlashCommand extends SlashCommand { constructor(client, options) { - const descriptionLocalizations = {}; - client.i18n.locales.forEach(l => (descriptionLocalizations[l] = client.i18n.getMessage(l, 'commands.slash.release.description'))); - - const nameLocalizations = {}; - client.i18n.locales.forEach(l => (nameLocalizations[l] = client.i18n.getMessage(l, 'commands.slash.release.name'))); - + const name = 'release'; super(client, { ...options, - description: descriptionLocalizations['en-GB'], - descriptionLocalizations, + description: client.i18n.getMessage(null, `commands.slash.${name}.description`), + descriptionLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.description`), dmPermission: false, - name: nameLocalizations['en-GB'], - nameLocalizations, + name, + nameLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.name`), }); } diff --git a/src/commands/slash/remove.js b/src/commands/slash/remove.js index 29cc142..0123fa0 100644 --- a/src/commands/slash/remove.js +++ b/src/commands/slash/remove.js @@ -3,48 +3,32 @@ const { ApplicationCommandOptionType } = require('discord.js'); module.exports = class RemoveSlashCommand extends SlashCommand { constructor(client, options) { - const descriptionLocalizations = {}; - client.i18n.locales.forEach(l => (descriptionLocalizations[l] = client.i18n.getMessage(l, 'commands.slash.remove.description'))); - - const nameLocalizations = {}; - client.i18n.locales.forEach(l => (nameLocalizations[l] = client.i18n.getMessage(l, 'commands.slash.remove.name'))); - - let opts = [ - { - name: 'member', - required: true, - type: ApplicationCommandOptionType.User, - }, - { - autocomplete: true, - name: 'ticket', - required: false, - type: ApplicationCommandOptionType.String, - }, - ]; - opts = opts.map(o => { - const descriptionLocalizations = {}; - client.i18n.locales.forEach(l => (descriptionLocalizations[l] = client.i18n.getMessage(l, `commands.slash.remove.options.${o.name}.description`))); - - const nameLocalizations = {}; - client.i18n.locales.forEach(l => (nameLocalizations[l] = client.i18n.getMessage(l, `commands.slash.remove.options.${o.name}.name`))); - - return { - ...o, - description: descriptionLocalizations['en-GB'], - descriptionLocalizations, - nameLocalizations: nameLocalizations, - }; - }); - + const name = 'remove'; super(client, { ...options, - description: descriptionLocalizations['en-GB'], - descriptionLocalizations, + description: client.i18n.getMessage(null, `commands.slash.${name}.description`), + descriptionLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.description`), dmPermission: false, - name: nameLocalizations['en-GB'], - nameLocalizations, - options: opts, + name, + nameLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.name`), + options: [ + { + name: 'member', + required: true, + type: ApplicationCommandOptionType.User, + }, + { + autocomplete: true, + name: 'ticket', + required: false, + type: ApplicationCommandOptionType.String, + }, + ].map(option => { + option.descriptionLocalizations = client.i18n.getAllMessages(`commands.slash.${name}.options.${option.name}.description`); + option.description = option.descriptionLocalizations['en-GB']; + option.nameLocalizations = client.i18n.getAllMessages(`commands.slash.${name}.options.${option.name}.name`); + return option; + }), }); } diff --git a/src/commands/slash/tag.js b/src/commands/slash/tag.js index dd4b655..4eea3b5 100644 --- a/src/commands/slash/tag.js +++ b/src/commands/slash/tag.js @@ -4,48 +4,32 @@ const ExtendedEmbedBuilder = require('../../lib/embed'); module.exports = class TagSlashCommand extends SlashCommand { constructor(client, options) { - const descriptionLocalizations = {}; - client.i18n.locales.forEach(l => (descriptionLocalizations[l] = client.i18n.getMessage(l, 'commands.slash.tag.description'))); - - const nameLocalizations = {}; - client.i18n.locales.forEach(l => (nameLocalizations[l] = client.i18n.getMessage(l, 'commands.slash.tag.name'))); - - let opts = [ - { - autocomplete: true, - name: 'tag', - required: true, - type: ApplicationCommandOptionType.Integer, - }, - { - name: 'for', - required: false, - type: ApplicationCommandOptionType.User, - }, - ]; - opts = opts.map(o => { - const descriptionLocalizations = {}; - client.i18n.locales.forEach(l => (descriptionLocalizations[l] = client.i18n.getMessage(l, `commands.slash.tag.options.${o.name}.description`))); - - const nameLocalizations = {}; - client.i18n.locales.forEach(l => (nameLocalizations[l] = client.i18n.getMessage(l, `commands.slash.tag.options.${o.name}.name`))); - - return { - ...o, - description: descriptionLocalizations['en-GB'], - descriptionLocalizations, - nameLocalizations: nameLocalizations, - }; - }); - + const name = 'tag'; super(client, { ...options, - description: descriptionLocalizations['en-GB'], - descriptionLocalizations, + description: client.i18n.getMessage(null, `commands.slash.${name}.description`), + descriptionLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.description`), dmPermission: false, - name: nameLocalizations['en-GB'], - nameLocalizations, - options: opts, + name, + nameLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.name`), + options: [ + { + autocomplete: true, + name: 'tag', + required: true, + type: ApplicationCommandOptionType.Integer, + }, + { + name: 'for', + required: false, + type: ApplicationCommandOptionType.User, + }, + ].map(option => { + option.descriptionLocalizations = client.i18n.getAllMessages(`commands.slash.${name}.options.${option.name}.description`); + option.description = option.descriptionLocalizations['en-GB']; + option.nameLocalizations = client.i18n.getAllMessages(`commands.slash.${name}.options.${option.name}.name`); + return option; + }), }); } diff --git a/src/commands/slash/tickets.js b/src/commands/slash/tickets.js index 0f71997..7ed1f2b 100644 --- a/src/commands/slash/tickets.js +++ b/src/commands/slash/tickets.js @@ -7,42 +7,26 @@ const { decrypt } = new Cryptr(process.env.ENCRYPTION_KEY); module.exports = class TicketsSlashCommand extends SlashCommand { constructor(client, options) { - const descriptionLocalizations = {}; - client.i18n.locales.forEach(l => (descriptionLocalizations[l] = client.i18n.getMessage(l, 'commands.slash.tickets.description'))); - - const nameLocalizations = {}; - client.i18n.locales.forEach(l => (nameLocalizations[l] = client.i18n.getMessage(l, 'commands.slash.tickets.name'))); - - let opts = [ - { - name: 'member', - required: false, - type: ApplicationCommandOptionType.User, - }, - ]; - opts = opts.map(o => { - const descriptionLocalizations = {}; - client.i18n.locales.forEach(l => (descriptionLocalizations[l] = client.i18n.getMessage(l, `commands.slash.tickets.options.${o.name}.description`))); - - const nameLocalizations = {}; - client.i18n.locales.forEach(l => (nameLocalizations[l] = client.i18n.getMessage(l, `commands.slash.tickets.options.${o.name}.name`))); - - return { - ...o, - description: descriptionLocalizations['en-GB'], - descriptionLocalizations, - nameLocalizations: nameLocalizations, - }; - }); - + const name = 'tickets'; super(client, { ...options, - description: descriptionLocalizations['en-GB'], - descriptionLocalizations, + description: client.i18n.getMessage(null, `commands.slash.${name}.description`), + descriptionLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.description`), dmPermission: false, - name: nameLocalizations['en-GB'], - nameLocalizations, - options: opts, + name, + nameLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.name`), + options: [ + { + name: 'member', + required: false, + type: ApplicationCommandOptionType.User, + }, + ].map(option => { + option.descriptionLocalizations = client.i18n.getAllMessages(`commands.slash.${name}.options.${option.name}.description`); + option.description = option.descriptionLocalizations['en-GB']; + option.nameLocalizations = client.i18n.getAllMessages(`commands.slash.${name}.options.${option.name}.name`); + return option; + }), }); } @@ -124,6 +108,7 @@ module.exports = class TicketsSlashCommand extends SlashCommand { }).join('\n'), }); } + // TODO: add portal URL to view all (this list is limited to the last 10) const embed = new ExtendedEmbedBuilder({ iconURL: interaction.guild.iconURL(), diff --git a/src/commands/slash/topic.js b/src/commands/slash/topic.js index 751c93d..07e7617 100644 --- a/src/commands/slash/topic.js +++ b/src/commands/slash/topic.js @@ -11,19 +11,14 @@ const ExtendedEmbedBuilder = require('../../lib/embed'); module.exports = class TopicSlashCommand extends SlashCommand { constructor(client, options) { - const descriptionLocalizations = {}; - client.i18n.locales.forEach(l => (descriptionLocalizations[l] = client.i18n.getMessage(l, 'commands.slash.topic.description'))); - - const nameLocalizations = {}; - client.i18n.locales.forEach(l => (nameLocalizations[l] = client.i18n.getMessage(l, 'commands.slash.topic.name'))); - + const name = 'topic'; super(client, { ...options, - description: descriptionLocalizations['en-GB'], - descriptionLocalizations, + description: client.i18n.getMessage(null, `commands.slash.${name}.description`), + descriptionLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.description`), dmPermission: false, - name: nameLocalizations['en-GB'], - nameLocalizations, + name, + nameLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.name`), }); } diff --git a/src/commands/slash/transcript.js b/src/commands/slash/transcript.js index 25a9f30..eef5a46 100644 --- a/src/commands/slash/transcript.js +++ b/src/commands/slash/transcript.js @@ -10,43 +10,27 @@ const pad = require('pad'); module.exports = class TranscriptSlashCommand extends SlashCommand { constructor(client, options) { - const descriptionLocalizations = {}; - client.i18n.locales.forEach(l => (descriptionLocalizations[l] = client.i18n.getMessage(l, 'commands.slash.transcript.description'))); - - const nameLocalizations = {}; - client.i18n.locales.forEach(l => (nameLocalizations[l] = client.i18n.getMessage(l, 'commands.slash.transcript.name'))); - - let opts = [ - { - autocomplete: true, - name: 'ticket', - required: true, - type: ApplicationCommandOptionType.String, - }, - ]; - opts = opts.map(o => { - const descriptionLocalizations = {}; - client.i18n.locales.forEach(l => (descriptionLocalizations[l] = client.i18n.getMessage(l, `commands.slash.transcript.options.${o.name}.description`))); - - const nameLocalizations = {}; - client.i18n.locales.forEach(l => (nameLocalizations[l] = client.i18n.getMessage(l, `commands.slash.transcript.options.${o.name}.name`))); - - return { - ...o, - description: descriptionLocalizations['en-GB'], - descriptionLocalizations, - nameLocalizations: nameLocalizations, - }; - }); - + const name = 'transcript'; super(client, { ...options, - description: descriptionLocalizations['en-GB'], - descriptionLocalizations, + description: client.i18n.getMessage(null, `commands.slash.${name}.description`), + descriptionLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.description`), dmPermission: false, - name: nameLocalizations['en-GB'], - nameLocalizations, - options: opts, + name, + nameLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.name`), + options: [ + { + autocomplete: true, + name: 'ticket', + required: true, + type: ApplicationCommandOptionType.String, + }, + ].map(option => { + option.descriptionLocalizations = client.i18n.getAllMessages(`commands.slash.${name}.options.${option.name}.description`); + option.description = option.descriptionLocalizations['en-GB']; + option.nameLocalizations = client.i18n.getAllMessages(`commands.slash.${name}.options.${option.name}.name`); + return option; + }), }); Mustache.escape = text => text; // don't HTML-escape diff --git a/src/commands/slash/transfer.js b/src/commands/slash/transfer.js index 5584c6f..fb23a3e 100644 --- a/src/commands/slash/transfer.js +++ b/src/commands/slash/transfer.js @@ -3,42 +3,26 @@ const { ApplicationCommandOptionType } = require('discord.js'); module.exports = class TransferSlashCommand extends SlashCommand { constructor(client, options) { - const descriptionLocalizations = {}; - client.i18n.locales.forEach(l => (descriptionLocalizations[l] = client.i18n.getMessage(l, 'commands.slash.transfer.description'))); - - const nameLocalizations = {}; - client.i18n.locales.forEach(l => (nameLocalizations[l] = client.i18n.getMessage(l, 'commands.slash.transfer.name'))); - - let opts = [ - { - name: 'member', - required: true, - type: ApplicationCommandOptionType.User, - }, - ]; - opts = opts.map(o => { - const descriptionLocalizations = {}; - client.i18n.locales.forEach(l => (descriptionLocalizations[l] = client.i18n.getMessage(l, `commands.slash.transfer.options.${o.name}.description`))); - - const nameLocalizations = {}; - client.i18n.locales.forEach(l => (nameLocalizations[l] = client.i18n.getMessage(l, `commands.slash.transfer.options.${o.name}.name`))); - - return { - ...o, - description: descriptionLocalizations['en-GB'], - descriptionLocalizations, - nameLocalizations: nameLocalizations, - }; - }); - + const name = 'transfer'; super(client, { ...options, - description: descriptionLocalizations['en-GB'], - descriptionLocalizations, + description: client.i18n.getMessage(null, `commands.slash.${name}.description`), + descriptionLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.description`), dmPermission: false, - name: nameLocalizations['en-GB'], - nameLocalizations, - options: opts, + name, + nameLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.name`), + options: [ + { + name: 'member', + required: true, + type: ApplicationCommandOptionType.User, + }, + ].map(option => { + option.descriptionLocalizations = client.i18n.getAllMessages(`commands.slash.${name}.options.${option.name}.description`); + option.description = option.descriptionLocalizations['en-GB']; + option.nameLocalizations = client.i18n.getAllMessages(`commands.slash.${name}.options.${option.name}.name`); + return option; + }), }); }