refactor(types): separate files for gateway types (#715)

This commit is contained in:
ayntee
2021-03-29 23:13:18 +04:00
committed by GitHub
parent a0ff1a3a71
commit a98df7f36d
49 changed files with 747 additions and 583 deletions

View File

@@ -0,0 +1,13 @@
import { SnakeCaseProps } from "../util.ts";
export interface ChannelPinsUpdate {
/** The id of the guild */
guildId?: string;
/** The id of the channel */
channelId: string;
/** The time at which the most recent pinned message was pinned */
lastPinTimestamp?: string | null;
}
/** https://discord.com/developers/docs/topics/gateway#channel-pins-update */
export type DiscordChannelPinsUpdate = SnakeCaseProps<ChannelPinsUpdate>;

View File

@@ -0,0 +1,12 @@
import { Emoji } from "../emojis/emoji.ts";
import { SnakeCaseProps } from "../util.ts";
/** https://discord.com/developers/docs/topics/gateway#guild-emojis-update */
export interface GuildEmojisUpdate {
/** id of the guild */
guild_id: string;
/** Array of emojis */
emojis: Emoji[];
}
export type DiscordGuildEmojisUpdate = SnakeCaseProps<GuildEmojisUpdate>;

View File

@@ -1,583 +0,0 @@
/** https://discord.com/developers/docs/topics/gateway#payloads-gateway-payload-structure */
export interface DiscordGatewayPayload {
/** opcode for the payload */
op: number;
/** Event data */
d: unknown | null;
/** Sequence number, used for resuming sessions and heartbeats */
s: number | null;
/** The event name for this payload */
t: string | null;
}
/** https://discord.com/developers/docs/topics/gateway#connecting-gateway-url-params */
export interface DiscordGatewayURLParams {
/** Gateway version to use */
v: string;
/** The encoding of received gateway packets */
encoding: string;
/** The (optional) compression of gateway packets */
compress?: string;
}
/** https://discord.com/developers/docs/topics/gateway#gateway-intents */
export enum DiscordGatewayIntents {
/**
* - GUILD_CREATE
* - GUILD_UPDATE
* - GUILD_DELETE
* - GUILD_ROLE_CREATE
* - GUILD_ROLE_UPDATE
* - GUILD_ROLE_DELETE
* - CHANNEL_CREATE
* - CHANNEL_UPDATE
* - CHANNEL_DELETE
* - CHANNEL_PINS_UPDATE
*/
GUILDS = 1 << 0,
/**
* - GUILD_MEMBER_ADD
* - GUILD_MEMBER_UPDATE
* - GUILD_MEMBER_REMOVE
*/
GUILD_MEMBERS = 1 << 1,
/**
* - GUILD_BAN_ADD
* - GUILD_BAN_REMOVE
*/
GUILD_BANS = 1 << 2,
/** - GUILD_EMOJIS_UPDATE */
GUILD_EMOJIS = 1 << 3,
/** - GUILD_INTEGRATIONS_UPDATE */
GUILD_INTEGRATIONS = 1 << 4,
/** - WEBHOOKS_UPDATE */
GUILD_WEBHOOKS = 1 << 5,
/**
* - INVITE_CREATE
* - INVITE_DELETE
*/
GUILD_INVITES = 1 << 6,
/** - VOICE_STATE_UPDATE */
GUILD_VOICE_STATES = 1 << 7,
/** - PRESENCE_UPDATE */
GUILD_PRESENCES = 1 << 8,
/**
* - MESSAGE_CREATE
* - MESSAGE_UPDATE
* - MESSAGE_DELETE
* - MESSAGE_DELETE_BULK
*/
GUILD_MESSAGES = 1 << 9,
/**
* - MESSAGE_REACTION_ADD
* - MESSAGE_REACTION_REMOVE
* - MESSAGE_REACTION_REMOVE_ALL
* - MESSAGE_REACTION_REMOVE_EMOJI
*/
GUILD_MESSAGE_REACTIONS = 1 << 10,
/** - TYPING_START */
GUILD_MESSAGE_TYPING = 1 << 11,
/**
* - MESSAGE_CREATE
* - MESSAGE_UPDATE
* - MESSAGE_DELETE
* - CHANNEL_PINS_UPDATE
*/
DIRECT_MESSAGES = 1 << 12,
/**
* - MESSAGE_REACTION_ADD
* - MESSAGE_REACTION_REMOVE
* - MESSAGE_REACTION_REMOVE_ALL
* - MESSAGE_REACTION_REMOVE_EMOJI
*/
DIRECT_MESSAGE_REACTIONS = 1 << 13,
/** - TYPING_START */
DIRECT_MESSAGE_TYPING = 1 << 14,
}
/** https://discord.com/developers/docs/topics/gateway#identify */
export interface DiscordIdentify {
/** Authentication token */
token: string;
/** Connection properties */
properties: DiscordIdentifyConnectionProperties;
/** Whether this connection supports compression of packets */
compress?: boolean;
/** Value between 50 and 250, total number of members where the gateway will stop sending offline members in the guild member list */
large_threshold?: number;
/** Used for Guild Sharding */
shard?: [number, number];
/** Presence structure for initial presence information */
presence?: DiscordUpdateStatus;
/** Enables dispatching of guild subscription events (presence and typing events) */
guild_subscriptions?: boolean;
/** The Gateway Intents you wish to receive */
intents: number;
}
/** https://discord.com/developers/docs/topics/gateway#identify-identify-connection-properties */
export interface DiscordIdentifyConnectionProperties {
/** Operating system */
$os: string;
/** Library name */
$browser: string;
/** Library name */
$device: string;
}
/** https://discord.com/developers/docs/topics/gateway#resume */
export interface DiscordResume {
/** Session token */
token: string;
/** Session id */
session_id: string;
/** Last sequence number received */
seq: number;
}
/** https://discord.com/developers/docs/topics/gateway#request-guild-members */
export interface DiscordRequestGuildMembers {
/** id of the guild to get members for */
guild_id: string;
/** String that username starts with, or an empty string to return all members */
query?: string;
/** Maximum number of members to send matching the query; a limit of 0 can be used with an empty string query to return all members */
limit: number;
/** Used to specify if we want the presences of the matched members */
presences?: boolean;
/** Used to specify which users you wish to fetch */
user_ids?: string[];
/** Nonce to identify the Guild Members Chunk response */
nonce?: string;
}
/** https://discord.com/developers/docs/topics/gateway#update-voice-state */
export interface DiscordUpdateVoiceState {
/** id of the guild */
guild_id: string;
/** id of the voice channel client wants to join (null if disconnecting) */
channel_id: string | null;
/** Is the client muted */
self_mute: boolean;
/** Is the client deafened */
self_deaf: boolean;
}
/** https://discord.com/developers/docs/topics/gateway#update-status */
export interface DiscordUpdateStatus {
/** Unix time (in milliseconds) of when the client went idle, or null if the client is not idle */
since: number | null;
/** null, or the user's activities */
activities: DiscordActivity[] | null;
/** The user's new status */
status: DiscordStatusTypes;
/** Whether or not the client is afk */
afk: boolean;
}
/** https://discord.com/developers/docs/topics/gateway#update-status-status-types */
export type DiscordStatusTypes =
| "online"
| "dnd"
| "idle"
| "invisible"
| "offline";
/** https://discord.com/developers/docs/topics/gateway#hello */
export interface DiscordHello {
/** The interval (in milliseconds) the client should heartbeat with */
heartbeat_interval: number;
}
/** https://discord.com/developers/docs/topics/gateway#ready */
export interface DiscordReady {
/** Gateway version */
v: number;
/** Information about the user including email */
user: DiscordUser;
/** Empty array */
private_channels: [];
/** The guilds the user is in */
guilds: DiscordUnavailableGuild[];
/** Used for resuming connections */
session_id: string;
/** The shard information associated with this session, if sent when identifying */
shard?: [number, number];
/** Contains id and flags */
application:
& Partial<DiscordApplication>
& Pick<DiscordApplication, "id" | "flags">;
}
/** https://discord.com/developers/docs/topics/gateway#channel-pins-update */
export interface DiscordChannelPinsUpdate {
/** The id of the guild */
guild_id?: string;
/** The id of the channel */
channel_id: string;
/** The time at which the most recent pinned message was pinned */
last_pin_timestamp?: string | null;
}
/** https://discord.com/developers/docs/topics/gateway#guild-ban-add */
export interface DiscordGuildBanAddRemove {
/** id of the guild */
guild_id: string;
/** The (un)banned user */
user: DiscordUser;
}
/** https://discord.com/developers/docs/topics/gateway#guild-emojis-update */
export interface DiscordGuildEmojisUpdate {
/** id of the guild */
guild_id: string;
/** Array of emojis */
emojis: DiscordEmoji[];
}
/** https://discord.com/developers/docs/topics/gateway#guild-integrations-update */
export interface DiscordGuildIntegrationsUpdate {
/** id of the guild whose integrations were updated */
guild_id: string;
}
/** https://discord.com/developers/docs/topics/gateway#guild-member-add */
export interface DiscordGuildMemberAdd extends DiscordMember {
/** id of the guild */
guild_id: string;
}
/** https://discord.com/developers/docs/topics/gateway#guild-member-remove */
export interface DiscordGuildMemberRemove {
/** The id of the guild */
guild_id: string;
/** The user who was removed */
user: DiscordUser;
}
/** https://discord.com/developers/docs/topics/gateway#guild-member-update */
export interface DiscordGuildMemberUpdate {
/** The id of the guild */
guild_id: string;
/** User role ids */
roles: string[];
/** The user */
user: DiscordUser;
/** Nickname of the user in the guild */
nick?: string | null;
/** When the user joined the guild */
joined_at: string;
/** When the user starting boosting the guild */
premium_since?: string | null;
/** Whether the user has not yet passed the guild's Membership Screening requirements */
pending?: boolean;
}
/** https://discord.com/developers/docs/topics/gateway#guild-members-chunk */
export interface DiscordGuildMembersChunk {
/** The id of the guild */
guild_id: string;
/** Set of guild members */
members: DiscordMember[];
/** The chunk index in the expected chunks for this response (0 <= chunk_index < chunk_count) */
chunk_index: number;
/** The total number of expected chunks for this response */
chunk_count: number;
/** If passing an invalid id to `REQUEST_GUILD_MEMBERS`, it will be returned here */
not_found?: string[];
/** If passing true to `REQUEST_GUILD_MEMBERS`, presences of the returned members will be here */
presences?: DiscordPresence[];
/** The nonce used in the Guild Members Request */
nonce?: string;
}
/** https://discord.com/developers/docs/topics/gateway#guild-role-create */
export interface DiscordGuildRoleCreateUpdate {
/** The id of the guild */
guild_id: string;
/** The role created/updated */
role: DiscordRole;
}
/** https://discord.com/developers/docs/topics/gateway#guild-role-delete */
export interface DiscordGuildRoleDelete {
/** id of the guild */
guild_id: string;
/** id of the role */
role_id: string;
}
/** https://discord.com/developers/docs/topics/gateway#invite-create */
export interface DiscordInviteCreate {
/** The channel the invite is for */
channel_id: string;
/** The unique invite code */
code: string;
/** The time at which the invite was created */
created_at: string;
/** The guild of the invite */
guild_id?: string;
/** The user that created the invite */
inviter?: DiscordUser;
/** How long the invite is valid for (in seconds) */
max_age: number;
/** The maximum number of times the invite can be used */
max_uses: number;
/** The target user for this invite */
target_user?: Partial<DiscordUser>;
/** The type of user target for this invite */
target_user_type?: number;
/** Whether or not the invite is temporary (invited users will be kicked on disconnect unless they're assigned a role) */
temporary: boolean;
/** How many times the invite has been used (always will be 0) */
uses: number;
}
/** https://discord.com/developers/docs/topics/gateway#invite-delete */
export interface DiscordInviteDelete {
/** The channel of the invite */
channel_id: string;
/** The guild of the invite */
guild_id?: string;
/** The unique invite code */
code: string;
}
/** https://discord.com/developers/docs/topics/gateway#message-delete */
export interface DiscordMessageDelete {
/** The id of the message */
id: string;
/** The id of the channel */
channel_id: string;
/** The id of the guild */
guild_id?: string;
}
/** https://discord.com/developers/docs/topics/gateway#message-delete-bulk */
export interface DiscordMessageDeleteBulk {
/** The ids of the messages */
ids: string[];
/** The id of the channel */
channel_id: string;
/** The id of the guild */
guild_id?: string;
}
/** https://discord.com/developers/docs/topics/gateway#message-reaction-add */
export interface DiscordMessageReactionAdd {
/** The id of the user */
user_id: string;
/** The id of the channel */
channel_id: string;
/** The id of the message */
message_id: string;
/** The id of the guild */
guild_id?: string;
/** The member who reacted if this happened in a guild */
member?: DiscordMember;
/** The emoji used to react */
emoji: Partial<DiscordEmoji>;
}
/** https://discord.com/developers/docs/topics/gateway#message-reaction-remove */
export type DiscordMessageReactionRemove = Omit<
DiscordMessageReactionAdd,
"member"
>;
/** https://discord.com/developers/docs/topics/gateway#message-reaction-remove-all */
export type DiscordMessageReactionRemoveAll = Pick<
DiscordMessageReactionAdd,
"channel_id" | "message_id" | "guild_id"
>;
/** https://discord.com/developers/docs/topics/gateway#message-reaction-remove-emoji */
export type DiscordMessageReactionRemoveEmoji = Pick<
DiscordMessageReactionAdd,
"channel_id" | "guild_id" | "message_id" | "emoji"
>;
/** https://discord.com/developers/docs/topics/gateway#presence-update */
export interface DiscordPresenceUpdate {
/** The user presence is being updated for */
user: DiscordUser;
/** id of the guild */
guild_id: string;
/** Either "idle", "dnd", "online", or "offline" */
status: "idle" | "dnd" | "online" | "offline";
/** User's current activities */
activities: DiscordActivity[];
/** User's platform-dependent status */
client_status: DiscordClientStatus;
}
/** https://discord.com/developers/docs/topics/gateway#client-status-object */
export interface DiscordClientStatus {
/** The user's status set for an active desktop (Windows, Linux, Mac) application session */
desktop?: string;
/** The user's status set for an active mobile (iOS, Android) application session */
mobile?: string;
/** The user's status set for an active web (browser, bot account) application session */
web?: string;
}
/** https://discord.com/developers/docs/topics/gateway#activity-object */
export interface DiscordActivity {
/** The activity's name */
name: string;
/** Activity type */
type: DiscordActivityTypes;
/** Stream url, is validated when type is 1 */
url?: string | null;
/** Unix timestamp of when the activity was added to the user's session */
created_at: number;
/** Unix timestamps for start and/or end of the game */
timestamps?: DiscordActivityTimestamps;
/** Application id for the game */
application_id?: string;
/** What the player is currently doing */
details?: string | null;
/** The user's current party status */
state?: string | null;
/** The emoji used for a custom status */
emoji?: DiscordActivityEmoji | null;
/** Information for the current party of the player */
party?: DiscordActivityParty;
/** Images for the presence and their hover texts */
assets?: DiscordActivityAssets;
/** Secrets for Rich Presence joining and spectating */
secrets?: DiscordActivitySecrets;
/** Whether or not the activity is an instanced game session */
instance?: boolean;
/** Activity flags `OR`d together, describes what the payload includes */
flags?: number;
}
/** https://discord.com/developers/docs/topics/gateway#activity-object-activity-types */
export enum DiscordActivityTypes {
Game,
Streaming,
Listening,
Custom = 4,
Competing,
}
/** https://discord.com/developers/docs/topics/gateway#activity-object-activity-timestamps */
export interface DiscordActivityTimestamps {
/** Unix time (in milliseconds) of when the activity started */
start?: number;
/** Unix time (in milliseconds) of when the activity ends */
end?: number;
}
/** https://discord.com/developers/docs/topics/gateway#activity-object-activity-emoji */
export interface DiscordActivityEmoji {
/** The name of the emoji */
name: string;
/** The id of the emoji */
id?: string;
/** Whether this emoji is animated */
animated?: boolean;
}
/** https://discord.com/developers/docs/topics/gateway#activity-object-activity-party */
export interface DiscordActivityParty {
/** The id of the party */
id?: string;
/** Used to show the party's current and maximum size */
size?: [current_size: number, max_size: number];
}
/** https://discord.com/developers/docs/topics/gateway#activity-object-activity-assets */
export interface DiscordActivityAssets {
/** The id for a large asset of the activity, usually a snowflake */
large_image?: string;
/** Text displayed when hovering over the large image of the activity */
large_text?: string;
/** The id for a small asset of the activity, usually a snowflake */
small_image?: string;
/** Text displayed when hovering over the small image of the activity */
small_text?: string;
}
/** https://discord.com/developers/docs/topics/gateway#activity-object-activity-secrets */
export interface DiscordActivitySecrets {
/** The secret for joining a party */
join?: string;
/** The secret for spectating a game */
spectate?: string;
/** The secret for a specific instanced match */
match?: string;
}
/** https://discord.com/developers/docs/topics/gateway#activity-object-activity-flags */
export enum ActivityFlags {
INSTANCE = 1 << 0,
JOIN = 1 << 1,
SPECTATE = 1 << 2,
JOIN_REQUEST = 1 << 3,
SYNC = 1 << 4,
PLAY = 1 << 5,
}
/** https://discord.com/developers/docs/topics/gateway#typing-start */
export interface DiscordTypingStart {
/** id of the channel */
channel_id: string;
/** id of the guild */
guild_id?: string;
/** id of the user */
user_id: string;
/** Unix time (in seconds) of when the user started typing */
timestamp: number;
/** The member who started typing if this happened in a guild */
member?: DiscordMember;
}
/** https://discord.com/developers/docs/topics/gateway#voice-server-update */
export interface DiscordVoiceServerUpdate {
/** Voice connection token */
token: string;
/** The guild this voice server update is for */
guild_id: string;
/** The voice server host */
endpoint: string;
}
/** https://discord.com/developers/docs/topics/gateway#webhooks-update */
export interface DiscordWebhooksUpdate {
/** id of the guild */
guild_id: string;
/** id of the channel */
channel_id: string;
}
/** https://discord.com/developers/docs/topics/gateway#commands */
export type DiscordApplicationCommandCreateUpdateDelete =
& DiscordApplicationCommand
& {
/** id of the guild the command is in */
guild_id: string;
};
/** https://discord.com/developers/docs/topics/gateway#get-gateway-bot */
export interface DiscordGetGatewayBot {
/** The WSS URL that can be used for connecting to the gateway */
url: string;
/** The recommended number of shards to use when connecting */
shards: number;
/** Information on the current session start limit */
session_start_limit: DiscordSessionStartLimit;
}
/** https://discord.com/developers/docs/topics/gateway#session-start-limit-object */
export interface DiscordSessionStartLimit {
/** The total number of session starts the current user is allowed */
total: number;
/** The remaining number of session starts the current user is allowed */
remaining: number;
/** The number of milliseconds after which the limit resets */
reset_after: number;
/** The number of identify requests allowed per 5 seconds */
max_concurrency: number;
}

View File

@@ -0,0 +1,90 @@
/** https://discord.com/developers/docs/topics/gateway#list-of-intents */
export enum DiscordGatewayIntents {
/**
* - GUILD_CREATE
* - GUILD_DELETE
* - GUILD_ROLE_CREATE
* - GUILD_ROLE_UPDATE
* - GUILD_ROLE_DELETE
* - CHANNEL_CREATE
* - CHANNEL_UPDATE
* - CHANNEL_DELETE
* - CHANNEL_PINS_UPDATE
*/
GUILDS = 1 << 0,
/**
* - GUILD_MEMBER_ADD
* - GUILD_MEMBER_UPDATE
* - GUILD_MEMBER_REMOVE
*/
GUILD_MEMBERS = 1 << 1,
/**
* - GUILD_BAN_ADD
* - GUILD_BAN_REMOVE
*/
GUILD_BANS = 1 << 2,
/**
* - GUILD_EMOJIS_UPDATE
*/
GUILD_EMOJIS = 1 << 3,
/**
* - GUILD_INTEGRATIONS_UPDATE
* - INTEGRATION_CREATE
* - INTEGRATION_UPDATE
* - INTEGRATION_DELETE
*/
GUILD_INTEGRATIONS = 1 << 4,
/** Enables the following events:
* - WEBHOOKS_UPDATE
*/
GUILD_WEBHOOKS = 1 << 5,
/**
* - INVITE_CREATE
* - INVITE_DELETE
*/
GUILD_INVITES = 1 << 6,
/**
* - VOICE_STATE_UPDATE
*/
GUILD_VOICE_STATES = 1 << 7,
/**
* - PRESENCE_UPDATE
*/
GUILD_PRESENCES = 1 << 8,
/**
* - MESSAGE_CREATE
* - MESSAGE_UPDATE
* - MESSAGE_DELETE
*/
GUILD_MESSAGES = 1 << 9,
/**
* - MESSAGE_REACTION_ADD
* - MESSAGE_REACTION_REMOVE
* - MESSAGE_REACTION_REMOVE_ALL
* - MESSAGE_REACTION_REMOVE_EMOJI
*/
GUILD_MESSAGE_REACTIONS = 1 << 10,
/**
* - TYPING_START
*/
GUILD_MESSAGE_TYPING = 1 << 11,
/**
* - CHANNEL_CREATE
* - MESSAGE_CREATE
* - MESSAGE_UPDATE
* - MESSAGE_DELETE
* - CHANNEL_PINS_UPDATE
*/
DIRECT_MESSAGES = 1 << 12,
/**
* - MESSAGE_REACTION_ADD
* - MESSAGE_REACTION_REMOVE
* - MESSAGE_REACTION_REMOVE_ALL
* - MESSAGE_REACTION_REMOVE_EMOJI
*/
DIRECT_MESSAGE_REACTIONS = 1 << 13,
/**
* - TYPING_START
*/
DIRECT_MESSAGE_TYPING = 1 << 14,
}

View File

@@ -0,0 +1,13 @@
export interface GatewayPayload {
/** opcode for the payload */
op: number;
/** Event data */
d: unknown | null;
/** Sequence number, used for resuming sessions and heartbeats */
s: number | null;
/** The event name for this payload */
t: string | null;
}
/** https://discord.com/developers/docs/topics/gateway#payloads-gateway-payload-structure */
export type DiscordGatewayPayload = GatewayPayload;

View File

@@ -0,0 +1,11 @@
export interface GatewayURLParams {
/** Gateway version to use */
v: string;
/** The encoding of received gateway packets */
encoding: string;
/** The (optional) compression of gateway packets */
compress?: string;
}
/** https://discord.com/developers/docs/topics/gateway#connecting-gateway-url-params */
export type DiscordGatewayURLParams = GatewayURLParams;

View File

@@ -0,0 +1,13 @@
import { SnakeCaseProps } from "../util.ts";
export interface GetGatewayBot {
/** The WSS URL that can be used for connecting to the gateway */
url: string;
/** The recommended number of shards to use when connecting */
shards: number;
/** Information on the current session start limit */
sessionStartLimit: SessionStartLimit;
}
/** https://discord.com/developers/docs/topics/gateway#get-gateway-bot */
export type DiscordGetGatewayBot = SnakeCaseProps<GetGatewayBot>;

View File

@@ -0,0 +1,9 @@
import { SnakeCaseProps } from "../util.ts";
export interface Hello {
/** The interval (in milliseconds) the client should heartbeat with */
heartbeatInterval: number;
}
/** https://discord.com/developers/docs/topics/gateway#hello */
export type DiscordHello = SnakeCaseProps<Hello>;

View File

@@ -0,0 +1,25 @@
import { SnakeCaseProps } from "../util.ts";
import { IdentifyConnectionProperties } from "./identify_connection_properties.ts";
import { UpdateStatus } from "./update_status.ts";
export interface Identify {
/** Authentication token */
token: string;
/** Connection properties */
properties: IdentifyConnectionProperties;
/** Whether this connection supports compression of packets */
compress?: boolean;
/** Value between 50 and 250, total number of members where the gateway will stop sending offline members in the guild member list */
largeThreshold?: number;
/** Used for Guild Sharding */
shard?: [number, number];
/** Presence structure for initial presence information */
presence?: UpdateStatus;
/** Enables dispatching of guild subscription events (presence and typing events) */
guild_subscriptions?: boolean;
/** The Gateway Intents you wish to receive */
intents: number;
}
/** https://discord.com/developers/docs/topics/gateway#identify */
export type DiscordIdentify = SnakeCaseProps<Identify>;

View File

@@ -0,0 +1,11 @@
/** https://discord.com/developers/docs/topics/gateway#identify-identify-connection-properties */
export interface IdentifyConnectionProperties {
/** Operating system */
$os: string;
/** Library name */
$browser: string;
/** Library name */
$device: string;
}
export type DiscordIdentifyConnectionProperties = IdentifyConnectionProperties;

View File

@@ -0,0 +1,24 @@
import { User } from "../users/user.ts";
import { SnakeCaseProps } from "../util.ts";
export interface Ready {
/** Gateway version */
v: number;
/** Information about the user including email */
user: User;
/** Empty array */
privateChannels: [];
/** The guilds the user is in */
guilds: UnavailableGuild[];
/** Used for resuming connections */
sessionId: string;
/** The shard information associated with this session, if sent when identifying */
shard?: [number, number];
/** Contains id and flags */
application:
& Partial<Application>
& Pick<Application, "id" | "flags">;
}
/** https://discord.com/developers/docs/topics/gateway#ready */
export type DiscordReady = SnakeCaseProps<Ready>;

View File

@@ -0,0 +1,11 @@
/** https://discord.com/developers/docs/topics/gateway#resume */
export interface Resume {
/** Session token */
token: string;
/** Session id */
session_id: string;
/** Last sequence number received */
seq: number;
}
export type DiscordResume = Resume;

View File

@@ -0,0 +1,15 @@
import { SnakeCaseProps } from "../util.ts";
export interface SessionStartLimit {
/** The total number of session starts the current user is allowed */
total: number;
/** The remaining number of session starts the current user is allowed */
remaining: number;
/** The number of milliseconds after which the limit resets */
resetAfter: number;
/** The number of identify requests allowed per 5 seconds */
maxConcurrency: number;
}
/** https://discord.com/developers/docs/topics/gateway#session-start-limit-object */
export type DiscordSessionStartLimit = SnakeCaseProps<SessionStartLimit>;

View File

@@ -0,0 +1,7 @@
/** https://discord.com/developers/docs/topics/gateway#update-status-status-types */
export type DiscordStatusTypes =
| "online"
| "dnd"
| "idle"
| "invisible"
| "offline";

View File

@@ -0,0 +1,17 @@
import { Activity } from "../misc/activity.ts";
import { SnakeCaseProps } from "../util.ts";
import { DiscordStatusTypes } from "./status_types.ts";
export interface UpdateStatus {
/** Unix time (in milliseconds) of when the client went idle, or null if the client is not idle */
since: number | null;
/** null, or the user's activities */
activities: Activity[] | null;
/** The user's new status */
status: DiscordStatusTypes;
/** Whether or not the client is afk */
afk: boolean;
}
/** https://discord.com/developers/docs/topics/gateway#update-status */
export type DiscordUpdateStatus = SnakeCaseProps<UpdateStatus>;

View File

@@ -0,0 +1,12 @@
import { User } from "../users/user.ts";
import { SnakeCaseProps } from "../util.ts";
export interface GuildBanAdd {
/** id of the guild */
guildId: string;
/** The banned user */
user: User;
}
/** https://discord.com/developers/docs/topics/gateway#guild-ban-add */
export type DiscordGuildBanAdd = SnakeCaseProps<GuildBanAdd>;

View File

@@ -0,0 +1,12 @@
import { User } from "../users/user.ts";
import { SnakeCaseProps } from "../util.ts";
export interface GuildBanRemove {
/** id of the guild */
guildId: string;
/** The unbanned user */
user: User;
}
/** https://discord.com/developers/docs/topics/gateway#guild-ban-remove */
export type DiscordGuildBanRemove = SnakeCaseProps<GuildBanRemove>;

View File

@@ -0,0 +1,11 @@
import { SnakeCaseProps } from "../util.ts";
export interface GuildIntegrationsUpdate {
/** id of the guild whose integrations were updated */
guildId: string;
}
/** https://discord.com/developers/docs/topics/gateway#guild-integrations-update */
export type DiscordGuildIntegrationsUpdate = SnakeCaseProps<
GuildIntegrationsUpdate
>;

View File

@@ -0,0 +1,11 @@
import { SnakeCaseProps } from "../util.ts";
export interface GuildRoleCreate {
/** The id of the guild */
guildId: string;
/** The role created */
role: Role;
}
/** https://discord.com/developers/docs/topics/gateway#guild-role-create */
export type DiscordGuildRoleCreate = SnakeCaseProps<GuildRoleCreate>;

View File

@@ -0,0 +1,11 @@
import { SnakeCaseProps } from "../util.ts";
export interface GuildRoleDelete {
/** id of the guild */
guildId: string;
/** id of the role */
roleId: string;
}
/** https://discord.com/developers/docs/topics/gateway#guild-role-delete */
export type DiscordGuildRoleDelete = SnakeCaseProps<GuildRoleDelete>;

View File

@@ -0,0 +1,11 @@
import { SnakeCaseProps } from "../util.ts";
export interface GuildRoleUpdate {
/** The id of the guild */
guildId: string;
/** The role updated */
role: Role;
}
/** https://discord.com/developers/docs/topics/gateway#guild-role-update */
export type DiscordGuildRoleUpdate = SnakeCaseProps<GuildRoleUpdate>;

View File

@@ -0,0 +1,19 @@
import { SnakeCaseProps } from "../util.ts";
export interface RequestGuildMembers {
/** id of the guild to get members for */
guild_id: string;
/** String that username starts with, or an empty string to return all members */
query?: string;
/** Maximum number of members to send matching the query; a limit of 0 can be used with an empty string query to return all members */
limit: number;
/** Used to specify if we want the presences of the matched members */
presences?: boolean;
/** Used to specify which users you wish to fetch */
userIds?: string[];
/** Nonce to identify the Guild Members Chunk response */
nonce?: string;
}
/** https://discord.com/developers/docs/topics/gateway#request-guild-members */
export type DiscordRequestGuildMembers = SnakeCaseProps<RequestGuildMembers>;

View File

@@ -0,0 +1,30 @@
import { User } from "../users/user.ts";
import { SnakeCaseProps } from "../util.ts";
export interface InviteCreate {
/** The channel the invite is for */
channelId: string;
/** The unique invite code */
code: string;
/** The time at which the invite was created */
createdAt: string;
/** The guild of the invite */
guildId?: string;
/** The user that created the invite */
inviter?: User;
/** How long the invite is valid for (in seconds) */
maxAge: number;
/** The maximum number of times the invite can be used */
maxUses: number;
/** The target user for this invite */
targetUser?: Partial<User>;
/** The type of user target for this invite */
targetUserType?: number;
/** Whether or not the invite is temporary (invited users will be kicked on disconnect unless they're assigned a role) */
temporary: boolean;
/** How many times the invite has been used (always will be 0) */
uses: number;
}
/** https://discord.com/developers/docs/topics/gateway#invite-create */
export type DiscordInviteCreate = SnakeCaseProps<InviteCreate>;

View File

@@ -0,0 +1,13 @@
import { SnakeCaseProps } from "../util.ts";
/** https://discord.com/developers/docs/topics/gateway#invite-delete */
export interface InviteDelete {
/** The channel of the invite */
channelId: string;
/** The guild of the invite */
guildId?: string;
/** The unique invite code */
code: string;
}
export type DiscordInviteDelete = SnakeCaseProps<InviteDelete>;

View File

@@ -0,0 +1,9 @@
import { SnakeCaseProps } from "../util.ts";
export interface GuildMemberAdd extends GuildMember {
/** id of the guild */
guildId: string;
}
/** https://discord.com/developers/docs/topics/gateway#guild-member-add */
export type DiscordGuildMemberAdd = SnakeCaseProps<GuildMemberAdd>;

View File

@@ -0,0 +1,12 @@
import { User } from "../users/user.ts";
import { SnakeCaseProps } from "../util.ts";
export interface GuildMemberRemove {
/** The id of the guild */
guildId: string;
/** The user who was removed */
user: User;
}
/** https://discord.com/developers/docs/topics/gateway#guild-member-remove */
export type DiscordGuildMemberRemove = SnakeCaseProps<GuildMemberRemove>;

View File

@@ -0,0 +1,22 @@
import { User } from "../users/user.ts";
import { SnakeCaseProps } from "../util.ts";
export interface GuildMemberUpdate {
/** The id of the guild */
guildId: string;
/** User role ids */
roles: string[];
/** The user */
user: User;
/** Nickname of the user in the guild */
nick?: string | null;
/** When the user joined the guild */
joinedAt: string;
/** When the user starting boosting the guild */
premiumSince?: string | null;
/** Whether the user has not yet passed the guild's Membership Screening requirements */
pending?: boolean;
}
/** https://discord.com/developers/docs/topics/gateway#guild-member-update */
export type DiscordGuildMemberUpdate = SnakeCaseProps<GuildMemberUpdate>;

View File

@@ -0,0 +1,21 @@
import { SnakeCaseProps } from "../util.ts";
export interface GuildMembersChunk {
/** The id of the guild */
guildId: string;
/** Set of guild members */
members: GuildMember[];
/** The chunk index in the expected chunks for this response (0 <= chunk_index < chunk_count) */
chunkIndex: number;
/** The total number of expected chunks for this response */
chunkCount: number;
/** If passing an invalid id to `REQUEST_GUILD_MEMBERS`, it will be returned here */
notFound?: string[];
/** If passing true to `REQUEST_GUILD_MEMBERS`, presences of the returned members will be here */
presences?: Presence[];
/** The nonce used in the Guild Members Request */
nonce?: string;
}
/** https://discord.com/developers/docs/topics/gateway#guild-members-chunk */
export type DiscordGuildMembersChunk = SnakeCaseProps<GuildMembersChunk>;

View File

@@ -0,0 +1,13 @@
import { SnakeCaseProps } from "../util.ts";
export interface MessageDelete {
/** The id of the message */
id: string;
/** The id of the channel */
channelId: string;
/** The id of the guild */
guildId?: string;
}
/** https://discord.com/developers/docs/topics/gateway#message-delete */
export type DiscordMessageDelete = SnakeCaseProps<MessageDelete>;

View File

@@ -0,0 +1,13 @@
import { SnakeCaseProps } from "../util.ts";
export interface MessageDeleteBulk {
/** The ids of the messages */
ids: string[];
/** The id of the channel */
channelId: string;
/** The id of the guild */
guildId?: string;
}
/** https://discord.com/developers/docs/topics/gateway#message-delete-bulk */
export type DiscordMessageDeleteBulk = SnakeCaseProps<MessageDeleteBulk>;

View File

@@ -0,0 +1,20 @@
import { Emoji } from "../emojis/emoji.ts";
import { SnakeCaseProps } from "../util.ts";
export interface MessageReactionAdd {
/** The id of the user */
userId: string;
/** The id of the channel */
channelId: string;
/** The id of the message */
messageId: string;
/** The id of the guild */
guildId?: string;
/** The member who reacted if this happened in a guild */
member?: GuildMember;
/** The emoji used to react */
emoji: Partial<Emoji>;
}
/** https://discord.com/developers/docs/topics/gateway#message-reaction-add */
export type DiscordMessageReactionAdd = SnakeCaseProps<MessageReactionAdd>;

View File

@@ -0,0 +1,12 @@
import { SnakeCaseProps } from "../util.ts";
import { MessageReactionAdd } from "./message_reaction_add.ts";
export type MessageReactionRemove = Omit<
MessageReactionAdd,
"member"
>;
/** https://discord.com/developers/docs/topics/gateway#message-reaction-remove */
export type DiscordMessageReactionRemove = SnakeCaseProps<
MessageReactionRemove
>;

View File

@@ -0,0 +1,12 @@
import { SnakeCaseProps } from "../util.ts";
import { MessageReactionAdd } from "./message_reaction_add.ts";
export type MessageReactionRemoveAll = Pick<
MessageReactionAdd,
"channelId" | "messageId" | "guildId"
>;
/** https://discord.com/developers/docs/topics/gateway#message-reaction-remove-all */
export type DiscordMessageReactionRemoveAll = SnakeCaseProps<
MessageReactionRemoveAll
>;

View File

@@ -0,0 +1,12 @@
import { SnakeCaseProps } from "../util.ts";
import { MessageReactionAdd } from "./message_reaction_add.ts";
export type MessageReactionRemoveEmoji = Pick<
MessageReactionAdd,
"channelId" | "guildId" | "messageId" | "emoji"
>;
/** https://discord.com/developers/docs/topics/gateway#message-reaction-remove-emoji */
export type DiscordMessageReactionRemoveEmoji = SnakeCaseProps<
MessageReactionRemoveEmoji
>;

View File

@@ -0,0 +1,41 @@
import { SnakeCaseProps } from "../util.ts";
import { ActivityAssets } from "./activity_assets.ts";
import { ActivityEmoji } from "./activity_emoji.ts";
import { ActivityParty } from "./activity_party.ts";
import { ActivitySecrets } from "./activity_secrets.ts";
import { ActivityTimestamps } from "./activity_timestamps.ts";
import { DiscordActivityTypes } from "./activity_types.ts";
export interface Activity {
/** The activity's name */
name: string;
/** Activity type */
type: DiscordActivityTypes;
/** Stream url, is validated when type is 1 */
url?: string | null;
/** Unix timestamp of when the activity was added to the user's session */
created_at: number;
/** Unix timestamps for start and/or end of the game */
timestamps?: ActivityTimestamps;
/** Application id for the game */
application_id?: string;
/** What the player is currently doing */
details?: string | null;
/** The user's current party status */
state?: string | null;
/** The emoji used for a custom status */
emoji?: ActivityEmoji | null;
/** Information for the current party of the player */
party?: ActivityParty;
/** Images for the presence and their hover texts */
assets?: ActivityAssets;
/** Secrets for Rich Presence joining and spectating */
secrets?: ActivitySecrets;
/** Whether or not the activity is an instanced game session */
instance?: boolean;
/** Activity flags `OR`d together, describes what the payload includes */
flags?: number;
}
/** https://discord.com/developers/docs/topics/gateway#activity-object */
export type DiscordActivity = SnakeCaseProps<Activity>;

View File

@@ -0,0 +1,15 @@
import { SnakeCaseProps } from "../util.ts";
export interface ActivityAssets {
/** The id for a large asset of the activity, usually a snowflake */
largeImage?: string;
/** Text displayed when hovering over the large image of the activity */
largeText?: string;
/** The id for a small asset of the activity, usually a snowflake */
smallImage?: string;
/** Text displayed when hovering over the small image of the activity */
smallText?: string;
}
/** https://discord.com/developers/docs/topics/gateway#activity-object-activity-assets */
export type DiscordActivityAssets = SnakeCaseProps<ActivityAssets>;

View File

@@ -0,0 +1,11 @@
export interface ActivityEmoji {
/** The name of the emoji */
name: string;
/** The id of the emoji */
id?: string;
/** Whether this emoji is animated */
animated?: boolean;
}
/** https://discord.com/developers/docs/topics/gateway#activity-object-activity-emoji */
export type DiscordActivityEmoji = ActivityEmoji;

View File

@@ -0,0 +1,9 @@
/** https://discord.com/developers/docs/topics/gateway#activity-object-activity-flags */
export enum DiscordActivityFlags {
INSTANCE = 1 << 0,
JOIN = 1 << 1,
SPECTATE = 1 << 2,
JOIN_REQUEST = 1 << 3,
SYNC = 1 << 4,
PLAY = 1 << 5,
}

View File

@@ -0,0 +1,9 @@
/** https://discord.com/developers/docs/topics/gateway#activity-object-activity-party */
export interface ActivityParty {
/** The id of the party */
id?: string;
/** Used to show the party's current and maximum size */
size?: [currentSize: number, maxSize: number];
}
export type DiscordActivityParty = ActivityParty;

View File

@@ -0,0 +1,11 @@
export interface ActivitySecrets {
/** The secret for joining a party */
join?: string;
/** The secret for spectating a game */
spectate?: string;
/** The secret for a specific instanced match */
match?: string;
}
/** https://discord.com/developers/docs/topics/gateway#activity-object-activity-secrets */
export type DiscordActivitySecrets = ActivitySecrets;

View File

@@ -0,0 +1,9 @@
export interface ActivityTimestamps {
/** Unix time (in milliseconds) of when the activity started */
start?: number;
/** Unix time (in milliseconds) of when the activity ends */
end?: number;
}
/** https://discord.com/developers/docs/topics/gateway#activity-object-activity-timestamps */
export type DiscordactivityTimestamps = ActivityTimestamps;

View File

@@ -0,0 +1,8 @@
/** https://discord.com/developers/docs/topics/gateway#activity-object-activity-types */
export enum DiscordActivityTypes {
Game,
Streaming,
Listening,
Custom = 4,
Competing,
}

View File

@@ -0,0 +1,11 @@
export interface ClientStatus {
/** The user's status set for an active desktop (Windows, Linux, Mac) application session */
desktop?: string;
/** The user's status set for an active mobile (iOS, Android) application session */
mobile?: string;
/** The user's status set for an active web (browser, bot account) application session */
web?: string;
}
/** https://discord.com/developers/docs/topics/gateway#client-status-object */
export type DiscordClientStatus = ClientStatus;

View File

@@ -0,0 +1,20 @@
import { User } from "../users/user.ts";
import { SnakeCaseProps } from "../util.ts";
import { Activity } from "./activity.ts";
import { ClientStatus } from "./client_status.ts";
export interface PresenceUpdate {
/** The user presence is being updated for */
user: User;
/** id of the guild */
guild_id: string;
/** Either "idle", "dnd", "online", or "offline" */
status: "idle" | "dnd" | "online" | "offline";
/** User's current activities */
activities: Activity[];
/** User's platform-dependent status */
clientStatus: ClientStatus;
}
/** https://discord.com/developers/docs/topics/gateway#presence-update */
export type DiscordPresenceUpdate = SnakeCaseProps<PresenceUpdate>;

View File

@@ -0,0 +1,17 @@
import { SnakeCaseProps } from "../util.ts";
export interface TypingStart {
/** id of the channel */
channelId: string;
/** id of the guild */
guildId?: string;
/** id of the user */
userId: string;
/** Unix time (in seconds) of when the user started typing */
timestamp: number;
/** The member who started typing if this happened in a guild */
member?: GuildMember;
}
/** https://discord.com/developers/docs/topics/gateway#typing-start */
export type DiscordTypingStart = SnakeCaseProps<TypingStart>;

View File

@@ -0,0 +1,15 @@
import { SnakeCaseProps } from "../util.ts";
export interface UpdateVoiceState {
/** id of the guild */
guildId: string;
/** id of the voice channel client wants to join (null if disconnecting) */
channelId: string | null;
/** Is the client muted */
selfMute: boolean;
/** Is the client deafened */
selfDeaf: boolean;
}
/** https://discord.com/developers/docs/topics/gateway#update-voice-state */
export type DiscordUpdateVoiceState = SnakeCaseProps<UpdateVoiceState>;

View File

@@ -0,0 +1,13 @@
import { SnakeCaseProps } from "../util.ts";
export interface VoiceServerUpdate {
/** Voice connection token */
token: string;
/** The guild this voice server update is for */
guildId: string;
/** The voice server host */
endpoint: string;
}
/** https://discord.com/developers/docs/topics/gateway#voice-server-update */
export type DiscordVoiceServerUpdate = SnakeCaseProps<VoiceServerUpdate>;

View File

@@ -0,0 +1,11 @@
import { SnakeCaseProps } from "../util.ts";
export interface WebhooksUpdate {
/** id of the guild */
guildId: string;
/** id of the channel */
channelId: string;
}
/** https://discord.com/developers/docs/topics/gateway#webhooks-update */
export type DiscordWebhooksUpdate = SnakeCaseProps<WebhooksUpdate>;