refactor: simplify commands i18n

This commit is contained in:
Isaac 2022-10-26 18:58:46 +01:00
parent c6f1261478
commit 1843400004
No known key found for this signature in database
GPG Key ID: 0DE40AE37BBA5C33
16 changed files with 263 additions and 463 deletions

View File

@ -37,9 +37,9 @@
"@discord-tickets/settings": "^1.1.5", "@discord-tickets/settings": "^1.1.5",
"@eartharoid/dbf": "^0.3.3", "@eartharoid/dbf": "^0.3.3",
"@eartharoid/dtf": "^2.0.1", "@eartharoid/dtf": "^2.0.1",
"@eartharoid/i18n": "^1.1.0", "@eartharoid/i18n": "^1.2.1",
"@fastify/cookie": "^6.0.0", "@fastify/cookie": "^6.0.0",
"@fastify/cors": "^8.1.0", "@fastify/cors": "^8.1.1",
"@fastify/http-proxy": "^8.2.3", "@fastify/http-proxy": "^8.2.3",
"@fastify/jwt": "^5.0.1", "@fastify/jwt": "^5.0.1",
"@fastify/oauth2": "^5.1.0", "@fastify/oauth2": "^5.1.0",
@ -67,7 +67,7 @@
}, },
"devDependencies": { "devDependencies": {
"all-contributors-cli": "^6.24.0", "all-contributors-cli": "^6.24.0",
"eslint": "^8.25.0", "eslint": "^8.26.0",
"eslint-plugin-unused-imports": "^2.0.0", "eslint-plugin-unused-imports": "^2.0.0",
"nodemon": "^2.0.20" "nodemon": "^2.0.20"
}, },

View File

@ -3,48 +3,32 @@ const { ApplicationCommandOptionType } = require('discord.js');
module.exports = class AddSlashCommand extends SlashCommand { module.exports = class AddSlashCommand extends SlashCommand {
constructor(client, options) { constructor(client, options) {
const descriptionLocalizations = {}; const name = 'add';
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,
};
});
super(client, { super(client, {
...options, ...options,
description: descriptionLocalizations['en-GB'], description: client.i18n.getMessage(null, `commands.slash.${name}.description`),
descriptionLocalizations, descriptionLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.description`),
dmPermission: false, dmPermission: false,
name: nameLocalizations['en-GB'], name,
nameLocalizations, nameLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.name`),
options: opts, 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;
}),
}); });
} }

View File

@ -2,19 +2,14 @@ const { SlashCommand } = require('@eartharoid/dbf');
module.exports = class ClaimSlashCommand extends SlashCommand { module.exports = class ClaimSlashCommand extends SlashCommand {
constructor(client, options) { constructor(client, options) {
const descriptionLocalizations = {}; const name = 'claim';
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')));
super(client, { super(client, {
...options, ...options,
description: descriptionLocalizations['en-GB'], description: client.i18n.getMessage(null, `commands.slash.${name}.description`),
descriptionLocalizations, descriptionLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.description`),
dmPermission: false, dmPermission: false,
name: nameLocalizations['en-GB'], name,
nameLocalizations, nameLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.name`),
}); });
} }

View File

@ -3,48 +3,32 @@ const { ApplicationCommandOptionType } = require('discord.js');
module.exports = class CloseSlashCommand extends SlashCommand { module.exports = class CloseSlashCommand extends SlashCommand {
constructor(client, options) { constructor(client, options) {
const descriptionLocalizations = {}; const name = 'close';
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,
};
});
super(client, { super(client, {
...options, ...options,
description: descriptionLocalizations['en-GB'], description: client.i18n.getMessage(null, `commands.slash.${name}.description`),
descriptionLocalizations, descriptionLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.description`),
dmPermission: false, dmPermission: false,
name: nameLocalizations['en-GB'], name,
nameLocalizations, nameLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.name`),
options: opts, 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;
}),
}); });
} }

View File

@ -12,59 +12,43 @@ const ms = require('ms');
module.exports = class ForceCloseSlashCommand extends SlashCommand { module.exports = class ForceCloseSlashCommand extends SlashCommand {
constructor(client, options) { constructor(client, options) {
const descriptionLocalizations = {}; const name = 'force-close';
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,
};
});
super(client, { super(client, {
...options, ...options,
description: descriptionLocalizations['en-GB'], description: client.i18n.getMessage(null, `commands.slash.${name}.description`),
descriptionLocalizations, descriptionLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.description`),
dmPermission: false, dmPermission: false,
name: nameLocalizations['en-GB'], name,
nameLocalizations, nameLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.name`),
options: opts, 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;
}),
}); });
} }

View File

@ -5,19 +5,14 @@ const { version } = require('../../../package.json');
module.exports = class ClaimSlashCommand extends SlashCommand { module.exports = class ClaimSlashCommand extends SlashCommand {
constructor(client, options) { constructor(client, options) {
const descriptionLocalizations = {}; const name = 'help';
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')));
super(client, { super(client, {
...options, ...options,
description: descriptionLocalizations['en-GB'], description: client.i18n.getMessage(null, `commands.slash.${name}.description`),
descriptionLocalizations, descriptionLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.description`),
dmPermission: false, dmPermission: false,
name: nameLocalizations['en-GB'], name,
nameLocalizations, nameLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.name`),
}); });
} }

View File

@ -3,43 +3,27 @@ const { ApplicationCommandOptionType } = require('discord.js');
module.exports = class MoveSlashCommand extends SlashCommand { module.exports = class MoveSlashCommand extends SlashCommand {
constructor(client, options) { constructor(client, options) {
const descriptionLocalizations = {}; const name = 'move';
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,
};
});
super(client, { super(client, {
...options, ...options,
description: descriptionLocalizations['en-GB'], description: client.i18n.getMessage(null, `commands.slash.${name}.description`),
descriptionLocalizations, descriptionLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.description`),
dmPermission: false, dmPermission: false,
name: nameLocalizations['en-GB'], name,
nameLocalizations, nameLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.name`),
options: opts, 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;
}),
}); });
} }

View File

@ -4,43 +4,27 @@ const { useGuild } = require('../../lib/tickets/utils');
module.exports = class NewSlashCommand extends SlashCommand { module.exports = class NewSlashCommand extends SlashCommand {
constructor(client, options) { constructor(client, options) {
const descriptionLocalizations = {}; const name = 'new';
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,
};
});
super(client, { super(client, {
...options, ...options,
description: descriptionLocalizations['en-GB'], description: client.i18n.getMessage(null, `commands.slash.${name}.description`),
descriptionLocalizations, descriptionLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.description`),
dmPermission: false, dmPermission: false,
name: nameLocalizations['en-GB'], name,
nameLocalizations, nameLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.name`),
options: opts, 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;
}),
}); });
} }

View File

@ -5,55 +5,34 @@ const { logTicketEvent } = require('../../lib/logging');
module.exports = class PrioritySlashCommand extends SlashCommand { module.exports = class PrioritySlashCommand extends SlashCommand {
constructor(client, options) { constructor(client, options) {
const descriptionLocalizations = {}; const name = 'priority';
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,
};
});
super(client, { super(client, {
...options, ...options,
description: descriptionLocalizations['en-GB'], description: client.i18n.getMessage(null, `commands.slash.${name}.description`),
descriptionLocalizations, descriptionLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.description`),
dmPermission: false, dmPermission: false,
name: nameLocalizations['en-GB'], name,
nameLocalizations, nameLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.name`),
options: opts, 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;
}),
}); });
} }

View File

@ -2,19 +2,14 @@ const { SlashCommand } = require('@eartharoid/dbf');
module.exports = class ReleaseSlashCommand extends SlashCommand { module.exports = class ReleaseSlashCommand extends SlashCommand {
constructor(client, options) { constructor(client, options) {
const descriptionLocalizations = {}; const name = 'release';
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')));
super(client, { super(client, {
...options, ...options,
description: descriptionLocalizations['en-GB'], description: client.i18n.getMessage(null, `commands.slash.${name}.description`),
descriptionLocalizations, descriptionLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.description`),
dmPermission: false, dmPermission: false,
name: nameLocalizations['en-GB'], name,
nameLocalizations, nameLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.name`),
}); });
} }

View File

@ -3,48 +3,32 @@ const { ApplicationCommandOptionType } = require('discord.js');
module.exports = class RemoveSlashCommand extends SlashCommand { module.exports = class RemoveSlashCommand extends SlashCommand {
constructor(client, options) { constructor(client, options) {
const descriptionLocalizations = {}; const name = 'remove';
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,
};
});
super(client, { super(client, {
...options, ...options,
description: descriptionLocalizations['en-GB'], description: client.i18n.getMessage(null, `commands.slash.${name}.description`),
descriptionLocalizations, descriptionLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.description`),
dmPermission: false, dmPermission: false,
name: nameLocalizations['en-GB'], name,
nameLocalizations, nameLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.name`),
options: opts, 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;
}),
}); });
} }

View File

@ -4,48 +4,32 @@ const ExtendedEmbedBuilder = require('../../lib/embed');
module.exports = class TagSlashCommand extends SlashCommand { module.exports = class TagSlashCommand extends SlashCommand {
constructor(client, options) { constructor(client, options) {
const descriptionLocalizations = {}; const name = 'tag';
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,
};
});
super(client, { super(client, {
...options, ...options,
description: descriptionLocalizations['en-GB'], description: client.i18n.getMessage(null, `commands.slash.${name}.description`),
descriptionLocalizations, descriptionLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.description`),
dmPermission: false, dmPermission: false,
name: nameLocalizations['en-GB'], name,
nameLocalizations, nameLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.name`),
options: opts, 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;
}),
}); });
} }

View File

@ -7,42 +7,26 @@ const { decrypt } = new Cryptr(process.env.ENCRYPTION_KEY);
module.exports = class TicketsSlashCommand extends SlashCommand { module.exports = class TicketsSlashCommand extends SlashCommand {
constructor(client, options) { constructor(client, options) {
const descriptionLocalizations = {}; const name = 'tickets';
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,
};
});
super(client, { super(client, {
...options, ...options,
description: descriptionLocalizations['en-GB'], description: client.i18n.getMessage(null, `commands.slash.${name}.description`),
descriptionLocalizations, descriptionLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.description`),
dmPermission: false, dmPermission: false,
name: nameLocalizations['en-GB'], name,
nameLocalizations, nameLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.name`),
options: opts, 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'), }).join('\n'),
}); });
} }
// TODO: add portal URL to view all (this list is limited to the last 10)
const embed = new ExtendedEmbedBuilder({ const embed = new ExtendedEmbedBuilder({
iconURL: interaction.guild.iconURL(), iconURL: interaction.guild.iconURL(),

View File

@ -11,19 +11,14 @@ const ExtendedEmbedBuilder = require('../../lib/embed');
module.exports = class TopicSlashCommand extends SlashCommand { module.exports = class TopicSlashCommand extends SlashCommand {
constructor(client, options) { constructor(client, options) {
const descriptionLocalizations = {}; const name = 'topic';
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')));
super(client, { super(client, {
...options, ...options,
description: descriptionLocalizations['en-GB'], description: client.i18n.getMessage(null, `commands.slash.${name}.description`),
descriptionLocalizations, descriptionLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.description`),
dmPermission: false, dmPermission: false,
name: nameLocalizations['en-GB'], name,
nameLocalizations, nameLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.name`),
}); });
} }

View File

@ -10,43 +10,27 @@ const pad = require('pad');
module.exports = class TranscriptSlashCommand extends SlashCommand { module.exports = class TranscriptSlashCommand extends SlashCommand {
constructor(client, options) { constructor(client, options) {
const descriptionLocalizations = {}; const name = 'transcript';
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,
};
});
super(client, { super(client, {
...options, ...options,
description: descriptionLocalizations['en-GB'], description: client.i18n.getMessage(null, `commands.slash.${name}.description`),
descriptionLocalizations, descriptionLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.description`),
dmPermission: false, dmPermission: false,
name: nameLocalizations['en-GB'], name,
nameLocalizations, nameLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.name`),
options: opts, 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 Mustache.escape = text => text; // don't HTML-escape

View File

@ -3,42 +3,26 @@ const { ApplicationCommandOptionType } = require('discord.js');
module.exports = class TransferSlashCommand extends SlashCommand { module.exports = class TransferSlashCommand extends SlashCommand {
constructor(client, options) { constructor(client, options) {
const descriptionLocalizations = {}; const name = 'transfer';
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,
};
});
super(client, { super(client, {
...options, ...options,
description: descriptionLocalizations['en-GB'], description: client.i18n.getMessage(null, `commands.slash.${name}.description`),
descriptionLocalizations, descriptionLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.description`),
dmPermission: false, dmPermission: false,
name: nameLocalizations['en-GB'], name,
nameLocalizations, nameLocalizations: client.i18n.getAllMessages(`commands.slash.${name}.name`),
options: opts, 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;
}),
}); });
} }