Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add UserContextMenuInteraction and MessageContextMenuInteraction #7003

Merged
merged 17 commits into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/structures/Interaction.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const Base = require('./Base');
const { InteractionTypes, MessageComponentTypes } = require('../util/Constants');
const { InteractionTypes, MessageComponentTypes, ApplicationCommandTypes } = require('../util/Constants');
const Permissions = require('../util/Permissions');
const SnowflakeUtil = require('../util/SnowflakeUtil');

Expand Down Expand Up @@ -160,6 +160,22 @@ class Interaction extends Base {
return InteractionTypes[this.type] === InteractionTypes.APPLICATION_COMMAND && typeof this.targetId !== 'undefined';
}

/**
* Indicates whether this interaction is a {@link UserContextMenuInteraction}
* @returns {boolean}
*/
isUserContextMenu() {
return this.isContextMenu() && ApplicationCommandTypes[this.targetType] === ApplicationCommandTypes.USER;
}

/**
* Indicates whether this interaction is a {@link MessageContextMenuInteraction}
* @returns {boolean}
*/
isMessageContextMenu() {
return this.isContextMenu() && ApplicationCommandTypes[this.targetType] === ApplicationCommandTypes.MESSAGE;
}

/**
* Indicates whether this interaction is an {@link AutocompleteInteraction}
* @returns {boolean}
Expand Down
20 changes: 20 additions & 0 deletions src/structures/MessageContextMenuInteraction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';

const ContextMenuInteraction = require('./ContextMenuInteraction');

/**
* Represents a message context menu interaction.
* @extends {ContextMenuInteraction}
*/
class MessageContextMenuInteraction extends ContextMenuInteraction {
/**
* The message this interaction was sent from
* @type {Message|APIMessage}
* @readonly
*/
get targetMessage() {
return this.options.getMessage('message');
}
}

module.exports = MessageContextMenuInteraction;
29 changes: 29 additions & 0 deletions src/structures/UserContextMenuInteraction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

const ContextMenuInteraction = require('./ContextMenuInteraction');

/**
* Represents a user context menu interaction.
* @extends {ContextMenuInteraction}
*/
class UserContextMenuInteraction extends ContextMenuInteraction {
/**
* The user this interaction was sent from
* @type {User}
* @readonly
*/
get targetUser() {
return this.options.getUser('user');
}

/**
* The member this interaction was sent from
* @type {?(GuildMember|APIGuildMember)}
* @readonly
*/
get targetMember() {
return this.options.getMember(this.targetId);
GrapeColor marked this conversation as resolved.
Show resolved Hide resolved
}
}

module.exports = UserContextMenuInteraction;
17 changes: 17 additions & 0 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,21 @@ export class ContextMenuInteraction<Cached extends CacheType = CacheType> extend
private resolveContextMenuOptions(data: APIApplicationCommandInteractionData): CommandInteractionOption<Cached>[];
}

export class UserContextMenuInteracion<Cached extends CacheType = CacheType> extends ContextMenuInteraction<Cached> {
public targetUser: User;
public targetMember: CacheTypeReducer<Cached, GuildMember, APIInteractionGuildMember>;
public inGuild(): this is UserContextMenuInteracion<'present'>;
public inCachedGuild(): this is UserContextMenuInteracion<'cached'>;
public inRawGuild(): this is UserContextMenuInteracion<'raw'>;
}

export class MessageContextMenuInteracion<Cached extends CacheType = CacheType> extends ContextMenuInteraction<Cached> {
public targetMessage: CacheTypeReducer<Cached, Message, APIMessage>;
public inGuild(): this is MessageContextMenuInteracion<'present'>;
public inCachedGuild(): this is MessageContextMenuInteracion<'cached'>;
public inRawGuild(): this is MessageContextMenuInteracion<'raw'>;
}

export class DataResolver extends null {
private constructor();
public static resolveBase64(data: Base64Resolvable): string;
Expand Down Expand Up @@ -1217,6 +1232,8 @@ export class Interaction<Cached extends CacheType = CacheType> extends Base {
public isCommand(): this is CommandInteraction<Cached>;
public isAutocomplete(): this is AutocompleteInteraction<Cached>;
public isContextMenu(): this is ContextMenuInteraction<Cached>;
public isUserContextMenu(): this is UserContextMenuInteracion<Cached>;
public isMessageContextMenu(): this is MessageContextMenuInteracion<Cached>;
public isMessageComponent(): this is MessageComponentInteraction<Cached>;
public isSelectMenu(): this is SelectMenuInteraction<Cached>;
}
Expand Down