fix: allow staff to get transcripts of other members (closes #400)

This commit is contained in:
Isaac 2023-05-24 22:04:19 +01:00
parent afa0123d22
commit a44539914e
No known key found for this signature in database
GPG Key ID: 0DE40AE37BBA5C33
3 changed files with 15 additions and 4 deletions

View File

@ -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,11 +73,13 @@ 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,
}),
);
}

View File

@ -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'];

View File

@ -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