2020-10-21 16:30:42 +00:00
|
|
|
// https://discord.com/developers/docs/topics/opcodes-and-status-codes#gateway
|
2020-10-22 15:50:47 +00:00
|
|
|
// https://discord.com/developers/docs/topics/gateway#commands-and-events-gateway-events
|
2020-10-31 12:33:34 +00:00
|
|
|
import { EmojiPayload } from './emoji.ts'
|
|
|
|
import { MemberPayload } from './guild.ts'
|
2020-11-02 06:58:23 +00:00
|
|
|
import { ActivityPayload } from './presence.ts'
|
2020-10-31 12:33:34 +00:00
|
|
|
import { RolePayload } from './role.ts'
|
|
|
|
import { UserPayload } from './user.ts'
|
2020-10-21 16:30:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gateway OPcodes from Discord docs.
|
|
|
|
*/
|
|
|
|
enum GatewayOpcodes { // 문서를 확인해본 결과 Opcode 5번은 비어있다. - UnderC -
|
|
|
|
DISPATCH = 0,
|
|
|
|
HEARTBEAT = 1,
|
|
|
|
IDENTIFY = 2,
|
|
|
|
PRESENCE_UPDATE = 3,
|
|
|
|
VOICE_STATE_UPDATE = 4,
|
|
|
|
RESUME = 6,
|
|
|
|
RECONNECT = 7,
|
|
|
|
REQUEST_GUILD_MEMBERS = 8,
|
|
|
|
INVALID_SESSION = 9,
|
|
|
|
HELLO = 10,
|
|
|
|
HEARTBEAT_ACK = 11
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gateway Close Codes from Discord docs.
|
|
|
|
*/
|
|
|
|
enum GatewayCloseCodes {
|
|
|
|
UNKNOWN_ERROR = 4000,
|
|
|
|
UNKNOWN_OPCODE = 4001,
|
|
|
|
DECODE_ERROR = 4002,
|
|
|
|
NOT_AUTHENTICATED = 4003,
|
|
|
|
AUTHENTICATION_FAILED = 4004,
|
|
|
|
ALREADY_AUTHENTICATED = 4005,
|
|
|
|
INVALID_SEQ = 4007,
|
|
|
|
RATE_LIMITED = 4008,
|
|
|
|
SESSION_TIMED_OUT = 4009,
|
|
|
|
INVALID_SHARD = 4010,
|
|
|
|
SHARDING_REQUIRED = 4011,
|
|
|
|
INVALID_API_VERSION = 4012,
|
|
|
|
INVALID_INTENTS = 4013,
|
|
|
|
DISALLOWED_INTENTS = 4014
|
|
|
|
}
|
|
|
|
|
|
|
|
enum GatewayIntents {
|
|
|
|
GUILDS = 1 << 0,
|
|
|
|
GUILD_MEMBERS = 1 << 1,
|
|
|
|
GUILD_BANS = 1 << 2,
|
|
|
|
GUILD_EMOJIS = 1 << 3,
|
|
|
|
GUILD_INTEGRATIONS = 1 << 4,
|
|
|
|
GUILD_WEBHOOKS = 1 << 5,
|
|
|
|
GUILD_INVITES = 1 << 6,
|
|
|
|
GUILD_VOICE_STATES = 1 << 7,
|
|
|
|
GUILD_PRESENCES = 1 << 8,
|
|
|
|
GUILD_MESSAGES = 1 << 9,
|
|
|
|
GUILD_MESSAGE_REACTIONS = 1 << 10,
|
|
|
|
GUILD_MESSAGE_TYPING = 1 << 11,
|
|
|
|
DIRECT_MESSAGES = 1 << 12,
|
|
|
|
DIRECT_MESSAGE_REACTIONS = 1 << 13,
|
|
|
|
DIRECT_MESSAGE_TYPING = 1 << 13
|
|
|
|
}
|
|
|
|
|
2020-10-22 15:50:47 +00:00
|
|
|
enum GatewayEvents {
|
|
|
|
Ready = 'READY',
|
|
|
|
Resumed = 'RESUMED',
|
|
|
|
Reconnect = 'RECONNECT',
|
|
|
|
Channel_Create = 'CHANNEL_CREATE',
|
|
|
|
Channel_Update = 'CHANNEL_UPDATE',
|
|
|
|
Channel_Delete = 'CHANNEL_DELETE',
|
2020-10-29 14:43:27 +00:00
|
|
|
Channel_Pins_Update = 'CHANNEL_PINS_UPDATE',
|
2020-10-22 15:50:47 +00:00
|
|
|
Guild_Create = 'GUILD_CREATE',
|
|
|
|
Guild_Update = 'GUILD_UPDATE',
|
|
|
|
Guild_Delete = 'GUILD_DELETE',
|
|
|
|
Guild_Ban_Add = 'GUILD_BAN_ADD',
|
|
|
|
Guild_Ban_Remove = 'GUILD_BAN_REMOVE',
|
|
|
|
Guild_Emojis_Update = 'GUILD_EMOJIS_UPDATE',
|
|
|
|
Guild_Integrations_Update = 'GUILD_INTEGRATIONS_UPDATE',
|
|
|
|
Guild_Member_Add = 'GUILD_MEMBER_ADD',
|
|
|
|
Guild_Member_Remove = 'GUILD_MEMBER_REMOVE',
|
|
|
|
Guild_Member_Update = 'GUILD_MEMBER_UPDATE',
|
|
|
|
Guild_Members_Chunk = 'GUILD_MEMBERS_CHUNK',
|
|
|
|
Guild_Role_Create = 'GUILD_ROLE_CREATE',
|
|
|
|
Guild_Role_Update = 'GUILD_ROLE_UPDATE',
|
|
|
|
Guild_Role_Delete = 'GUILD_ROLE_DELETE',
|
|
|
|
Invite_Create = 'INVITE_CREATE',
|
|
|
|
Invite_Delete = 'INVITE_DELETE',
|
|
|
|
Message_Create = 'MESSAGE_CREATE',
|
|
|
|
Message_Update = 'MESSAGE_UPDATE',
|
2020-10-30 14:51:40 +00:00
|
|
|
Message_Delete = 'MESSAGE_DELETE',
|
2020-10-22 15:50:47 +00:00
|
|
|
Message_Delete_Bulk = 'MESSAGE_DELETE_BULK',
|
|
|
|
Message_Reaction_Add = 'MESSAGE_REACTION_ADD',
|
|
|
|
Message_Reaction_Remove = 'MESSAGE_REACTION_REMOVE',
|
|
|
|
Message_Reaction_Remove_All = 'MESSAGE_REACTION_REMOVE_ALL',
|
|
|
|
Message_Reaction_Remove_Emoji = 'MESSAGE_REACTION_REMOVE_EMOJI',
|
|
|
|
Presence_Update = 'PRESENCE_UPDATE',
|
|
|
|
Typing_Start = 'TYPING_START',
|
|
|
|
User_Update = 'USER_UPDATE',
|
|
|
|
Voice_Server_Update = 'VOICE_SERVER_UPDATE',
|
|
|
|
Webhooks_Update = 'WEBHOOKS_UPDATE'
|
|
|
|
}
|
|
|
|
|
2020-11-02 06:58:23 +00:00
|
|
|
export interface IdentityPayload {
|
2020-10-22 15:50:47 +00:00
|
|
|
token: string
|
|
|
|
properties: IdentityConnection
|
|
|
|
compress?: boolean
|
|
|
|
large_threshold?: number
|
|
|
|
shard?: number[]
|
|
|
|
presence?: UpdateStatus
|
|
|
|
guildSubscriptions?: boolean
|
|
|
|
intents: number
|
|
|
|
}
|
|
|
|
|
|
|
|
enum UpdateStatus {
|
|
|
|
online = 'online',
|
|
|
|
dnd = 'dnd',
|
|
|
|
afk = 'idle',
|
|
|
|
invisible = 'invisible',
|
|
|
|
offline = 'offline'
|
|
|
|
}
|
|
|
|
|
2020-11-02 06:58:23 +00:00
|
|
|
export interface IdentityConnection {
|
2020-10-23 16:11:00 +00:00
|
|
|
$os: 'darwin' | 'windows' | 'linux' | 'custom os'
|
2020-10-22 15:50:47 +00:00
|
|
|
$browser: 'discord.deno'
|
|
|
|
$device: 'discord.deno'
|
|
|
|
}
|
|
|
|
|
2020-11-02 06:58:23 +00:00
|
|
|
export interface Resume {
|
2020-10-22 15:50:47 +00:00
|
|
|
token: string
|
|
|
|
session_id: string
|
|
|
|
seq: number
|
|
|
|
}
|
|
|
|
|
2020-11-02 06:58:23 +00:00
|
|
|
export interface GuildRequestMembers {
|
2020-10-22 15:50:47 +00:00
|
|
|
guild_id: string | string[]
|
|
|
|
query?: string
|
|
|
|
limit: number
|
2020-10-23 16:11:00 +00:00
|
|
|
presences?: boolean
|
2020-10-22 15:50:47 +00:00
|
|
|
user_ids?: string | string[]
|
|
|
|
nonce?: string
|
|
|
|
}
|
|
|
|
|
2020-11-02 06:58:23 +00:00
|
|
|
export interface GatewayVoiceStateUpdate {
|
2020-10-22 15:50:47 +00:00
|
|
|
guild_id: string
|
|
|
|
channel_id: string
|
|
|
|
self_mute: boolean
|
|
|
|
self_deaf: boolean
|
|
|
|
}
|
|
|
|
|
2020-11-02 06:58:23 +00:00
|
|
|
export interface GatewayStatusUpdate {
|
2020-10-22 15:50:47 +00:00
|
|
|
since: number | undefined
|
|
|
|
activities: ActivityPayload[]
|
|
|
|
status: string
|
|
|
|
afk: boolean
|
|
|
|
}
|
|
|
|
|
2020-11-02 06:58:23 +00:00
|
|
|
export interface Hello {
|
2020-10-22 15:50:47 +00:00
|
|
|
heartbeat_interval: number
|
|
|
|
}
|
|
|
|
|
2020-11-02 06:58:23 +00:00
|
|
|
export interface ReadyEvent {
|
2020-10-22 15:50:47 +00:00
|
|
|
v: number
|
2020-10-23 16:11:00 +00:00
|
|
|
user: UserPayload
|
2020-10-22 15:50:47 +00:00
|
|
|
privateChannels: []
|
|
|
|
guilds: []
|
|
|
|
session_id: string
|
|
|
|
shard?: number[]
|
|
|
|
}
|
|
|
|
|
2020-11-02 06:58:23 +00:00
|
|
|
export interface ChannelPinsUpdatePayload {
|
2020-10-22 15:50:47 +00:00
|
|
|
guild_id?: string
|
|
|
|
channel_id: string
|
|
|
|
last_pin_timestamp?: string
|
|
|
|
}
|
|
|
|
|
2020-11-02 06:58:23 +00:00
|
|
|
export interface GuildBanAddPayload {
|
2020-10-22 15:50:47 +00:00
|
|
|
guild_id: string
|
2020-10-23 16:11:00 +00:00
|
|
|
user: UserPayload
|
2020-10-22 15:50:47 +00:00
|
|
|
}
|
|
|
|
|
2020-11-02 06:58:23 +00:00
|
|
|
export interface GuildBanRemovePayload {
|
2020-10-22 15:50:47 +00:00
|
|
|
guild_id: string
|
2020-10-23 16:11:00 +00:00
|
|
|
user: UserPayload
|
2020-10-22 15:50:47 +00:00
|
|
|
}
|
|
|
|
|
2020-11-02 06:58:23 +00:00
|
|
|
export interface GuildEmojiUpdatePayload {
|
2020-10-22 15:50:47 +00:00
|
|
|
guild_id: string
|
|
|
|
emojis: []
|
|
|
|
}
|
|
|
|
|
2020-11-02 06:58:23 +00:00
|
|
|
export interface GuildIntegrationsUpdatePayload {
|
2020-10-22 15:50:47 +00:00
|
|
|
guild_id: string
|
|
|
|
}
|
|
|
|
|
2020-11-02 06:58:23 +00:00
|
|
|
export interface GuildMemberAddPayload {
|
2020-10-22 15:50:47 +00:00
|
|
|
guild_id: string
|
|
|
|
}
|
|
|
|
|
2020-11-02 06:58:23 +00:00
|
|
|
export interface GuildMemberRemovePayload {
|
2020-10-22 15:50:47 +00:00
|
|
|
guild_id: string
|
2020-10-23 16:11:00 +00:00
|
|
|
user: UserPayload
|
2020-10-22 15:50:47 +00:00
|
|
|
}
|
2020-11-02 06:58:23 +00:00
|
|
|
export interface GuildMemberUpdatePayload {
|
2020-10-22 15:50:47 +00:00
|
|
|
guild_id: string
|
|
|
|
roles: string[]
|
2020-10-23 16:11:00 +00:00
|
|
|
user: UserPayload
|
2020-10-22 15:50:47 +00:00
|
|
|
nick?: string | undefined
|
|
|
|
joined_at: string
|
|
|
|
premium_since?: string | undefined
|
|
|
|
}
|
|
|
|
|
2020-11-02 06:58:23 +00:00
|
|
|
export interface GuildMemberChunkPayload {
|
2020-10-22 15:50:47 +00:00
|
|
|
guild_id: string
|
|
|
|
members: MemberPayload[]
|
|
|
|
chunk_index: number
|
|
|
|
chunk_count: number
|
|
|
|
not_found?: []
|
|
|
|
presences?: PresenceUpdatePayload[]
|
|
|
|
nonce?: string
|
|
|
|
}
|
|
|
|
|
2020-11-02 06:58:23 +00:00
|
|
|
export interface GuildRoleCreatePayload {
|
2020-10-22 15:50:47 +00:00
|
|
|
guild_id: string
|
2020-10-23 16:11:00 +00:00
|
|
|
role: RolePayload
|
2020-10-22 15:50:47 +00:00
|
|
|
}
|
|
|
|
|
2020-11-02 06:58:23 +00:00
|
|
|
export interface GuildRoleUpdatePayload {
|
2020-10-22 15:50:47 +00:00
|
|
|
guild_id: string
|
2020-10-23 16:11:00 +00:00
|
|
|
role: RolePayload
|
2020-10-22 15:50:47 +00:00
|
|
|
}
|
|
|
|
|
2020-11-02 06:58:23 +00:00
|
|
|
export interface GuildRoleDeletePayload {
|
2020-10-22 15:50:47 +00:00
|
|
|
guild_id: string
|
|
|
|
role_id: string
|
|
|
|
}
|
|
|
|
|
2020-11-02 06:58:23 +00:00
|
|
|
export interface InviteCreatePayload {
|
2020-10-22 15:50:47 +00:00
|
|
|
channel_id: string
|
|
|
|
code: string
|
|
|
|
created_at: string
|
|
|
|
guild_id?: string
|
2020-10-23 16:11:00 +00:00
|
|
|
inviter?: UserPayload
|
2020-10-22 15:50:47 +00:00
|
|
|
max_age: number
|
|
|
|
max_uses: number
|
2020-10-23 16:11:00 +00:00
|
|
|
target_user?: UserPayload
|
2020-10-22 15:50:47 +00:00
|
|
|
target_user_type?: number
|
|
|
|
temporary: boolean
|
|
|
|
uses: number
|
|
|
|
}
|
|
|
|
|
2020-11-02 06:58:23 +00:00
|
|
|
export interface InviteDeletePayload {
|
2020-10-22 15:50:47 +00:00
|
|
|
channel_id: string
|
|
|
|
guild_id?: string
|
|
|
|
code: string
|
|
|
|
}
|
|
|
|
|
2020-11-02 06:58:23 +00:00
|
|
|
export interface MessageDeletePayload {
|
2020-10-22 15:50:47 +00:00
|
|
|
id: string
|
|
|
|
channel_id: string
|
|
|
|
guild_id?: string
|
|
|
|
}
|
|
|
|
|
2020-11-02 06:58:23 +00:00
|
|
|
export interface MessageDeleteBulkPayload {
|
2020-10-22 15:50:47 +00:00
|
|
|
ids: string[]
|
|
|
|
channel_id: string
|
|
|
|
guild_id: string
|
|
|
|
}
|
|
|
|
|
2020-11-02 06:58:23 +00:00
|
|
|
export interface MessageReactionAddPayload {
|
2020-10-22 15:50:47 +00:00
|
|
|
user_id: string
|
|
|
|
channel_id: string
|
|
|
|
message_id: string
|
|
|
|
guild_id?: string
|
2020-10-23 16:11:00 +00:00
|
|
|
emoji: EmojiPayload
|
2020-10-22 15:50:47 +00:00
|
|
|
}
|
|
|
|
|
2020-11-02 06:58:23 +00:00
|
|
|
export interface MessageReactionRemovePayload {
|
2020-10-22 15:50:47 +00:00
|
|
|
user_id: string
|
|
|
|
channel_id: string
|
|
|
|
message_id: string
|
|
|
|
guild_id?: string
|
2020-10-23 16:11:00 +00:00
|
|
|
emoji: EmojiPayload
|
2020-10-22 15:50:47 +00:00
|
|
|
}
|
|
|
|
|
2020-11-02 06:58:23 +00:00
|
|
|
export interface MessageReactionRemoveAllPayload {
|
2020-10-22 15:50:47 +00:00
|
|
|
channel_id: string
|
|
|
|
guild_id?: string
|
|
|
|
message_id: string
|
|
|
|
}
|
|
|
|
|
2020-11-02 06:58:23 +00:00
|
|
|
export interface PresenceUpdatePayload {
|
2020-10-23 16:11:00 +00:00
|
|
|
user: UserPayload
|
2020-10-22 15:50:47 +00:00
|
|
|
guild_id: string
|
|
|
|
status: string
|
|
|
|
activities: ActivityPayload[]
|
|
|
|
client_status: UpdateStatus[]
|
|
|
|
}
|
|
|
|
|
2020-11-02 06:58:23 +00:00
|
|
|
export interface TypeStart {
|
2020-10-23 03:19:40 +00:00
|
|
|
channel_id: string
|
|
|
|
guild_id?: string
|
|
|
|
user_id: string
|
|
|
|
timestamp: number
|
2020-10-23 16:11:00 +00:00
|
|
|
member?: MemberPayload
|
2020-10-23 03:19:40 +00:00
|
|
|
}
|
|
|
|
|
2020-11-02 06:58:23 +00:00
|
|
|
export interface VoiceServerUpdatePayload {
|
2020-10-23 03:19:40 +00:00
|
|
|
token: string
|
|
|
|
guild_id: string
|
|
|
|
endpoint: string
|
|
|
|
}
|
|
|
|
|
2020-11-02 06:58:23 +00:00
|
|
|
export interface WebhooksUpdatePayload {
|
2020-10-23 03:19:40 +00:00
|
|
|
guild_id: string
|
|
|
|
channel_id: string
|
|
|
|
}
|
|
|
|
|
2020-10-30 14:51:40 +00:00
|
|
|
// https://discord.com/developers/docs/topics/gateway#typing-start-typing-start-event-fields
|
2020-11-02 06:58:23 +00:00
|
|
|
export {
|
|
|
|
GatewayCloseCodes,
|
|
|
|
GatewayOpcodes,
|
|
|
|
GatewayIntents,
|
|
|
|
GatewayEvents,
|
|
|
|
UpdateStatus
|
|
|
|
}
|