Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Get up to date *again* (#156)
Co-authored-by: monbrey <rsm999@uowmail.edu.au> * Added `DiscordCertifiedModerator` flag to UserFlags * Updated types for Message Components * Added `disabled` to APISelectMenuCompponent * Cleaned up Buttons types, making them stricter based on the `style` you provide BREAKING CHANGE: `APISelectOption` has been renamed to `APISelectMenuOption` BREAKING CHANGE: APISelectMenuOption#default is now properly marked as optional * Updated OAuth2 Application types BREAKING CHANGE: `APIApplication#owner` is now marked as optional, per the docs * Correct APIAuditLogChangeKeyNick's key BREAKING CHANGE: This renames APIAuditLogChangeKeyNick's key from `mute` to `nick` * Add `application_id` to APIMessage * Correct type of `id` and `user_id` in APIThreadMember BREAKING CHANGE: The type of `id` and `user_id` in APIThreadMember are now marked as optional; read the TSDoc for when it's actually optional * Correctly version API route in RouteBases BREAKING CHANGE: This changes the `RouteBases.api` to be versioned based on the API version you're importing. **Make sure to update your code to handle that** * Added new guild features ref: 4d36e53 * Cleaned up interaction types BREAKING CHANGE: While this shouldn't be necessary, this is a warning that types for interactions HAVE changed and you may need to update your code. For the most part, the types *should* be the same, more accurate and strictly typed. You will also see that every type of interaction has a Guild/DM counterpart exported (ex: APIApplicationCommandGuildInteraction vs APIApplicationCommandInteraction, where the former has all the guild properties, while the latter has all properties that depend on context marked as optional). * Add TSD testing support in CI This is mostly useful for testing unions of types * Add message property to MessageComponent interactions
- Loading branch information
1 parent
ca933ae
commit 86e0736
Showing
57 changed files
with
7,102 additions
and
13,576 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import { Permissions, Snowflake } from '../../../globals.ts'; | ||
import { InteractionType } from '../../v8.ts'; | ||
import { APIMessage } from '../channel.ts'; | ||
import { APIGuildMember } from '../guild.ts'; | ||
import { APIUser } from '../user.ts'; | ||
|
||
/** | ||
* https://discord.com/developers/docs/interactions/slash-commands#message-interaction-object-message-interaction-structure | ||
*/ | ||
export interface APIMessageInteraction { | ||
/** | ||
* ID of the interaction | ||
*/ | ||
id: Snowflake; | ||
/** | ||
* The type of interaction | ||
*/ | ||
type: InteractionType; | ||
/** | ||
* The name of the ApplicationCommand | ||
*/ | ||
name: string; | ||
/** | ||
* The user who invoked the interaction | ||
*/ | ||
user: APIUser; | ||
} | ||
|
||
/** | ||
* https://discord.com/developers/docs/resources/guild#guild-member-object | ||
*/ | ||
export interface APIInteractionGuildMember extends APIGuildMember { | ||
permissions: Permissions; | ||
user: APIUser; | ||
} | ||
|
||
// INTERACTIONS RECEIVED | ||
|
||
/** | ||
* https://discord.com/developers/docs/interactions/slash-commands#interaction-object | ||
*/ | ||
export interface APIBaseInteraction<Type extends InteractionType, Data extends unknown> { | ||
/** | ||
* ID of the interaction | ||
*/ | ||
id: Snowflake; | ||
/** | ||
* ID of the application this interaction is for | ||
*/ | ||
application_id: Snowflake; | ||
/** | ||
* The type of interaction | ||
*/ | ||
type: Type; | ||
/** | ||
* The command data payload | ||
*/ | ||
data?: Data; | ||
/** | ||
* The guild it was sent from | ||
*/ | ||
guild_id?: Snowflake; | ||
/** | ||
* The channel it was sent from | ||
*/ | ||
channel_id?: Snowflake; | ||
/** | ||
* Guild member data for the invoking user, including permissions | ||
* | ||
* **This is only sent when an interaction is invoked in a guild** | ||
*/ | ||
member?: APIInteractionGuildMember; | ||
/** | ||
* User object for the invoking user, if invoked in a DM | ||
*/ | ||
user?: APIUser; | ||
/** | ||
* A continuation token for responding to the interaction | ||
*/ | ||
token: string; | ||
/** | ||
* Read-only property, always `1` | ||
*/ | ||
version: 1; | ||
/** | ||
* For components, the message they were attached to | ||
*/ | ||
message?: APIMessage; | ||
} | ||
|
||
export type APIDMInteractionWrapper<Original extends APIBaseInteraction<InteractionType, unknown>> = Omit< | ||
Original, | ||
'member' | 'guild_id' | ||
> & | ||
Required<Pick<Original, 'user'>>; | ||
|
||
export type APIGuildInteractionWrapper<Original extends APIBaseInteraction<InteractionType, unknown>> = Omit< | ||
Original, | ||
'user' | ||
> & | ||
Required<Pick<Original, 'member' | 'guild_id'>>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { ComponentType } from '../channel.ts'; | ||
import { APIBaseInteraction, InteractionType } from '../interactions.ts'; | ||
import { APIDMInteractionWrapper, APIGuildInteractionWrapper } from './base.ts'; | ||
|
||
export type APIMessageComponentInteraction = APIBaseInteraction< | ||
InteractionType.MessageComponent, | ||
APIMessageComponentInteractionData | ||
> & | ||
Required< | ||
Pick< | ||
APIBaseInteraction<InteractionType.MessageComponent, APIMessageComponentInteractionData>, | ||
'channel_id' | 'data' | 'message' | ||
> | ||
>; | ||
|
||
export type APIMessageComponentInteractionData = APIMessageButtonInteractionData | APIMessageSelectMenuInteractionData; | ||
|
||
export interface APIMessageComponentBaseInteractionData<CType extends ComponentType> { | ||
/** | ||
* The `custom_id` of the component | ||
*/ | ||
custom_id: string; | ||
/** | ||
* The type of the component | ||
*/ | ||
component_type: CType; | ||
} | ||
|
||
export type APIMessageButtonInteractionData = APIMessageComponentBaseInteractionData<ComponentType.Button>; | ||
|
||
export interface APIMessageSelectMenuInteractionData | ||
extends APIMessageComponentBaseInteractionData<ComponentType.SelectMenu> { | ||
values: string[]; | ||
} | ||
|
||
export type APIMessageComponentDMInteraction = APIDMInteractionWrapper<APIMessageComponentInteraction>; | ||
|
||
export type APIMessageComponentGuildInteraction = APIGuildInteractionWrapper<APIMessageComponentInteraction>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { MessageFlags } from '../mod.ts'; | ||
import { RESTPostAPIWebhookWithTokenJSONBody } from '../../../v8.ts'; | ||
|
||
/** | ||
* https://discord.com/developers/docs/interactions/slash-commands#interaction-object-interaction-request-type | ||
*/ | ||
export enum InteractionType { | ||
Ping = 1, | ||
ApplicationCommand, | ||
MessageComponent, | ||
} | ||
|
||
/** | ||
* https://discord.com/developers/docs/interactions/slash-commands#interaction-response-object | ||
*/ | ||
export type APIInteractionResponse = | ||
| APIInteractionResponsePong | ||
| APIInteractionResponseChannelMessageWithSource | ||
| APIInteractionResponseDeferredChannelMessageWithSource | ||
| APIInteractionResponseDeferredMessageUpdate | ||
| APIInteractionResponseUpdateMessage; | ||
|
||
export interface APIInteractionResponsePong { | ||
type: InteractionResponseType.Pong; | ||
} | ||
|
||
export interface APIInteractionResponseChannelMessageWithSource { | ||
type: InteractionResponseType.ChannelMessageWithSource; | ||
data: APIInteractionResponseCallbackData; | ||
} | ||
|
||
export interface APIInteractionResponseDeferredChannelMessageWithSource { | ||
type: InteractionResponseType.DeferredChannelMessageWithSource; | ||
data?: Pick<APIInteractionResponseCallbackData, 'flags'>; | ||
} | ||
|
||
export interface APIInteractionResponseDeferredMessageUpdate { | ||
type: InteractionResponseType.DeferredMessageUpdate; | ||
} | ||
|
||
export interface APIInteractionResponseUpdateMessage { | ||
type: InteractionResponseType.UpdateMessage; | ||
data?: APIInteractionResponseCallbackData; | ||
} | ||
|
||
/** | ||
* https://discord.com/developers/docs/interactions/slash-commands#interaction-response-object-interaction-callback-type | ||
*/ | ||
export enum InteractionResponseType { | ||
/** | ||
* ACK a `Ping` | ||
*/ | ||
Pong = 1, | ||
/** | ||
* Respond to an interaction with a message | ||
*/ | ||
ChannelMessageWithSource = 4, | ||
/** | ||
* ACK an interaction and edit to a response later, the user sees a loading state | ||
*/ | ||
DeferredChannelMessageWithSource, | ||
/** | ||
* ACK a button interaction and update it to a loading state | ||
*/ | ||
DeferredMessageUpdate, | ||
/** | ||
* ACK a button interaction and edit the message to which the button was attached | ||
*/ | ||
UpdateMessage, | ||
} | ||
|
||
/** | ||
* https://discord.com/developers/docs/interactions/slash-commands#interaction-response-object-interaction-application-command-callback-data-structure | ||
*/ | ||
export type APIInteractionResponseCallbackData = Omit< | ||
RESTPostAPIWebhookWithTokenJSONBody, | ||
'username' | 'avatar_url' | ||
> & { flags?: MessageFlags }; |
Oops, something went wrong.