Skip to content

Commit

Permalink
use raw messages when interaction messages are ephemeral
Browse files Browse the repository at this point in the history
  • Loading branch information
TTtie committed Aug 11, 2021
1 parent 4415d02 commit 023cfc9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
5 changes: 3 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ declare namespace Eris {
type MessageContent = string | AdvancedMessageContent;
type MFALevel = 0 | 1;
type PossiblyUncachedMessage = Message | { channel: TextableChannel | { id: string; guild?: Uncached }; guildID?: string; id: string };
type PossiblyEphemeralMessage = Message | { id: string; flags: number };

// Interaction
type InteractionDataOptions = {
Expand Down Expand Up @@ -2373,7 +2374,7 @@ declare namespace Eris {
};
guildID?: string;
member?: Member;
message: Message;
message: PossiblyEphemeralMessage;
user?: User;
acknowledge(): Promise<void>;
createFollowup(content: string | InteractionWebhookContent): Promise<Message>;
Expand All @@ -2393,7 +2394,7 @@ declare namespace Eris {
data?: unknown;
guildID?: string;
member?: Member;
message?: Message;
message?: PossiblyEphemeralMessage;
type: number;
user?: User;
createFollowup(content: string | InteractionWebhookContent): Promise<Message>;
Expand Down
10 changes: 7 additions & 3 deletions lib/structures/ComponentInteraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const Interaction = require("./Interaction");
const Message = require("./Message");
const Member = require("./Member");
const User = require("./User");
const {InteractionResponseTypes} = require("../Constants");
const {InteractionResponseTypes, InteractionFlags} = require("../Constants");

/**
* Represents a message component interaction. See Interaction for more properties.
Expand All @@ -16,7 +16,7 @@ const {InteractionResponseTypes} = require("../Constants");
* @prop {Array<String>?} data.values The value of the run selected options (Select Menus Only)
* @prop {String?} guildID The ID of the guild in which the interaction was created
* @prop {Member?} member The member who triggered the interaction (This is only sent when the interaction is invoked within a guild)
* @prop {Message} message The message the interaction came from
* @prop {Message?} message The message the interaction came from. If the message is ephemeral, this will be an object with `id` and `flags` keys.
* @prop {User?} user The user who triggered the interaction (This is only sent when the interaction is invoked within a dm)
*/
class ComponentInteraction extends Interaction {
Expand All @@ -38,7 +38,11 @@ class ComponentInteraction extends Interaction {
}

if(data.message !== undefined) {
this.message = new Message(data.message, this._client);
if(data.message.flags === InteractionFlags.EPHEMERAL) {
this.message = data.message;
} else {
this.message = new Message(data.message, this._client);
}
}

if(data.user !== undefined) {
Expand Down
10 changes: 7 additions & 3 deletions lib/structures/UnknownInteraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const Interaction = require("./Interaction");
const Message = require("./Message");
const Member = require("./Member");
const User = require("./User");
const {InteractionResponseTypes} = require("../Constants");
const {InteractionResponseTypes, InteractionFlags} = require("../Constants");

/**
* Represents an unknown interaction. See Interaction for more properties.
Expand All @@ -13,7 +13,7 @@ const {InteractionResponseTypes} = require("../Constants");
* @prop {Object?} data The data attached to the interaction
* @prop {String?} guildID The ID of the guild in which the interaction was created
* @prop {Member?} member The member who triggered the interaction (This is only sent when the interaction is invoked within a guild)
* @prop {Message?} message The message the interaction came from (Message Component only)
* @prop {Message?} message The message the interaction came from (Message Component only). If the message is ephemeral, this will be an object with `id` and `flags` keys.
* @prop {User?} user The user who triggered the interaction (This is only sent when the interaction is invoked within a dm)
*/
class UnknownInteraction extends Interaction {
Expand All @@ -37,7 +37,11 @@ class UnknownInteraction extends Interaction {
}

if(data.message !== undefined) {
this.message = new Message(data.message, this._client);
if(data.message.flags === InteractionFlags.EPHEMERAL) {
this.message = data.message;
} else {
this.message = new Message(data.message, this._client);
}
}

if(data.user !== undefined) {
Expand Down

0 comments on commit 023cfc9

Please sign in to comment.