From a44539914eac9bb9196115d1361b6b85433daa22 Mon Sep 17 00:00:00 2001 From: Isaac Date: Wed, 24 May 2023 22:04:19 +0100 Subject: [PATCH] fix: allow staff to get transcripts of other members (closes #400) --- src/autocomplete/ticket.js | 7 +++++-- src/commands/slash/transcript.js | 7 ++++++- src/i18n/en-GB.yml | 5 ++++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/autocomplete/ticket.js b/src/autocomplete/ticket.js index 767a6e8..c18eec6 100644 --- a/src/autocomplete/ticket.js +++ b/src/autocomplete/ticket.js @@ -5,6 +5,7 @@ const Cryptr = require('cryptr'); const { decrypt } = new Cryptr(process.env.ENCRYPTION_KEY); const Keyv = require('keyv'); const ms = require('ms'); +const { isStaff } = require('../lib/users'); module.exports = class TicketCompleter extends Autocompleter { constructor(client, options) { @@ -72,12 +73,14 @@ module.exports = class TicketCompleter extends Autocompleter { * @param {import("discord.js").AutocompleteInteraction} interaction */ async run(value, command, interaction) { + const otherMember = await isStaff(interaction.guild, interaction.user.id) && interaction.options.data[1]?.value; + const userId = otherMember || interaction.user.id; await interaction.respond( await this.getOptions(value, { guildId: interaction.guild.id, open: ['add', 'close', 'force-close', 'remove'].includes(command.name), // false for `new`, `transcript` etc - userId: interaction.user.id, + userId, }), ); } -}; \ No newline at end of file +}; diff --git a/src/commands/slash/transcript.js b/src/commands/slash/transcript.js index b889f4d..c9642a5 100644 --- a/src/commands/slash/transcript.js +++ b/src/commands/slash/transcript.js @@ -24,6 +24,11 @@ module.exports = class TranscriptSlashCommand extends SlashCommand { required: true, type: ApplicationCommandOptionType.String, }, + { + 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']; @@ -143,4 +148,4 @@ module.exports = class TranscriptSlashCommand extends SlashCommand { await interaction.editReply({ files: [attachment] }); // TODO: add portal link } -}; \ No newline at end of file +}; diff --git a/src/i18n/en-GB.yml b/src/i18n/en-GB.yml index 042d884..1f8f977 100644 --- a/src/i18n/en-GB.yml +++ b/src/i18n/en-GB.yml @@ -222,8 +222,11 @@ commands: description: Get the transcript of a ticket name: transcript options: + member: + description: The member to search for tickets of + name: member ticket: - description: The number of the ticket to get the transcript of + description: The ticket to get the transcript of name: ticket transfer: description: Transfer ownership of a ticket to another member