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 10 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
7 changes: 5 additions & 2 deletions src/client/actions/InteractionCreate.js
Expand Up @@ -4,8 +4,9 @@ const Action = require('./Action');
const AutocompleteInteraction = require('../../structures/AutocompleteInteraction');
const ButtonInteraction = require('../../structures/ButtonInteraction');
const CommandInteraction = require('../../structures/CommandInteraction');
const ContextMenuInteraction = require('../../structures/ContextMenuInteraction');
const MessageContextMenuInteraction = require('../../structures/MessageContextMenuInteraction');
const SelectMenuInteraction = require('../../structures/SelectMenuInteraction');
const UserContextMenuInteraction = require('../../structures/UserContextMenuInteraction');
const { Events, InteractionTypes, MessageComponentTypes, ApplicationCommandTypes } = require('../../util/Constants');

let deprecationEmitted = false;
Expand All @@ -25,8 +26,10 @@ class InteractionCreateAction extends Action {
InteractionType = CommandInteraction;
break;
case ApplicationCommandTypes.USER:
InteractionType = UserContextMenuInteraction;
break;
case ApplicationCommandTypes.MESSAGE:
InteractionType = ContextMenuInteraction;
InteractionType = MessageContextMenuInteraction;
break;
default:
client.emit(
Expand Down
18 changes: 17 additions & 1 deletion src/structures/Interaction.js
@@ -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
@@ -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
@@ -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('user');
}
}

module.exports = UserContextMenuInteraction;
17 changes: 17 additions & 0 deletions typings/index.d.ts
Expand Up @@ -1217,6 +1217,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 Expand Up @@ -1526,6 +1528,13 @@ export class MessageComponentInteraction<Cached extends CacheType = CacheType> e
public static resolveType(type: MessageComponentTypeResolvable): MessageComponentType;
}

export class MessageContextMenuInteracion<Cached extends CacheType = CacheType> extends ContextMenuInteraction<Cached> {
GrapeColor marked this conversation as resolved.
Show resolved Hide resolved
public targetMessage: CacheTypeReducer<Cached, Message, APIMessage>;
GrapeColor marked this conversation as resolved.
Show resolved Hide resolved
public inGuild(): this is MessageContextMenuInteracion<'present'>;
public inCachedGuild(): this is MessageContextMenuInteracion<'cached'>;
public inRawGuild(): this is MessageContextMenuInteracion<'raw'>;
}

export class MessageEmbed {
private _fieldEquals(field: EmbedField, other: EmbedField): boolean;

Expand Down Expand Up @@ -2169,6 +2178,14 @@ export class User extends PartialTextBasedChannel(Base) {
public toString(): UserMention;
}

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

export class UserFlags extends BitField<UserFlagsString> {
public static FLAGS: Record<UserFlagsString, number>;
public static resolve(bit?: BitFieldResolvable<UserFlagsString, number>): number;
Expand Down