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 { decrypt } = new Cryptr(process.env.ENCRYPTION_KEY);
const Keyv = require('keyv'); const Keyv = require('keyv');
const ms = require('ms'); const ms = require('ms');
const { isStaff } = require('../lib/users');
module.exports = class TicketCompleter extends Autocompleter { module.exports = class TicketCompleter extends Autocompleter {
constructor(client, options) { constructor(client, options) {
@ -72,12 +73,14 @@ module.exports = class TicketCompleter extends Autocompleter {
* @param {import("discord.js").AutocompleteInteraction} interaction * @param {import("discord.js").AutocompleteInteraction} interaction
*/ */
async run(value, command, 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 interaction.respond(
await this.getOptions(value, { await this.getOptions(value, {
guildId: interaction.guild.id, guildId: interaction.guild.id,
open: ['add', 'close', 'force-close', 'remove'].includes(command.name), // false for `new`, `transcript` etc 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, required: true,
type: ApplicationCommandOptionType.String, type: ApplicationCommandOptionType.String,
}, },
{
name: 'member',
required: false,
type: ApplicationCommandOptionType.User,
},
].map(option => { ].map(option => {
option.descriptionLocalizations = client.i18n.getAllMessages(`commands.slash.${name}.options.${option.name}.description`); option.descriptionLocalizations = client.i18n.getAllMessages(`commands.slash.${name}.options.${option.name}.description`);
option.description = option.descriptionLocalizations['en-GB']; option.description = option.descriptionLocalizations['en-GB'];
@ -143,4 +148,4 @@ module.exports = class TranscriptSlashCommand extends SlashCommand {
await interaction.editReply({ files: [attachment] }); await interaction.editReply({ files: [attachment] });
// TODO: add portal link // TODO: add portal link
} }
}; };

View File

@ -222,8 +222,11 @@ commands:
description: Get the transcript of a ticket description: Get the transcript of a ticket
name: transcript name: transcript
options: options:
member:
description: The member to search for tickets of
name: member
ticket: ticket:
description: The number of the ticket to get the transcript of description: The ticket to get the transcript of
name: ticket name: ticket
transfer: transfer:
description: Transfer ownership of a ticket to another member description: Transfer ownership of a ticket to another member