Skip to content

Commit

Permalink
Undo last commit
Browse files Browse the repository at this point in the history
  • Loading branch information
JustCat80 committed Aug 30, 2021
1 parent f303ae3 commit 7e19c81
Show file tree
Hide file tree
Showing 6 changed files with 442 additions and 25 deletions.
2 changes: 1 addition & 1 deletion esm.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export const {
GuildIntegration,
GuildPreview,
GuildTemplate,
Interaction,
Invite,
Member,
Message,
Expand All @@ -44,6 +43,7 @@ export const {
StoreChannel,
TextChannel,
UnavailableGuild,
UnknownInteraction,
User,
VERSION,
VoiceChannel,
Expand Down
25 changes: 22 additions & 3 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ declare namespace Eris {
guildUnavailable: [guild: UnavailableGuild];
guildUpdate: [guild: Guild, oldGuild: OldGuild];
hello: [trace: string[], id: number];
interactionCreate: [interaction: PingInteraction | CommandInteraction | ComponentInteraction | Interaction];
interactionCreate: [interaction: PingInteraction | CommandInteraction | ComponentInteraction | UnknownInteraction];
inviteCreate: [guild: Guild, invite: Invite];
inviteDelete: [guild: Guild, invite: Invite];
messageCreate: [message: Message<PossiblyUncachedTextableChannel>];
Expand Down Expand Up @@ -2449,15 +2449,13 @@ declare namespace Eris {
export class Interaction extends Base {
acknowledged: boolean;
applicationID: string;
data?: unknown;
id: string;
token: string;
type: number;
version: number;
}

export class PingInteraction extends Interaction {
data: undefined;
type: Constants["InteractionTypes"]["PING"];
acknowledge(): Promise<void>;
pong(): Promise<void>;
Expand Down Expand Up @@ -2526,6 +2524,27 @@ declare namespace Eris {
getOriginalMessage(): Promise<Message>
}

export class UnknownInteraction<T extends PossiblyUncachedTextable = TextableChannel> extends Interaction {
channel?: T;
data?: unknown;
guildID?: string;
member?: Member;
message?: Message;
type: number;
user?: User;
createFollowup(content: string | InteractionWebhookContent): Promise<Message>;
createMessage(content: string | InteractionContent | InteractionWebhookContent): Promise<void>;
defer(flags?: number): Promise<void>;
deferUpdate(): Promise<void>;
deleteMessage(messageID: string): Promise<void>;
deleteOriginalMessage(): Promise<void>;
editMessage(messageID: string, content: string | MessageWebhookContent): Promise<Message>;
editOriginalMessage(content: string | MessageWebhookContent): Promise<Message>;
editParent(content: MessageWebhookContent): Promise<Message>;
getOriginalMessage(): Promise<Message>
pong(): Promise<void>;
}

// If CT (count) is "withMetadata", it will not have count properties
export class Invite<CT extends "withMetadata" | "withCount" | "withoutCount" = "withMetadata", CH extends InviteChannel = InviteChannel> extends Base {
channel: CH;
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Eris.SharedStream = require("./lib/voice/SharedStream");
Eris.StoreChannel = require("./lib/structures/StoreChannel");
Eris.TextChannel = require("./lib/structures/TextChannel");
Eris.UnavailableGuild = require("./lib/structures/UnavailableGuild");
Eris.Interaction = require("./lib/structures/Interaction");
Eris.UnknownInteraction = require("./lib/structures/UnknownInteraction");
Eris.User = require("./lib/structures/User");
Eris.VERSION = require("./package.json").version;
Eris.VoiceChannel = require("./lib/structures/VoiceChannel");
Expand Down
2 changes: 1 addition & 1 deletion lib/gateway/Shard.js
Original file line number Diff line number Diff line change
Expand Up @@ -2082,7 +2082,7 @@ class Shard extends EventEmitter {
/**
* Fired when an interaction is created
* @event Client#interactionCreate
* @prop {PingInteraction | CommandInteraction | ComponentInteraction | Interaction} Interaction Interaction that was created
* @prop {PingInteraction | CommandInteraction | ComponentInteraction | UnknownInteraction} Interaction Interaction that was created
*/
this.emit("interactionCreate", Interaction.from(packet.d, this.client));
break;
Expand Down
34 changes: 15 additions & 19 deletions lib/structures/Interaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,44 @@ const Base = require("./Base");
const {InteractionTypes} = require("../Constants");

/**
* Represents an interaction. You also probably want to look at PingInteraction, CommandInteraction, and ComponentInteraction.
* Represents an interaction. You also probably want to look at PingInteraction, CommandInteraction, ComponentInteraction, and UnknownInteraction.
* @prop {Boolean} acknowledged Whether or not the interaction has been acknowledged
* @prop {String} applicationID The ID of the interaction's application
* @prop {Object?} data The data attached to the interaction. Check CommandInteraction and ComponentInteraction for specifics
* @prop {String} id The ID of the interaction
* @prop {String} token The interaction token (Interaction tokens are valid for 15 minutes after initial response and can be used to send followup messages but you must send an initial response within 3 seconds of receiving the event. If the 3 second deadline is exceeded, the token will be invalidated.)
* @prop {Number} type 1 is a Ping, 2 is an Application Command, 3 is a Message Component
* @prop {Number} version The interaction version
*/
class Interaction extends Base {
constructor(info, client) {
super(info.id);
constructor(data, client) {
super(data.id);
this._client = client;

this.applicationID = info.application_id;
this.token = info.token;
this.type = info.type;
this.version = info.version;
this.applicationID = data.application_id;
this.token = data.token;
this.type = data.type;
this.version = data.version;
this.acknowledged = false;

if(info.data !== undefined) {
this.data = info.data;
}
}
update() {
this.acknowledged = true;
}

static from(info, client) {
switch(info.type) {
static from(data, client) {
switch(data.type) {
case InteractionTypes.PING: {
return new PingInteraction(info, client);
return new PingInteraction(data, client);
}
case InteractionTypes.APPLICATION_COMMAND: {
return new CommandInteraction(info, client);
return new CommandInteraction(data, client);
}
case InteractionTypes.MESSAGE_COMPONENT: {
return new ComponentInteraction(info, client);
return new ComponentInteraction(data, client);
}
}

this._client.emit("warn", new Error(`Unknown interaction type: ${info.type}\n${JSON.stringify(info)}`));
return new Interaction(info, client);
this._client.emit("warn", new Error(`Unknown interaction type: ${data.type}\n${JSON.stringify(data)}`));
return new UnknownInteraction(data, client);
}
}

Expand All @@ -56,3 +51,4 @@ module.exports = Interaction;
const PingInteraction = require("./PingInteraction");
const CommandInteraction = require("./CommandInteraction");
const ComponentInteraction = require("./ComponentInteraction");
const UnknownInteraction = require("./UnknownInteraction");
Loading

0 comments on commit 7e19c81

Please sign in to comment.