From 2cdb671fb142421c6cc24e5aa312dd05fa3991ba Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Wed, 28 Apr 2021 16:54:22 +0530 Subject: [PATCH] interactions api design fix --- mod.ts | 2 - src/gateway/handlers/interactionCreate.ts | 9 ----- src/gateway/handlers/mod.ts | 8 +--- src/interactions/slashClient.ts | 6 +-- src/managers/_util.ts | 19 ---------- src/managers/channels.ts | 9 ----- src/structures/interactions.ts | 21 ++--------- src/structures/messageComponents.ts | 42 --------------------- src/types/channel.ts | 8 ---- src/types/interactions.ts | 11 +----- src/types/messageComponents.ts | 45 ----------------------- src/utils/interactions.ts | 7 ---- 12 files changed, 7 insertions(+), 180 deletions(-) delete mode 100644 src/structures/messageComponents.ts delete mode 100644 src/types/messageComponents.ts diff --git a/mod.ts b/mod.ts index 5df0bbb..c7caa24 100644 --- a/mod.ts +++ b/mod.ts @@ -40,10 +40,8 @@ export { GuildManager } from './src/managers/guilds.ts' export * from './src/structures/base.ts' export * from './src/structures/slash.ts' export * from './src/structures/interactions.ts' -export * from './src/structures/messageComponents.ts' export * from './src/types/slashCommands.ts' export * from './src/types/interactions.ts' -export * from './src/types/messageComponents.ts' export { GuildEmojisManager } from './src/managers/guildEmojis.ts' export { MembersManager } from './src/managers/members.ts' export { MessageReactionsManager } from './src/managers/messageReactions.ts' diff --git a/src/gateway/handlers/interactionCreate.ts b/src/gateway/handlers/interactionCreate.ts index f99c7e1..e533a5e 100644 --- a/src/gateway/handlers/interactionCreate.ts +++ b/src/gateway/handlers/interactionCreate.ts @@ -22,7 +22,6 @@ import { RolePayload } from '../../types/role.ts' import { InteractionChannelPayload } from '../../types/slashCommands.ts' import { Message } from '../../structures/message.ts' import { TextChannel } from '../../structures/textChannel.ts' -import { MessageComponentInteraction } from '../../structures/messageComponents.ts' export const interactionCreate: GatewayEventHandler = async ( gateway: Gateway, @@ -156,14 +155,6 @@ export const interactionCreate: GatewayEventHandler = async ( user, resolved }) - } else if (d.type === InteractionType.MESSAGE_COMPONENT) { - interaction = new MessageComponentInteraction(gateway.client, d, { - member, - guild, - channel, - user, - message - }) } else { interaction = new Interaction(gateway.client, d, { member, diff --git a/src/gateway/handlers/mod.ts b/src/gateway/handlers/mod.ts index 561c898..dc649e8 100644 --- a/src/gateway/handlers/mod.ts +++ b/src/gateway/handlers/mod.ts @@ -69,7 +69,6 @@ import { applicationCommandCreate } from './applicationCommandCreate.ts' import { applicationCommandDelete } from './applicationCommandDelete.ts' import { applicationCommandUpdate } from './applicationCommandUpdate.ts' import type { SlashCommand } from '../../interactions/slashCommand.ts' -import { MessageComponentInteraction } from '../../structures/messageComponents.ts' export const gatewayHandlers: { [eventCode in GatewayEvents]: GatewayEventHandler | undefined @@ -365,12 +364,7 @@ export type ClientEvents = { * An Interaction was created * @param interaction Created interaction object */ - interactionCreate: [ - interaction: - | Interaction - | SlashCommandInteraction - | MessageComponentInteraction - ] + interactionCreate: [interaction: Interaction | SlashCommandInteraction] /** * When debug message was made diff --git a/src/interactions/slashClient.ts b/src/interactions/slashClient.ts index a34c0c8..4db556a 100644 --- a/src/interactions/slashClient.ts +++ b/src/interactions/slashClient.ts @@ -17,7 +17,6 @@ import { User } from '../structures/user.ts' import { HarmonyEventEmitter } from '../utils/events.ts' import { encodeText, decodeText } from '../utils/encoding.ts' import { SlashCommandsManager } from './slashCommand.ts' -import { MessageComponentInteraction } from '../structures/messageComponents.ts' export type SlashCommandHandlerCallback = ( interaction: SlashCommandInteraction @@ -203,10 +202,7 @@ export class SlashClient extends HarmonyEventEmitter { /** Process an incoming Interaction */ private async _process( - interaction: - | Interaction - | SlashCommandInteraction - | MessageComponentInteraction + interaction: Interaction | SlashCommandInteraction ): Promise { if (!this.enabled) return diff --git a/src/managers/_util.ts b/src/managers/_util.ts index 8b5b670..e69de29 100644 --- a/src/managers/_util.ts +++ b/src/managers/_util.ts @@ -1,19 +0,0 @@ -import { - MessageComponentData, - MessageComponentPayload -} from '../types/messageComponents.ts' - -export function transformComponent( - d: MessageComponentData[] -): MessageComponentPayload[] { - return d.map((e: any) => { - if (e.customID !== undefined) { - e.custom_id = e.customID - delete e.customID - } - if (e.components !== undefined) { - e.components = transformComponent(e.components) - } - return e - }) -} diff --git a/src/managers/channels.ts b/src/managers/channels.ts index 6810ecb..69efe6c 100644 --- a/src/managers/channels.ts +++ b/src/managers/channels.ts @@ -11,7 +11,6 @@ import type { import { CHANNEL } from '../types/endpoint.ts' import getChannelByType from '../utils/channel.ts' import { BaseManager } from './base.ts' -import { transformComponent } from './_util.ts' export type AllMessageOptions = MessageOptions | Embed @@ -101,10 +100,6 @@ export class ChannelsManager extends BaseManager { content: content, embed: option?.embed, file: option?.file, - components: - option?.components !== undefined - ? transformComponent(option.components) - : undefined, files: option?.files, tts: option?.tts, allowed_mentions: option?.allowedMentions, @@ -172,10 +167,6 @@ export class ChannelsManager extends BaseManager { embed: option?.embed !== undefined ? option.embed.toJSON() : undefined, // Cannot upload new files with Message // file: option?.file, - components: - option?.components !== undefined - ? transformComponent(option.components) - : undefined, tts: option?.tts, allowed_mentions: option?.allowedMentions }) diff --git a/src/structures/interactions.ts b/src/structures/interactions.ts index f848012..86001e9 100644 --- a/src/structures/interactions.ts +++ b/src/structures/interactions.ts @@ -1,5 +1,4 @@ import type { Client } from '../client/client.ts' -import { transformComponent } from '../managers/_util.ts' import { AllowedMentionsPayload, ChannelTypes, @@ -14,10 +13,6 @@ import { InteractionResponseType, InteractionType } from '../types/interactions.ts' -import { - InteractionMessageComponentData, - MessageComponentData -} from '../types/messageComponents.ts' import { InteractionApplicationCommandData, InteractionChannelPayload @@ -50,7 +45,6 @@ export interface InteractionMessageOptions { allowedMentions?: AllowedMentionsPayload /** Whether the Message Response should be Ephemeral (only visible to User) or not */ ephemeral?: boolean - components?: MessageComponentData[] } export interface InteractionResponse extends InteractionMessageOptions { @@ -107,7 +101,7 @@ export class Interaction extends SnowflakeBase { _httpResponded?: boolean applicationID: string /** Data sent with Interaction. Only applies to Application Command */ - data?: InteractionApplicationCommandData | InteractionMessageComponentData + data?: InteractionApplicationCommandData message?: Message constructor( @@ -154,11 +148,7 @@ export class Interaction extends SnowflakeBase { embeds: data.embeds, tts: data.tts ?? false, flags, - allowed_mentions: data.allowedMentions ?? undefined, - components: - data.components === undefined - ? undefined - : transformComponent(data.components) + allowed_mentions: data.allowedMentions ?? undefined } : undefined } @@ -231,7 +221,6 @@ export class Interaction extends SnowflakeBase { embeds?: Array flags?: number | number[] allowedMentions?: AllowedMentionsPayload - components?: MessageComponentData[] }): Promise { const url = WEBHOOK_MESSAGE(this.applicationID, this.token, '@original') await this.client.rest.patch(url, { @@ -241,11 +230,7 @@ export class Interaction extends SnowflakeBase { typeof data.flags === 'object' ? data.flags.reduce((p, a) => p | a, 0) : data.flags, - allowed_mentions: data.allowedMentions, - components: - data.components === undefined - ? undefined - : transformComponent(data.components) + allowed_mentions: data.allowedMentions }) return this } diff --git a/src/structures/messageComponents.ts b/src/structures/messageComponents.ts deleted file mode 100644 index 1e47bd3..0000000 --- a/src/structures/messageComponents.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { - InteractionMessageComponentData, - MessageComponentType -} from '../types/messageComponents.ts' -import { Interaction } from './interactions.ts' -import type { Client } from '../client/mod.ts' -import { InteractionPayload } from '../types/interactions.ts' -import type { Guild } from './guild.ts' -import type { GuildTextChannel } from './guildTextChannel.ts' -import type { Member } from './member.ts' -import type { TextChannel } from './textChannel.ts' -import { User } from './user.ts' -import { Message } from './message.ts' - -export class MessageComponentInteraction extends Interaction { - data: InteractionMessageComponentData - declare message: Message - - constructor( - client: Client, - data: InteractionPayload, - others: { - channel?: TextChannel | GuildTextChannel - guild?: Guild - member?: Member - user: User - message?: Message - } - ) { - super(client, data, others) - // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion - this.data = data.data as InteractionMessageComponentData - } - - get customID(): string { - return this.data.custom_id - } - - get componentType(): MessageComponentType { - return this.data.component_type - } -} diff --git a/src/types/channel.ts b/src/types/channel.ts index f6542b5..25eb484 100644 --- a/src/types/channel.ts +++ b/src/types/channel.ts @@ -7,10 +7,6 @@ import type { EmojiPayload } from './emoji.ts' import type { MemberPayload } from './guild.ts' import type { InteractionType } from './interactions.ts' import type { UserPayload } from './user.ts' -import type { - MessageComponentData, - MessageComponentPayload -} from './messageComponents.ts' export interface ChannelPayload { id: string @@ -192,7 +188,6 @@ export interface MessagePayload { flags?: number stickers?: MessageStickerPayload[] interaction?: MessageInteractionPayload - components?: MessageComponentPayload[] } export enum AllowedMentionType { @@ -215,7 +210,6 @@ export interface MessageOptions { files?: MessageAttachment[] allowedMentions?: AllowedMentionsPayload reply?: Message | MessageReference | string - components?: MessageComponentData[] } export interface ChannelMention { @@ -399,7 +393,6 @@ export interface EditMessagePayload { embed?: EmbedPayload allowed_mentions?: AllowedMentionsPayload flags?: number - components?: MessageComponentPayload[] } export interface CreateMessagePayload extends EditMessagePayload { @@ -408,7 +401,6 @@ export interface CreateMessagePayload extends EditMessagePayload { message_reference?: MessageReference file?: MessageAttachment files?: MessageAttachment[] - components?: MessageComponentPayload[] } export interface CreateWebhookMessageBasePayload { diff --git a/src/types/interactions.ts b/src/types/interactions.ts index 01c12a4..e4d4d94 100644 --- a/src/types/interactions.ts +++ b/src/types/interactions.ts @@ -4,10 +4,6 @@ import { MessagePayload } from './channel.ts' import type { MemberPayload } from './guild.ts' -import { - InteractionMessageComponentData, - MessageComponentData -} from './messageComponents.ts' import type { InteractionApplicationCommandData } from './slashCommands.ts' import type { UserPayload } from './user.ts' @@ -15,9 +11,7 @@ export enum InteractionType { /** Ping sent by the API (HTTP-only) */ PING = 1, /** Slash Command Interaction */ - APPLICATION_COMMAND = 2, - /** Message Component Interaction */ - MESSAGE_COMPONENT = 3 + APPLICATION_COMMAND = 2 } export interface InteractionMemberPayload extends MemberPayload { @@ -39,7 +33,7 @@ export interface InteractionPayload { /** * Data sent with the interaction. Undefined only when Interaction is PING (http-only).* */ - data?: InteractionApplicationCommandData | InteractionMessageComponentData + data?: InteractionApplicationCommandData /** ID of the Guild in which Interaction was invoked */ guild_id?: string /** ID of the Channel in which Interaction was invoked */ @@ -75,7 +69,6 @@ export interface InteractionResponseDataPayload { /** Allowed Mentions object */ allowed_mentions?: AllowedMentionsPayload flags?: number - components?: MessageComponentData[] } export enum InteractionResponseFlags { diff --git a/src/types/messageComponents.ts b/src/types/messageComponents.ts deleted file mode 100644 index 3a0b21f..0000000 --- a/src/types/messageComponents.ts +++ /dev/null @@ -1,45 +0,0 @@ -export enum MessageComponentType { - ActionRow = 1, - Button = 2 -} - -export enum ButtonStyle { - Primary = 1, - Secondary = 2, - Success = 3, - Destructive = 4, - Link = 5 -} - -export interface MessageComponentEmoji { - id?: string - name?: string - animated?: boolean -} - -export interface MessageComponentPayload { - type: MessageComponentType - components?: MessageComponentPayload[] - label?: string - style?: ButtonStyle - url?: string - custom_id?: string - emoji?: MessageComponentEmoji - disabled?: boolean -} - -export interface MessageComponentData { - type: MessageComponentType - components?: MessageComponentData[] - label?: string - style?: ButtonStyle - url?: string - customID?: string - emoji?: MessageComponentEmoji - disabled?: boolean -} - -export interface InteractionMessageComponentData { - custom_id: string - component_type: MessageComponentType -} diff --git a/src/utils/interactions.ts b/src/utils/interactions.ts index 0849e72..c5d4249 100644 --- a/src/utils/interactions.ts +++ b/src/utils/interactions.ts @@ -1,6 +1,5 @@ import { InteractionType } from '../../mod.ts' import { Interaction } from '../structures/interactions.ts' -import { MessageComponentInteraction } from '../structures/messageComponents.ts' import { SlashCommandInteraction } from '../structures/slash.ts' export function isSlashCommandInteraction( @@ -8,9 +7,3 @@ export function isSlashCommandInteraction( ): d is SlashCommandInteraction { return d.type === InteractionType.APPLICATION_COMMAND } - -export function isMessageComponentInteraction( - d: Interaction -): d is MessageComponentInteraction { - return d.type === InteractionType.MESSAGE_COMPONENT -}