Skip to content

Commit

Permalink
Fix wrong tunnel author using buttons in requests
Browse files Browse the repository at this point in the history
  • Loading branch information
utarwyn committed Jan 28, 2022
1 parent 4781342 commit 06dda8c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/bot/command/AppCommandRegister.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export default class AppCommandRegister {
description: localize.__('command.description'),
options: [
{
type: 6,
type: 'USER',
name: this.optionName,
description: localize.__('command.option-user')
}
Expand Down
2 changes: 1 addition & 1 deletion src/bot/entity/DuelRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export default class DuelRequest {
*/
private async challengeButtonAnswered(interaction: MessageComponentInteraction): Promise<void> {
// now that an interaction using buttons has been operated on message, use it
this.tunnel = new ComponentInteractionMessagingTunnel(interaction);
this.tunnel = new ComponentInteractionMessagingTunnel(interaction, this.tunnel.author);
return this.challengeAnswered(interaction.customId === 'yes');
}

Expand Down
11 changes: 9 additions & 2 deletions src/bot/messaging/ComponentInteractionMessagingTunnel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ export default class ComponentInteractionMessagingTunnel extends MessagingTunnel
* @private
*/
private readonly interaction: MessageComponentInteraction;
/**
* Original author of the message
* @private
*/
private readonly originalAuthor?: GuildMember;
/**
* Last reply sent into the tunnnel
* @private
Expand All @@ -25,17 +30,19 @@ export default class ComponentInteractionMessagingTunnel extends MessagingTunnel
* tunnel using Discord interactions.
*
* @param interaction interaction generic object
* @param originalAuthor original author of the message if provided
*/
constructor(interaction: MessageComponentInteraction) {
constructor(interaction: MessageComponentInteraction, originalAuthor?: GuildMember) {
super();
this.interaction = interaction;
this.originalAuthor = originalAuthor;
}

/**
* @inheritdoc
*/
public get author(): GuildMember {
return this.interaction.member as GuildMember;
return this.originalAuthor ?? (this.interaction.member as GuildMember);
}

/**
Expand Down

0 comments on commit 06dda8c

Please sign in to comment.