Skip to content

Commit

Permalink
Add Message#interaction (#1167)
Browse files Browse the repository at this point in the history
  • Loading branch information
Snazzah authored Apr 14, 2021
1 parent c152aac commit 5837a31
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
9 changes: 9 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ declare namespace Eris {
type ImageFormat = "jpg" | "jpeg" | "png" | "gif" | "webp";
type MessageContent = string | AdvancedMessageContent;
type PossiblyUncachedMessage = Message | { channel: TextableChannel | { id: string; guild?: { id: string } }; guildID?: string; id: string };
type InteractionType = 1 | 2;

// Permission
type PermissionType = "role" | "member";
Expand Down Expand Up @@ -801,6 +802,13 @@ declare namespace Eris {
preview_asset?: string;
format_type: Constants["StickerFormats"][keyof Constants["StickerFormats"]];
}
interface MessageInteraction {
id: string;
type: InteractionType;
name: string;
user: User;
member: Member | null;
}

// Presence
interface Activity extends ActivityPartial<ActivityType> {
Expand Down Expand Up @@ -2130,6 +2138,7 @@ declare namespace Eris {
referencedMessage?: Message | null;
roleMentions: string[];
stickers?: Sticker[];
interaction: MessageInteraction | null;
timestamp: number;
tts: boolean;
type: number;
Expand Down
30 changes: 30 additions & 0 deletions lib/structures/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ const User = require("./User");
* @prop {String?} messageReference.messageID The id of the original message this message was crossposted from
* @prop {String} messageReference.channelID The id of the channel this message was crossposted from
* @prop {String?} messageReference.guildID The id of the guild this message was crossposted from
* @prop {Object?} interaction An object containing info about the interaction the message is responding to, if applicable
* @prop {String} interaction.id The id of the interaction
* @prop {Number} interaction.type The type of interaction
* @prop {User} interaction.user The user who invoked the interaction
* @prop {Member?} interaction.member The member who invoked the interaction
* @prop {Boolean} pinned Whether the message is pinned or not
* @prop {String?} prefix The prefix used in the Message, if any (CommandClient only)
* @prop {Object} reactions An object containing the reactions on the message. Each key is a reaction emoji and each value is an object with properties `me` (Boolean) and `count` (Number) for that specific reaction emoji.
Expand Down Expand Up @@ -89,6 +94,31 @@ class Message extends Base {
} else {
this.referencedMessage = data.referenced_message;
}
if(data.interaction) {
let interactionUser, interactionMember;
if(data.interaction.user.discriminator !== "0000") {
interactionUser = client.users.update(data.interaction.user, client);
} else {
interactionUser = new User(data.interaction.user, client);
}
if(data.interaction.member) {
data.interaction.member.id = data.interaction.user.id;
interactionMember = this.channel.guild.members.update(data.interaction.member, this.channel.guild);
} else if(this.channel.guild && this.channel.guild.members.has(data.interaction.user.id)) {
interactionMember = this.channel.guild.members.get(data.interaction.user.id);
} else {
interactionMember = null;
}
this.interaction = {
id: data.interaction.id,
type: data.interaction.type,
name: data.interaction.name,
user: interactionUser,
member: interactionMember
};
} else {
this.interaction = null;
}
if(this.channel.guild) {
if(data.member) {
data.member.id = this.author.id;
Expand Down

0 comments on commit 5837a31

Please sign in to comment.