Skip to content

Commit

Permalink
chore: Get up to date *again* (#156)
Browse files Browse the repository at this point in the history
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
vladfrangu committed Jul 19, 2021
1 parent ca933ae commit 86e0736
Show file tree
Hide file tree
Showing 57 changed files with 7,102 additions and 13,576 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/cicd.yml
Expand Up @@ -61,3 +61,25 @@ jobs:
git add --all .
git commit -m "build: deno build for ${GITHUB_SHA}" || true
git push || true
tsd:
name: TSD checks
runs-on: ubuntu-latest

needs: testing
if: needs.testing.result == 'success'

steps:
- name: Checkout Project
uses: actions/checkout@v2

- name: Use Node.js v16
uses: actions/setup-node@v2
with:
node-version: 16

- name: Install Dependencies
run: npm ci

- name: Run TSD
run: npm run test:types
4 changes: 1 addition & 3 deletions deno/gateway/v8.ts
Expand Up @@ -314,9 +314,7 @@ export type GatewayApplicationCommandModifyDispatch = DataPayload<
* https://discord.com/developers/docs/topics/gateway#application-command-update
* https://discord.com/developers/docs/topics/gateway#application-command-delete
*/
export interface GatewayApplicationCommandModifyDispatchData extends APIApplicationCommand {
guild_id?: string;
}
export type GatewayApplicationCommandModifyDispatchData = APIApplicationCommand;

/**
* https://discord.com/developers/docs/topics/gateway#application-command-create
Expand Down
4 changes: 1 addition & 3 deletions deno/gateway/v9.ts
Expand Up @@ -324,9 +324,7 @@ export type GatewayApplicationCommandModifyDispatch = DataPayload<
* https://discord.com/developers/docs/topics/gateway#application-command-update
* https://discord.com/developers/docs/topics/gateway#application-command-delete
*/
export interface GatewayApplicationCommandModifyDispatchData extends APIApplicationCommand {
guild_id?: string;
}
export type GatewayApplicationCommandModifyDispatchData = APIApplicationCommand;

/**
* https://discord.com/developers/docs/topics/gateway#application-command-create
Expand Down
101 changes: 101 additions & 0 deletions deno/payloads/v8/_interactions/base.ts
@@ -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'>>;
38 changes: 38 additions & 0 deletions deno/payloads/v8/_interactions/messageComponents.ts
@@ -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>;
78 changes: 78 additions & 0 deletions deno/payloads/v8/_interactions/responses.ts
@@ -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 };

0 comments on commit 86e0736

Please sign in to comment.