Skip to content
This repository has been archived by the owner on Aug 24, 2022. It is now read-only.

Commit

Permalink
Remote Update (v9-components-interactions, pr abalabahaha#58): catboi…
Browse files Browse the repository at this point in the history
…8/interactions
  • Loading branch information
DonovanDMC committed Aug 14, 2021
2 parents e5edbda + 3171d82 commit 9f05801
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 11 deletions.
5 changes: 2 additions & 3 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ declare namespace Eris {
type MessageContentEdit = string | AdvancedMessageContentEdit;
type MFALevel = 0 | 1;
type PossiblyUncachedMessage = Message | { channel: TextableChannel | { id: string; guild?: Uncached }; guildID?: string; id: string };
type PossiblyEphemeralMessage = Message | { id: string; flags: 64 };

// Interaction
type InteractionDataOptions = {
Expand Down Expand Up @@ -2539,7 +2538,7 @@ declare namespace Eris {
};
guildID?: string;
member?: Member;
message: PossiblyEphemeralMessage;
message: Message;
user?: User;
acknowledge(): Promise<void>;
createFollowup(content: string | InteractionWebhookContent): Promise<Message>;
Expand All @@ -2559,7 +2558,7 @@ declare namespace Eris {
data?: unknown;
guildID?: string;
member?: Member;
message?: PossiblyEphemeralMessage;
message?: Message;
type: number;
user?: User;
createFollowup(content: string | InteractionWebhookContent): Promise<Message>;
Expand Down
10 changes: 3 additions & 7 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, MessageFlags} = require("../Constants");
const {InteractionResponseTypes} = require("../Constants");

/**
* Represents a message component interaction. See Interaction for more properties.
Expand All @@ -16,7 +16,7 @@ const {InteractionResponseTypes, MessageFlags} = 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. If the message is ephemeral, this will be an object with `id` and `flags` keys.
* @prop {Message?} message The message the interaction came from.
* @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,11 +38,7 @@ class ComponentInteraction extends Interaction {
}

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

if(data.user !== undefined) {
Expand Down
35 changes: 34 additions & 1 deletion lib/structures/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const Base = require("./Base");
const Endpoints = require("../rest/Endpoints");
const Call = require("./Call");
const {SystemJoinMessages, MessageTypes} = require("../Constants");
const {SystemJoinMessages, MessageTypes, MessageFlags} = require("../Constants");
const User = require("./User");

/**
Expand Down Expand Up @@ -383,6 +383,9 @@ class Message extends Base {
* @returns {Promise}
*/
addReaction(reaction, userID) {
if(this.flags & MessageFlags.EPHEMERAL) {
throw new Error("Ephemeral messages cannot have reactions");
}
return this._client.addMessageReaction.call(this._client, this.channel.id, this.id, reaction, userID);
}

Expand All @@ -402,6 +405,9 @@ class Message extends Base {
* @returns {Promise<Message>}
*/
crosspost() {
if(this.flags & MessageFlags.EPHEMERAL) {
throw new Error("Ephemeral messages cannot be crossposted");
}
return this._client.crosspostMessage.call(this._client, this.channel.id, this.id);
}

Expand All @@ -411,6 +417,9 @@ class Message extends Base {
* @returns {Promise}
*/
delete(reason) {
if(this.flags & MessageFlags.EPHEMERAL) {
throw new Error("Ephemeral messages cannot be deleted");
}
return this._client.deleteMessage.call(this._client, this.channel.id, this.id, reason);
}

Expand All @@ -423,6 +432,9 @@ class Message extends Base {
if(!this.webhookID) {
throw new Error("Message is not a webhook");
}
if(this.flags & MessageFlags.EPHEMERAL) {
throw new Error("Ephemeral messages cannot be deleted");
}
return this._client.deleteWebhookMessage.call(this._client, this.webhookID, token, this.id);
}

Expand Down Expand Up @@ -464,6 +476,9 @@ class Message extends Base {
* @returns {Promise<Message>}
*/
edit(content) {
if(this.flags & MessageFlags.EPHEMERAL) {
throw new Error("Ephemeral messages cannot be edited via this method");
}
return this._client.editMessage.call(this._client, this.channel.id, this.id, content);
}

Expand Down Expand Up @@ -518,6 +533,9 @@ class Message extends Base {
* @returns {Promise<Array<User>>}
*/
getReaction(reaction, options, before, after) {
if(this.flags & MessageFlags.EPHEMERAL) {
throw new Error("Ephemeral messages cannot have reactions");
}
return this._client.getMessageReaction.call(this._client, this.channel.id, this.id, reaction, options, before, after);
}

Expand All @@ -526,6 +544,9 @@ class Message extends Base {
* @returns {Promise}
*/
pin() {
if(this.flags & MessageFlags.EPHEMERAL) {
throw new Error("Ephemeral messages cannot be pinned");
}
return this._client.pinMessage.call(this._client, this.channel.id, this.id);
}

Expand All @@ -536,6 +557,9 @@ class Message extends Base {
* @returns {Promise}
*/
removeReaction(reaction, userID) {
if(this.flags & MessageFlags.EPHEMERAL) {
throw new Error("Ephemeral messages cannot have reactions");
}
return this._client.removeMessageReaction.call(this._client, this.channel.id, this.id, reaction, userID);
}

Expand All @@ -545,6 +569,9 @@ class Message extends Base {
* @returns {Promise}
*/
removeReactionEmoji(reaction) {
if(this.flags & MessageFlags.EPHEMERAL) {
throw new Error("Ephemeral messages cannot have reactions");
}
return this._client.removeMessageReactionEmoji.call(this._client, this.channel.id, this.id, reaction);
}

Expand All @@ -553,6 +580,9 @@ class Message extends Base {
* @returns {Promise}
*/
removeReactions() {
if(this.flags & MessageFlags.EPHEMERAL) {
throw new Error("Ephemeral messages cannot have reactions");
}
return this._client.removeMessageReactions.call(this._client, this.channel.id, this.id);
}

Expand All @@ -561,6 +591,9 @@ class Message extends Base {
* @returns {Promise}
*/
unpin() {
if(this.flags & MessageFlags.EPHEMERAL) {
throw new Error("Ephemeral messages cannot be pinned");
}
return this._client.unpinMessage.call(this._client, this.channel.id, this.id);
}

Expand Down

0 comments on commit 9f05801

Please sign in to comment.