Skip to content

Commit

Permalink
feat: use provided type param
Browse files Browse the repository at this point in the history
  • Loading branch information
monbrey committed Aug 6, 2021
1 parent 98e6263 commit 47eb507
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
20 changes: 15 additions & 5 deletions src/client/actions/InteractionCreate.js
Expand Up @@ -5,7 +5,7 @@ const ButtonInteraction = require('../../structures/ButtonInteraction');
const CommandInteraction = require('../../structures/CommandInteraction');
const ContextMenuInteraction = require('../../structures/ContextMenuInteraction');
const SelectMenuInteraction = require('../../structures/SelectMenuInteraction');
const { Events, InteractionTypes, MessageComponentTypes } = require('../../util/Constants');
const { Events, InteractionTypes, MessageComponentTypes, ApplicationCommandTypes } = require('../../util/Constants');

let deprecationEmitted = false;

Expand All @@ -19,10 +19,20 @@ class InteractionCreateAction extends Action {
let InteractionType;
switch (data.type) {
case InteractionTypes.APPLICATION_COMMAND:
if (typeof data.data.target_id === 'undefined') {
InteractionType = CommandInteraction;
} else {
InteractionType = ContextMenuInteraction;
switch (data.data.type) {
case ApplicationCommandTypes.APPLICATION_COMMAND:
InteractionType = CommandInteraction;
break;
case ApplicationCommandTypes.USER:
case ApplicationCommandTypes.MESSAGE:
InteractionType = ContextMenuInteraction;
break;
default:
client.emit(
Events.DEBUG,
`[INTERACTION] Received application command interaction with unknown type: ${data.data.type}`,
);
return;
}
break;
case InteractionTypes.MESSAGE_COMPONENT:
Expand Down
10 changes: 8 additions & 2 deletions src/structures/ContextMenuInteraction.js
Expand Up @@ -2,7 +2,7 @@

const BaseCommandInteraction = require('./BaseCommandInteraction');
const CommandInteractionOptionResolver = require('./CommandInteractionOptionResolver');
const { ApplicationCommandOptionTypes } = require('../util/Constants');
const { ApplicationCommandOptionTypes, ApplicationCommandTypes } = require('../util/Constants');

/**
* Represents a context menu interaction.
Expand All @@ -12,7 +12,7 @@ class ContextMenuInteraction extends BaseCommandInteraction {
constructor(client, data) {
super(client, data);
/**
* The target of the interaction, parsed into an option
* The target of the interaction, parsed into options
* @type {CommandInteractionOptionResolver}
*/
this.options = new CommandInteractionOptionResolver(this.client, this.resolveContextMenuOptions(data.data));
Expand All @@ -22,6 +22,12 @@ class ContextMenuInteraction extends BaseCommandInteraction {
* @type {Snowflake}
*/
this.targetId = data.data.target_id;

/**
* The type of the target of the interaction; either USER or MESSAGE
* @type {ApplicationCommandType}
*/
this.targetType = ApplicationCommandTypes[data.data.type];
}

/**
Expand Down
1 change: 1 addition & 0 deletions typings/index.d.ts
Expand Up @@ -581,6 +581,7 @@ export class CommandInteractionOptionResolver {
export class ContextMenuInteraction extends BaseCommandInteraction {
public options: CommandInteractionOptionResolver;
public targetId: Snowflake;
public targetType: Exclude<ApplicationCommandType, 'CHAT_INPUT'>;
private resolveContextMenuOptions(data: APIApplicationCommandInteractionData): CommandInteractionOption[];
}

Expand Down

0 comments on commit 47eb507

Please sign in to comment.