Caching, Fetching, and other things

- Make the gateway fetches guilds from Discord response
- Fetch guilds with only ID and client
- Make more types
- Fix lint errors

Co-Authored-By: Y <8479056+yky4589@users.noreply.github.com>
Co-Authored-By: khk4912 <30457148+khk4912@users.noreply.github.com>
Co-Authored-By: Aki <71239005+AkiaCode@users.noreply.github.com>
Co-Authored-By: Choi Minseo <minseo0388@outlook.com>
This commit is contained in:
Helloyunho 2020-10-24 01:11:00 +09:00
parent 01d9b82f47
commit 1e8475456a
35 changed files with 667 additions and 358 deletions

46
src/models/cache.ts Normal file
View File

@ -0,0 +1,46 @@
let caches: any = {}
const get = (cacheName: string, key: string) => {
const gotCache: Map<string, any> = caches[cacheName]
if (gotCache === undefined || !(gotCache instanceof Map)) {
return undefined
}
const gotMap = gotCache.get(key)
return gotMap
}
const set = (cacheName: string, key: string, value: any) => {
let gotCache: Map<string, any> = caches[cacheName]
if (gotCache === undefined || !(gotCache instanceof Map)) {
gotCache = caches[cacheName] = new Map<string, any>()
}
gotCache.set(key, value)
return value
}
const del = (cacheName: string, key: string) => {
const gotCache: Map<string, any> = caches[cacheName]
if (gotCache === undefined || !(gotCache instanceof Map)) {
return
}
return gotCache.delete(key)
}
const deleteCache = (cacheName: string) => {
const gotCache = caches[cacheName]
if (gotCache === undefined) {
return
}
delete caches[cacheName]
}
const resetCaches = () => {
caches = {}
}
export { get, set, del, deleteCache, resetCaches }

View File

@ -1,7 +1,7 @@
import { User } from '../structures/user.ts' import { User } from '../structures/user.ts'
import { GatewayIntents } from '../types/gatewayTypes.ts' import { GatewayIntents } from '../types/gatewayTypes.ts'
import { Gateway } from './gateway.ts' import { Gateway } from './gateway.ts'
import { Rest } from "./rest.ts" import { Rest } from './rest.ts'
/** /**
* Discord Client. * Discord Client.
@ -11,6 +11,7 @@ export class Client {
rest?: Rest rest?: Rest
user?: User user?: User
ping = 0 ping = 0
token?: string
constructor () {} constructor () {}
@ -20,6 +21,7 @@ export class Client {
* @param intents Gateway intents in array. This is required. * @param intents Gateway intents in array. This is required.
*/ */
connect (token: string, intents: GatewayIntents[]) { connect (token: string, intents: GatewayIntents[]) {
this.token = token
this.gateway = new Gateway(this, token, intents) this.gateway = new Gateway(this, token, intents)
} }
} }

View File

@ -10,7 +10,10 @@ import {
GatewayIntents, GatewayIntents,
GatewayEvents GatewayEvents
} from '../types/gatewayTypes.ts' } from '../types/gatewayTypes.ts'
import { GuildPayload } from '../types/guildTypes.ts'
import { User } from '../structures/user.ts' import { User } from '../structures/user.ts'
import * as cache from './cache.ts'
import { Guild } from '../structures/guild.ts'
/** /**
* Handles Discord gateway connection. * Handles Discord gateway connection.
@ -48,11 +51,11 @@ class Gateway {
this.websocket.onerror = this.onerror.bind(this) this.websocket.onerror = this.onerror.bind(this)
} }
onopen () { private onopen () {
this.connected = true this.connected = true
} }
onmessage (event: MessageEvent) { private onmessage (event: MessageEvent) {
let data = event.data let data = event.data
if (data instanceof ArrayBuffer) { if (data instanceof ArrayBuffer) {
data = new Uint8Array(data) data = new Uint8Array(data)
@ -114,6 +117,7 @@ class Gateway {
break break
case GatewayOpcodes.DISPATCH: case GatewayOpcodes.DISPATCH:
this.heartbeatServerResponded = true
if (s !== null) { if (s !== null) {
this.sequenceID = s this.sequenceID = s
} }
@ -121,6 +125,9 @@ class Gateway {
case GatewayEvents.Ready: case GatewayEvents.Ready:
this.client.user = new User(this.client, d.user) this.client.user = new User(this.client, d.user)
this.sessionID = d.session_id this.sessionID = d.session_id
d.guilds.forEach((guild: GuildPayload) => {
cache.set('guilds', guild.id, new Guild(this.client, guild))
})
break break
default: default:
break break
@ -131,17 +138,17 @@ class Gateway {
} }
} }
onclose (event: CloseEvent) { private onclose (event: CloseEvent) {
// TODO: Handle close event codes. // TODO: Handle close event codes.
} }
onerror (event: Event | ErrorEvent) { private onerror (event: Event | ErrorEvent) {
const eventError = event as ErrorEvent const eventError = event as ErrorEvent
console.log(eventError) console.log(eventError)
} }
sendIdentify () { private sendIdentify () {
this.websocket.send( this.websocket.send(
JSON.stringify({ JSON.stringify({
op: GatewayOpcodes.IDENTIFY, op: GatewayOpcodes.IDENTIFY,

View File

@ -1,12 +1,12 @@
import { Client } from "./client.ts"; import { Client } from './client.ts'
class Rest { class Rest {
client: Client client: Client
constructor(client: Client) { constructor (client: Client) {
this.client = client this.client = client
} }
//TODO: make endpoints function //TODO: make endpoints function
} }
export { Rest } export { Rest }

View File

@ -0,0 +1,26 @@
import { Client } from '../models/client.ts'
import { Channel } from './channel.ts'
import { GuildPayload, GuildFeatures } from '../types/guildTypes.ts'
import {
GuildChannelCategoryPayload,
Overwrite
} from '../types/channelTypes.ts'
export class categoryChannel extends Channel {
guildID: string
name: string
position: number
permissionOverwrites: Overwrite[]
nsfw: boolean
parentID?: string
constructor (client: Client, data: GuildChannelCategoryPayload) {
super(client, data)
this.guildID = data.guild_id
this.name = data.name
this.position = data.position
this.permissionOverwrites = data.permission_overwrites
this.nsfw = data.nsfw
this.parentID = data.parent_id
}
}

View File

@ -1,7 +1,18 @@
import { Client } from '../models/client.ts' import { Client } from '../models/client.ts'
import { ChannelPayload, ChannelTypes } from '../types/channelTypes.ts' import {
ChannelPayload,
GuildChannelCategoryPayload,
GuildNewsChannelPayload,
GuildTextChannelPayload,
GuildVoiceChannelPayload,
DMChannelPayload,
GroupDMChannelPayload,
ChannelTypes
} from '../types/channelTypes.ts'
import { Base } from './base.ts' import { Base } from './base.ts'
import { PrivateChannel } from './dm.ts' import { DMChannel } from './dm.ts'
import { GroupChannel } from './groupChannel.ts'
import { VoiceChannel } from './guildVoiceChannel.ts'
import { TextChannel } from './textChannel.ts' import { TextChannel } from './textChannel.ts'
export class Channel extends Base { export class Channel extends Base {
@ -18,12 +29,29 @@ export class Channel extends Base {
return `<#${this.id}>` return `<#${this.id}>`
} }
static from (data: ChannelPayload, client: Client) { static from (
data:
| GuildChannelCategoryPayload
| GuildNewsChannelPayload
| GuildTextChannelPayload
| GuildVoiceChannelPayload
| DMChannelPayload
| GroupDMChannelPayload,
client: Client
) {
switch (data.type) { switch (data.type) {
case ChannelTypes.GUILD_CATEGORY:
return
case ChannelTypes.GUILD_NEWS:
return
case ChannelTypes.GUILD_TEXT: case ChannelTypes.GUILD_TEXT:
return new TextChannel(client, data) return new TextChannel(client, data as GuildTextChannelPayload)
case ChannelTypes.GUILD_VOICE:
return new VoiceChannel(client, data as GuildVoiceChannelPayload)
case ChannelTypes.DM: case ChannelTypes.DM:
return new PrivateChannel(client, data) return new DMChannel(client, data as DMChannelPayload)
case ChannelTypes.GROUP_DM:
return new GroupChannel(client, data as GroupDMChannelPayload)
} }
} }
} }

View File

@ -1,9 +1,13 @@
import { Client } from '../models/client.ts' import { Client } from '../models/client.ts'
import { ChannelPayload } from '../types/channelTypes.ts' import { DMChannelPayload } from '../types/channelTypes.ts'
import { Channel } from './channel.ts' import { UserPayload } from '../types/userTypes.ts'
import { TextChannel } from './textChannel.ts'
export class PrivateChannel extends Channel implements ChannelPayload { export class DMChannel extends TextChannel {
constructor (client: Client, data: ChannelPayload) { recipients: UserPayload[]
constructor (client: Client, data: DMChannelPayload) {
super(client, data) super(client, data)
this.recipients = data.recipients
} }
} }

View File

@ -12,7 +12,7 @@ import {
} from '../types/channelTypes.ts' } from '../types/channelTypes.ts'
import { Base } from './base.ts' import { Base } from './base.ts'
export class Embed extends Base implements EmbedPayload { export class Embed extends Base {
title?: string title?: string
type?: EmbedTypes type?: EmbedTypes
description?: string description?: string

View File

@ -1,21 +1,22 @@
import { Client } from '../models/client.ts' import { Client } from '../models/client.ts'
import { EmojiPayload } from '../types/emojiTypes.ts' import { EmojiPayload } from '../types/emojiTypes.ts'
import { UserPayload } from '../types/userTypes.ts'
import { Base } from './base.ts' import { Base } from './base.ts'
import { User } from './user.ts' import { User } from './user.ts'
export class Emoji extends Base implements EmojiPayload { export class Emoji extends Base {
id: string id: string
name: string name: string
roles?: [] roles?: []
user?: User user?: UserPayload
require_colons?: boolean requireColons?: boolean
managed?: boolean managed?: boolean
animated?: boolean animated?: boolean
available?: boolean available?: boolean
get CustomEmoji () { get CustomEmoji () {
if (this.animated === false) { if (this.animated === false) {
return `<:${this.name}:${this.id}>` return `<:${this.name}:${this.id}>`
} else return `<a:${this.name}:${this.id}>` } else return `<a:${this.name}:${this.id}>`
} }
@ -25,7 +26,7 @@ export class Emoji extends Base implements EmojiPayload {
this.name = data.name this.name = data.name
this.roles = data.roles this.roles = data.roles
this.user = data.user this.user = data.user
this.require_colons = data.require_colons this.requireColons = data.require_colons
this.managed = data.managed this.managed = data.managed
this.animated = data.animated this.animated = data.animated
this.available = data.available this.available = data.available

View File

@ -0,0 +1,17 @@
import { Client } from '../models/client.ts'
import { GroupDMChannelPayload } from '../types/channelTypes.ts'
import { Channel } from './channel.ts'
export class GroupChannel extends Channel {
name: string
icon?: string
ownerID: string
constructor (client: Client, data: GroupDMChannelPayload) {
super(client, data)
this.name = data.name
this.icon = data.icon
this.ownerID = data.owner_id
}
}

View File

@ -1,106 +1,129 @@
import { Client } from '../models/client.ts' import { Client } from '../models/client.ts'
import { ChannelPayload } from '../types/channelTypes.ts'
import { EmojiPayload } from '../types/emojiTypes.ts' import { EmojiPayload } from '../types/emojiTypes.ts'
import { GuildFeatures, GuildPayload } from '../types/guildTypes.ts' import { GUILD } from '../types/endpoint.ts'
import {
GuildFeatures,
GuildPayload,
MemberPayload
} from '../types/guildTypes.ts'
import { PresenceUpdatePayload } from '../types/presenceTypes.ts' import { PresenceUpdatePayload } from '../types/presenceTypes.ts'
import { RolePayload } from '../types/roleTypes.ts'
import { VoiceStatePayload } from '../types/voiceTypes.ts' import { VoiceStatePayload } from '../types/voiceTypes.ts'
import { Base } from './base.ts' import { Base } from './base.ts'
import { Channel } from './channel.ts'
import { Emoji } from './emoji.ts'
import { Member } from './member.ts'
import { Role } from './role.ts' import { Role } from './role.ts'
import * as cache from '../models/cache.ts'
export class Guild extends Base implements GuildPayload { export class Guild extends Base {
id: string id: string
name: string name: string
icon: string | undefined icon?: string
icon_hash?: string | undefined iconHash?: string
splash: string | undefined splash?: string
discovery_splash: string | undefined discoverySplash?: string
owner?: boolean | undefined owner?: boolean
owner_id: string ownerID: string
permissions?: string | undefined permissions?: string
region: string region: string
afk_channel_id: string | undefined afkChannelID?: string
afk_timeout: number afkTimeout: number
widget_enabled?: boolean | undefined widgetEnabled?: boolean
widge_channel_id?: string | undefined widgetChannelID?: string
verification_level: string verificationLevel: string
default_message_notifications: string defaultMessageNotifications: string
explicit_content_filter: string explicitContentFilter: string
roles: Role[] roles: RolePayload[]
emojis: Emoji[] emojis: EmojiPayload[]
features: GuildFeatures[] features: GuildFeatures[]
mfa_level: string mfaLevel: string
application_id: string | undefined applicationID?: string
system_channel_id: string | undefined systemChannelID?: string
system_channel_flags: string systemChannelFlags: string
rules_channel_id: string | undefined rulesChannelID?: string
joined_at?: string | undefined joinedAt?: string
large?: boolean | undefined large?: boolean
unavailable: boolean unavailable: boolean
member_count?: number | undefined memberCount?: number
voice_states?: VoiceStatePayload[] | undefined voiceStates?: VoiceStatePayload[]
members?: Member[] | undefined members?: MemberPayload[]
channels?: Channel[] | undefined channels?: ChannelPayload[]
presences?: PresenceUpdatePayload[] | undefined presences?: PresenceUpdatePayload[]
max_presences?: number | undefined maxPresences?: number
max_members?: number | undefined maxMembers?: number
vanity_url_code: string | undefined vanityURLCode?: string
description: string | undefined description?: string
banner: string | undefined banner?: string
premium_tier: number premiumTier: number
premium_subscription_count?: number | undefined premiumSubscriptionCount?: number
preferred_locale: string preferredLocale: string
public_updates_channel_id: string | undefined publicUpdatesChannelID?: string
max_video_channel_users?: number | undefined maxVideoChannelUsers?: number
approximate_number_count?: number | undefined approximateNumberCount?: number
approximate_presence_count?: number | undefined approximatePresenceCount?: number
constructor (client: Client, data: GuildPayload) { constructor (client: Client, data: GuildPayload) {
super(client) super(client)
this.id = data.id this.id = data.id
this.name = data.name this.name = data.name
this.icon = data.icon this.icon = data.icon
this.icon_hash = data.icon_hash this.iconHash = data.icon_hash
this.splash = data.splash this.splash = data.splash
this.discovery_splash = data.discovery_splash this.discoverySplash = data.discovery_splash
this.owner = data.owner this.owner = data.owner
this.owner_id = data.owner_id this.ownerID = data.owner_id
this.permissions = data.permissions this.permissions = data.permissions
this.region = data.region this.region = data.region
this.afk_timeout = data.afk_timeout this.afkTimeout = data.afk_timeout
this.afk_channel_id = data.afk_channel_id this.afkChannelID = data.afk_channel_id
this.widget_enabled = data.widget_enabled this.widgetEnabled = data.widget_enabled
this.widge_channel_id = data.widge_channel_id this.widgetChannelID = data.widge_channel_id
this.verification_level = data.verification_level this.verificationLevel = data.verification_level
this.default_message_notifications = data.default_message_notifications this.defaultMessageNotifications = data.default_message_notifications
this.explicit_content_filter = data.explicit_content_filter this.explicitContentFilter = data.explicit_content_filter
this.roles = data.roles this.roles = data.roles
this.emojis = data.emojis this.emojis = data.emojis
this.features = data.features this.features = data.features
this.mfa_level = data.mfa_level this.mfaLevel = data.mfa_level
this.system_channel_id = data.system_channel_id this.systemChannelID = data.system_channel_id
this.system_channel_flags = data.system_channel_flags this.systemChannelFlags = data.system_channel_flags
this.rules_channel_id = data.rules_channel_id this.rulesChannelID = data.rules_channel_id
this.joined_at = data.joined_at this.joinedAt = data.joined_at
this.large = data.large this.large = data.large
this.unavailable = data.unavailable this.unavailable = data.unavailable
this.member_count = data.member_count this.memberCount = data.member_count
this.voice_states = data.voice_states this.voiceStates = data.voice_states
this.members = data.members this.members = data.members
this.channels = data.channels this.channels = data.channels
this.presences = data.presences this.presences = data.presences
this.max_presences = data.max_presences this.maxPresences = data.max_presences
this.max_members = data.max_members this.maxMembers = data.max_members
this.vanity_url_code = data.vanity_url_code this.vanityURLCode = data.vanity_url_code
this.description = data.description this.description = data.description
this.banner = data.banner this.banner = data.banner
this.premium_tier = data.premium_tier this.premiumTier = data.premium_tier
this.premium_subscription_count = data.premium_subscription_count this.premiumSubscriptionCount = data.premium_subscription_count
this.preferred_locale = data.preferred_locale this.preferredLocale = data.preferred_locale
this.public_updates_channel_id = data.public_updates_channel_id this.publicUpdatesChannelID = data.public_updates_channel_id
this.max_video_channel_users = data.max_video_channel_users this.maxVideoChannelUsers = data.max_video_channel_users
this.approximate_number_count = data.approximate_number_count this.approximateNumberCount = data.approximate_number_count
this.approximate_presence_count = data.approximate_presence_count this.approximatePresenceCount = data.approximate_presence_count
}
static async autoInit (client: Client, guildID: string) {
const cached = cache.get('guilds', guildID)
if (cached === undefined || !(cached instanceof Guild)) {
const resp = await fetch(GUILD(guildID), {
headers: {
Authorization: `Bot ${client.token}`
}
})
const guildParsed: GuildPayload = await resp.json()
const newGuild = new Guild(client, guildParsed)
cache.set('guilds', guildID, newGuild)
return newGuild
} else {
return cached
}
} }
} }

View File

@ -1,9 +1,22 @@
import { Client } from '../models/client.ts' import { Client } from '../models/client.ts'
import { ChannelPayload } from '../types/channelTypes.ts' import { GuildChannelPayload, Overwrite } from '../types/channelTypes.ts'
import { Channel } from './channel.ts' import { Channel } from './channel.ts'
export class GuildChannel extends Channel { export class GuildChannel extends Channel {
constructor (client: Client, data: ChannelPayload) { guildID: string
name: string
position: number
permissionOverwrites: Overwrite[]
nsfw: boolean
parentID?: string
constructor (client: Client, data: GuildChannelPayload) {
super(client, data) super(client, data)
this.guildID = data.guild_id
this.name = data.name
this.position = data.position
this.permissionOverwrites = data.permission_overwrites
this.nsfw = data.nsfw
this.parentID = data.parent_id
} }
} }

View File

@ -0,0 +1,19 @@
import { Client } from '../models/client.ts'
import { GuildChannel } from './guildChannel.ts'
import { GuildTextChannelPayload } from '../types/channelTypes.ts'
import { User } from './user.ts'
export class GuildTextChannel extends GuildChannel {
rateLimit: number
topic?: string
get mention () {
return `<#${this.id}>`
}
constructor (client: Client, data: GuildTextChannelPayload) {
super(client, data)
this.topic = data.topic
this.rateLimit = data.rate_limit_per_user
}
}

View File

@ -0,0 +1,28 @@
import { Client } from '../models/client.ts'
import { GuildVoiceChannelPayload, Overwrite } from '../types/channelTypes.ts'
import { Base } from './base.ts'
import { Member } from './member.ts'
import { Channel } from './channel.ts'
export class VoiceChannel extends Channel {
bitrate: string
userLimit: number
guildID: string
name: string
position: number
permissionOverwrites: Overwrite[]
nsfw: boolean
parentID?: string
constructor (client: Client, data: GuildVoiceChannelPayload) {
super(client, data)
this.bitrate = data.bitrate
this.userLimit = data.user_limit
this.guildID = data.guild_id
this.name = data.name
this.position = data.position
this.permissionOverwrites = data.permission_overwrites
this.nsfw = data.nsfw
this.parentID = data.parent_id
}
}

View File

@ -2,22 +2,24 @@ import { Client } from '../models/client.ts'
import { Channel } from '../structures/channel.ts' import { Channel } from '../structures/channel.ts'
import { Guild } from '../structures/guild.ts' import { Guild } from '../structures/guild.ts'
import { User } from '../structures/user.ts' import { User } from '../structures/user.ts'
import { ChannelPayload } from '../types/channelTypes.ts'
import { GuildPayload } from '../types/guildTypes.ts'
import { InvitePayload } from '../types/inviteTypes.ts' import { InvitePayload } from '../types/inviteTypes.ts'
import { UserPayload } from '../types/userTypes.ts'
import { Base } from './base.ts' import { Base } from './base.ts'
export class Invite extends Base implements InvitePayload { export class Invite extends Base {
code: string code: string
guild?: Guild guild?: GuildPayload
channel: Channel channel: ChannelPayload
inviter?: User inviter?: UserPayload
target_user?: User targetUser?: UserPayload
target_user_type?: number targetUserType?: number
approximate_presence_count?: number approximatePresenceCount?: number
approximate_member_count?: number approximateMemberCount?: number
get link () { get link () {
return `discord.gg/${this.code}` return `https://discord.gg/${this.code}`
} }
constructor (client: Client, data: InvitePayload) { constructor (client: Client, data: InvitePayload) {
@ -26,9 +28,9 @@ export class Invite extends Base implements InvitePayload {
this.guild = data.guild this.guild = data.guild
this.channel = data.channel this.channel = data.channel
this.inviter = data.inviter this.inviter = data.inviter
this.target_user = data.target_user this.targetUser = data.target_user
this.target_user_type = data.target_user_type this.targetUserType = data.target_user_type
this.approximate_member_count = data.approximate_member_count this.approximateMemberCount = data.approximate_member_count
this.approximate_presence_count = data.approximate_presence_count this.approximatePresenceCount = data.approximate_presence_count
} }
} }

View File

@ -1,17 +1,18 @@
import { Client } from '../models/client.ts' import { Client } from '../models/client.ts'
import { MemberPayload } from '../types/guildTypes.ts' import { MemberPayload } from '../types/guildTypes.ts'
import { RolePayload } from '../types/roleTypes.ts'
import { UserPayload } from '../types/userTypes.ts' import { UserPayload } from '../types/userTypes.ts'
import { Base } from './base.ts' import { Base } from './base.ts'
import { Guild } from './guild.ts' import { Guild } from './guild.ts'
import { Role } from './role.ts' import { Role } from './role.ts'
import { User } from './user.ts' import { User } from './user.ts'
export class Member extends Base implements MemberPayload { export class Member extends Base {
user: User user: UserPayload
nick: string | undefined nick?: string
roles: Role[] roles: RolePayload[]
joined_at: string joinedAt: string
premium_since?: string | undefined premiumSince?: string
deaf: boolean deaf: boolean
mute: boolean mute: boolean
@ -20,8 +21,8 @@ export class Member extends Base implements MemberPayload {
this.user = data.user this.user = data.user
this.nick = data.nick this.nick = data.nick
this.roles = data.roles this.roles = data.roles
this.joined_at = data.joined_at this.joinedAt = data.joined_at
this.premium_since = data.premium_since this.premiumSince = data.premium_since
this.deaf = data.deaf this.deaf = data.deaf
this.mute = data.mute this.mute = data.mute
} }

View File

@ -13,57 +13,59 @@ import { Client } from '../models/client.ts'
import { User } from './user.ts' import { User } from './user.ts'
import { Role } from './role.ts' import { Role } from './role.ts'
import { Embed } from './embed.ts' import { Embed } from './embed.ts'
import { UserPayload } from '../types/userTypes.ts'
import { RolePayload } from '../types/roleTypes.ts'
class Message extends Base implements MessagePayload { class Message extends Base {
id: string id: string
channel_id: string channelID: string
guild_id?: string | undefined guildID?: string
author: User author: UserPayload
member?: any member?: any
content: string content: string
timestamp: string timestamp: string
edited_timestamp: string | undefined editedTimestamp?: string
tts: boolean tts: boolean
mention_everyone: boolean mentionEveryone: boolean
mentions: User[] mentions: UserPayload[]
mention_roles: Role[] mentionRoles: RolePayload[]
mention_channels?: ChannelMention[] | undefined mentionChannels?: ChannelMention[]
attachments: Attachment[] attachments: Attachment[]
embeds: EmbedPayload[] embeds: EmbedPayload[]
reactions?: Reaction[] | undefined reactions?: Reaction[]
nonce?: string | number | undefined nonce?: string | number
pinned: boolean pinned: boolean
webhook_id?: string | undefined webhookId?: string
type: number type: number
activity?: MessageActivity activity?: MessageActivity
application?: MessageApplication application?: MessageApplication
message_reference?: MessageReference messageReference?: MessageReference
flags?: number | undefined flags?: number
constructor (client: Client, data: MessagePayload) { constructor (client: Client, data: MessagePayload) {
super(client) super(client)
this.id = data.id this.id = data.id
this.channel_id = data.channel_id this.channelID = data.channel_id
this.guild_id = data.guild_id this.guildID = data.guild_id
this.author = data.author this.author = data.author
this.member = data.member this.member = data.member
this.content = data.content this.content = data.content
this.timestamp = data.timestamp this.timestamp = data.timestamp
this.edited_timestamp = data.edited_timestamp this.editedTimestamp = data.edited_timestamp
this.tts = data.tts this.tts = data.tts
this.mention_everyone = data.mention_everyone this.mentionEveryone = data.mention_everyone
this.mentions = data.mentions this.mentions = data.mentions
this.mention_roles = data.mention_roles this.mentionRoles = data.mention_roles
this.attachments = data.attachments this.attachments = data.attachments
this.embeds = data.embeds this.embeds = data.embeds
this.reactions = data.reactions this.reactions = data.reactions
this.nonce = data.nonce this.nonce = data.nonce
this.pinned = data.pinned this.pinned = data.pinned
this.webhook_id = data.webhook_id this.webhookId = data.webhook_id
this.type = data.type this.type = data.type
this.activity = data.activity this.activity = data.activity
this.application = data.application this.application = data.application
this.message_reference = data.message_reference this.messageReference = data.message_reference
this.flags = data.flags this.flags = data.flags
} }
} }

View File

@ -2,7 +2,7 @@ import { Client } from '../models/client.ts'
import { Base } from './base.ts' import { Base } from './base.ts'
import { RolePayload } from '../types/roleTypes.ts' import { RolePayload } from '../types/roleTypes.ts'
export class Role extends Base implements RolePayload { export class Role extends Base {
id: string id: string
name: string name: string
color: number color: number

View File

@ -1,36 +1,16 @@
import { Client } from '../models/client.ts' import { Client } from '../models/client.ts'
import { GuildChannel } from './guildChannel.ts' import { TextChannelPayload } from '../types/channelTypes.ts'
import { ChannelPayload } from '../types/channelTypes.ts' import { Channel } from './channel.ts'
import { User } from './user.ts' import { Embed } from './embed.ts'
export class TextChannel extends Channel {
lastMessageId?: string
lastPinTimestamp?: string
export class TextChannel extends GuildChannel implements ChannelPayload { constructor (client: Client, data: TextChannelPayload) {
id: string
type: number
guild_id?: string | undefined
position?: number | undefined
approximate_member_count?: any
name?: string | undefined
topic?: string | undefined
nsfw?: boolean | undefined
last_message_id?: string | undefined
bitrate?: number | undefined
user_limit?: number | undefined
rate_limit_per_user?: number | undefined
recipients?: User
icon?: string | undefined
owner_id?: string | undefined
application_id?: string | undefined
parent_id?: string | undefined
last_pin_timestamp?: string | undefined
get mention () {
return `<#${this.id}>`
}
constructor (client: Client, data: ChannelPayload) {
super(client, data) super(client, data)
this.id = data.id this.lastMessageId = data.last_message_id
this.type = data.type this.lastPinTimestamp = data.last_pin_timestamp
} }
send (content: string | Embed, option?: {}) {} //TODO: send function
} }

View File

@ -2,20 +2,20 @@ import { Client } from '../models/client.ts'
import { UserPayload } from '../types/userTypes.ts' import { UserPayload } from '../types/userTypes.ts'
import { Base } from './base.ts' import { Base } from './base.ts'
export class User extends Base implements UserPayload { export class User extends Base {
id: string id: string
username: string username: string
discriminator: string discriminator: string
avatar?: string avatar?: string
bot?: boolean bot?: boolean
system?: boolean system?: boolean
mfa_enabled?: boolean mfaEnabled?: boolean
locale?: string locale?: string
verified?: boolean verified?: boolean
email?: string email?: string
flags?: number flags?: number
premium_type?: 0 | 1 | 2 premiumType?: 0 | 1 | 2
public_flags?: number publicFlags?: number
get nickMention () { get nickMention () {
return `<@!${this.id}>` return `<@!${this.id}>`
@ -33,12 +33,12 @@ export class User extends Base implements UserPayload {
this.avatar = data.avatar this.avatar = data.avatar
this.bot = data.bot this.bot = data.bot
this.system = data.system this.system = data.system
this.mfa_enabled = data.mfa_enabled this.mfaEnabled = data.mfa_enabled
this.locale = data.locale this.locale = data.locale
this.verified = data.verified this.verified = data.verified
this.email = data.email this.email = data.email
this.flags = data.flags this.flags = data.flags
this.premium_type = data.premium_type this.premiumType = data.premium_type
this.public_flags = data.public_flags this.publicFlags = data.public_flags
} }
} }

View File

@ -1,33 +1,34 @@
import { Client } from "../models/client.ts" import { Client } from '../models/client.ts'
import { VoiceStatePayload } from "../types/voiceTypes.ts" import { MemberPayload } from '../types/guildTypes.ts'
import { Base } from "./base.ts" import { VoiceStatePayload } from '../types/voiceTypes.ts'
import { Member } from "./member.ts" import { Base } from './base.ts'
import { Member } from './member.ts'
export class VoiceState extends Base implements VoiceStatePayload { export class VoiceState extends Base {
guild_id?: string guildID?: string
channel_id: string | undefined channelID?: string
user_id: string userID: string
member?: Member member?: MemberPayload
session_id: string sessionID: string
deaf: boolean deaf: boolean
mute: boolean mute: boolean
self_deaf: boolean selfDeaf: boolean
self_mute: boolean selfMute: boolean
self_stream?: boolean selfStream?: boolean
self_video: boolean selfVideo: boolean
suppress: boolean suppress: boolean
constructor (client: Client, data: VoiceStatePayload) { constructor (client: Client, data: VoiceStatePayload) {
super(client) super(client)
this.channel_id = data.channel_id this.channelID = data.channel_id
this.session_id = data.session_id this.sessionID = data.session_id
this.user_id = data.user_id this.userID = data.user_id
this.deaf = data.deaf this.deaf = data.deaf
this.mute = data.mute this.mute = data.mute
this.self_deaf = data.self_deaf this.selfDeaf = data.self_deaf
this.self_mute = data.self_mute this.selfMute = data.self_mute
this.self_stream = data.self_stream this.selfStream = data.self_stream
this.self_video = data.self_video this.selfVideo = data.self_video
this.suppress = data.suppress this.suppress = data.suppress
} }
} }

View File

@ -1,23 +1,23 @@
import { Client } from "../models/client.ts" import { Client } from '../models/client.ts'
import { WebhookPayload } from "../types/webhookTypes.ts" import { UserPayload } from '../types/userTypes.ts'
import { Base } from "./base.ts" import { WebhookPayload } from '../types/webhookTypes.ts'
import { User } from "./user.ts" import { Base } from './base.ts'
export class VoiceState extends Base implements WebhookPayload { export class Webhook extends Base {
id: string id: string
type: 1 | 2 type: 1 | 2
guild_id?: string guildID?: string
channel_id: string channelID: string
user?: User user?: UserPayload
name: string | undefined name?: string
avatar: string | undefined avatar?: string
token?: string token?: string
application_id: string | undefined applicationID?: string
constructor (client: Client, data: WebhookPayload) { constructor (client: Client, data: WebhookPayload) {
super(client) super(client)
this.id = data.id this.id = data.id
this.type = data.type this.type = data.type
this.channel_id = data.channel_id this.channelID = data.channel_id
} }
} }

View File

@ -1,7 +1,15 @@
import { Client } from '../models/client.ts' import { Client } from '../models/client.ts'
import { Guild } from '../structures/guild.ts'
import { GatewayIntents } from '../types/gatewayTypes.ts' import { GatewayIntents } from '../types/gatewayTypes.ts'
import { TOKEN } from './config.ts' import { TOKEN } from './config.ts'
const bot = new Client() const bot = new Client()
bot.connect(TOKEN, [GatewayIntents.GUILD_MESSAGES]) bot.connect(TOKEN, [GatewayIntents.GUILD_MESSAGES])
Guild.autoInit(bot, '').then(a => console.log(a))
setTimeout(async () => {
const result = Guild.autoInit(bot, '')
console.log(result)
}, 30000)

View File

@ -1,29 +1,59 @@
import { Member } from '../structures/member.ts'
import { Role } from '../structures/role.ts'
import { User } from '../structures/user.ts'
import { EmojiPayload } from './emojiTypes.ts' import { EmojiPayload } from './emojiTypes.ts'
import { MemberPayload } from './guildTypes.ts'
import { RolePayload } from './roleTypes.ts'
import { UserPayload } from './userTypes.ts'
interface ChannelPayload { interface ChannelPayload {
id: string id: string
type: ChannelTypes type: ChannelTypes
guild_id?: string }
position?: number
approximate_member_count?: Overwrite interface TextChannelPayload extends ChannelPayload {
name?: string
topic?: string
nsfw?: boolean
last_message_id?: string last_message_id?: string
bitrate?: number
user_limit?: number
rate_limit_per_user?: number
recipients?: User
icon?: string
owner_id?: string
application_id?: string
parent_id?: string
last_pin_timestamp?: string last_pin_timestamp?: string
} }
interface GuildChannelPayload extends ChannelPayload {
guild_id: string
name: string
position: number
permission_overwrites: Overwrite[]
nsfw: boolean
parent_id?: string
}
interface GuildTextChannelPayload
extends TextChannelPayload,
GuildChannelPayload {
rate_limit_per_user: number
topic?: string
}
interface GuildNewsChannelPayload
extends TextChannelPayload,
GuildChannelPayload {
topic?: string
}
interface GuildVoiceChannelPayload extends GuildChannelPayload {
bitrate: string
user_limit: number
}
interface DMChannelPayload extends TextChannelPayload {
recipients: UserPayload[]
}
interface GroupDMChannelPayload extends DMChannelPayload {
name: string
icon?: string
owner_id: string
}
interface GuildChannelCategoryPayload
extends ChannelPayload,
GuildChannelPayload {}
interface Overwrite { interface Overwrite {
id: string id: string
type: number type: number
@ -45,15 +75,15 @@ interface MessagePayload {
id: string id: string
channel_id: string channel_id: string
guild_id?: string guild_id?: string
author: User author: UserPayload
member?: Member member?: MemberPayload
content: string content: string
timestamp: string timestamp: string
edited_timestamp: string | undefined edited_timestamp?: string
tts: boolean tts: boolean
mention_everyone: boolean mention_everyone: boolean
mentions: User[] mentions: UserPayload[]
mention_roles: Role[] mention_roles: RolePayload[]
mention_channels?: ChannelMention[] mention_channels?: ChannelMention[]
attachments: Attachment[] attachments: Attachment[]
embeds: EmbedPayload[] embeds: EmbedPayload[]
@ -210,12 +240,6 @@ interface FollowedChannel {
webhook_id: string webhook_id: string
} }
interface Reaction {
count: number
me: boolean
emoji: EmojiPayload
}
interface Overwrite { interface Overwrite {
id: string id: string
type: number type: number
@ -231,6 +255,15 @@ interface ChannelMention {
export { export {
ChannelPayload, ChannelPayload,
TextChannelPayload,
GuildChannelPayload,
GuildNewsChannelPayload,
GuildTextChannelPayload,
GuildVoiceChannelPayload,
GuildChannelCategoryPayload,
DMChannelPayload,
GroupDMChannelPayload,
Overwrite,
ChannelTypes, ChannelTypes,
ChannelMention, ChannelMention,
Attachment, Attachment,

View File

@ -1,10 +1,10 @@
import { User } from '../structures/user.ts' import { UserPayload } from './userTypes.ts'
export interface EmojiPayload { export interface EmojiPayload {
id: string id: string
name: string name: string
roles?: [] roles?: []
user?: User user?: UserPayload
require_colons?: boolean require_colons?: boolean
managed?: boolean managed?: boolean
animated?: boolean animated?: boolean

View File

@ -7,7 +7,7 @@ import {
} from '../consts/urlsAndVersions.ts' } from '../consts/urlsAndVersions.ts'
//Guild Endpoints //Guild Endpoints
const GUILDS = `${DISCORD_API_URL}/v${DISCORD_API_VERSION}/guilds` const GUILDS = () => `${DISCORD_API_URL}/v${DISCORD_API_VERSION}/guilds`
const GUILD = (guildID: string) => const GUILD = (guildID: string) =>
`${DISCORD_API_URL}/v${DISCORD_API_VERSION}/guilds/${guildID}` `${DISCORD_API_URL}/v${DISCORD_API_VERSION}/guilds/${guildID}`
const GUILD_AUDIT_LOGS = (guildID: string) => const GUILD_AUDIT_LOGS = (guildID: string) =>
@ -60,10 +60,10 @@ const CHANNEL = (channelID: string) =>
`${DISCORD_API_URL}/v${DISCORD_API_VERSION}/channels/${channelID}` `${DISCORD_API_URL}/v${DISCORD_API_VERSION}/channels/${channelID}`
const CHANNELS = (channelID: string) => const CHANNELS = (channelID: string) =>
`${DISCORD_API_URL}/v${DISCORD_API_VERSION}/guilds/${channelID}/channels` `${DISCORD_API_URL}/v${DISCORD_API_VERSION}/guilds/${channelID}/channels`
const CHANNEL_MESSAGES = (channelID: string) =>
`${DISCORD_API_URL}/v${DISCORD_API_VERSION}/channels/${channelID}/messages`
const CHANNEL_MESSAGE = (channelID: string, messageID: string) => const CHANNEL_MESSAGE = (channelID: string, messageID: string) =>
`${DISCORD_API_URL}/v${DISCORD_API_VERSION}/channels/${channelID}/messages/${messageID}` `${DISCORD_API_URL}/v${DISCORD_API_VERSION}/channels/${channelID}/messages/${messageID}`
const CHANNEL_MESSAGES = (channelID: string) =>
`${DISCORD_API_URL}/v${DISCORD_API_VERSION}/channels/${channelID}/messages`
const CHANNEL_CROSSPOST = (channelID: string, messageID: string) => const CHANNEL_CROSSPOST = (channelID: string, messageID: string) =>
`${DISCORD_API_URL}/v${DISCORD_API_VERSION}/channels/${channelID}/messages/${messageID}/crosspost` `${DISCORD_API_URL}/v${DISCORD_API_VERSION}/channels/${channelID}/messages/${messageID}/crosspost`
const MESSAGE_REACTIONS = (channelID: string, messageID: string) => const MESSAGE_REACTIONS = (channelID: string, messageID: string) =>
@ -105,10 +105,14 @@ const GROUP_RECIPIENT = (channelID: string, userID: string) =>
`${DISCORD_API_URL}/v${DISCORD_API_VERSION}/channels/${channelID}/recipient/${userID}` `${DISCORD_API_URL}/v${DISCORD_API_VERSION}/channels/${channelID}/recipient/${userID}`
//User Endpoints //User Endpoints
const CURRENT_USER = `${DISCORD_API_URL}/v${DISCORD_API_VERSION}/users/@me` const CURRENT_USER = () =>
const CURRENT_USER_GUILDS = `${DISCORD_API_URL}/v${DISCORD_API_VERSION}/users/@me/guilds` `${DISCORD_API_URL}/v${DISCORD_API_VERSION}/users/@me`
const USER_DM = `${DISCORD_API_URL}/v${DISCORD_API_VERSION}/users/@me/channels` const CURRENT_USER_GUILDS = () =>
const USER_CONNECTIONS = `${DISCORD_API_URL}/v${DISCORD_API_VERSION}/users/@me/connections` `${DISCORD_API_URL}/v${DISCORD_API_VERSION}/users/@me/guilds`
const USER_DM = () =>
`${DISCORD_API_URL}/v${DISCORD_API_VERSION}/users/@me/channels`
const USER_CONNECTIONS = () =>
`${DISCORD_API_URL}/v${DISCORD_API_VERSION}/users/@me/connections`
const LEAVE_GUILD = (guildID: string) => const LEAVE_GUILD = (guildID: string) =>
`${DISCORD_API_URL}/v${DISCORD_API_VERSION}/users/@me/guilds/${guildID}` `${DISCORD_API_URL}/v${DISCORD_API_VERSION}/users/@me/guilds/${guildID}`
const USER = (userID: string) => const USER = (userID: string) =>
@ -129,12 +133,12 @@ const GITHUB_WEBHOOK = (webhookID: string, webhookTOKEN: string) =>
`${DISCORD_API_URL}/v${DISCORD_API_VERSION}/webhooks/${webhookID}/${webhookTOKEN}/github` `${DISCORD_API_URL}/v${DISCORD_API_VERSION}/webhooks/${webhookID}/${webhookTOKEN}/github`
//Gateway Endpoints //Gateway Endpoints
const GATEWAY = `${DISCORD_API_URL}/v${DISCORD_API_VERSION}/gateway` const GATEWAY = () => `${DISCORD_API_URL}/v${DISCORD_API_VERSION}/gateway`
const GATEWAY_BOT = `${DISCORD_API_URL}/v${DISCORD_API_VERSION}/gateway/bot` const GATEWAY_BOT = () =>
`${DISCORD_API_URL}/v${DISCORD_API_VERSION}/gateway/bot`
//CDN Endpoints //CDN Endpoints
const CUSTOM_EMOJI = (emojiID: string) => const CUSTOM_EMOJI = (emojiID: string) => `${DISCORD_CDN_URL}/emojis/${emojiID}`
`${DISCORD_CDN_URL}/emojis/${emojiID}`
const GUILD_ICON = (guildID: string, iconID: number) => const GUILD_ICON = (guildID: string, iconID: number) =>
`${DISCORD_CDN_URL}/icons/${guildID}/${iconID}` `${DISCORD_CDN_URL}/icons/${guildID}/${iconID}`
const GUILD_SPLASH = (guildID: string, guildSPLASH: string) => const GUILD_SPLASH = (guildID: string, guildSPLASH: string) =>
@ -142,8 +146,7 @@ const GUILD_SPLASH = (guildID: string, guildSPLASH: string) =>
const GUILD_DISCOVERY_SPLASH = ( const GUILD_DISCOVERY_SPLASH = (
guildID: string, guildID: string,
guildDiscoverySplash: string guildDiscoverySplash: string
) => ) => `${DISCORD_CDN_URL}/discovery-splashes/${guildID}/${guildDiscoverySplash}`
`${DISCORD_CDN_URL}/discovery-splashes/${guildID}/${guildDiscoverySplash}`
const GUILD_BANNER = (guildID: string, guildBANNER: string) => const GUILD_BANNER = (guildID: string, guildBANNER: string) =>
`${DISCORD_CDN_URL}/banners/${guildID}/${guildBANNER}` `${DISCORD_CDN_URL}/banners/${guildID}/${guildBANNER}`
const DEFAULT_USER_AVATAR = (iconID: string) => const DEFAULT_USER_AVATAR = (iconID: string) =>
@ -178,3 +181,75 @@ const INVITE = (inviteCODE: string) =>
//Voice Endpoint //Voice Endpoint
const VOICE_REGIONS = (guildID: string) => const VOICE_REGIONS = (guildID: string) =>
`${DISCORD_API_URL}/v${DISCORD_API_VERSION}/guilds/${guildID}/regions` `${DISCORD_API_URL}/v${DISCORD_API_VERSION}/guilds/${guildID}/regions`
export {
GUILDS,
GUILD,
GUILD_AUDIT_LOGS,
GUILD_WIDGET,
GUILD_EMOJI,
GUILD_ROLE,
GUILD_ROLES,
GUILD_INTEGRATION,
GUILD_INTEGRATIONS,
GUILD_INTEGARTION_SYNC,
GUILD_BAN,
GUILD_BANS,
GUILD_CHANNEL,
GUILD_CHANNELS,
GUILD_MEMBER,
GUILD_MEMBERS,
GUILD_MEMBER_ROLE,
GUILD_INVITES,
GUILD_LEAVE,
GUILD_PRUNE,
GUILD_VANITY_URL,
GUILD_NICK,
GUILD_PREVIEW,
CHANNEL,
CHANNELS,
CHANNEL_MESSAGE,
CHANNEL_MESSAGES,
CHANNEL_CROSSPOST,
MESSAGE_REACTIONS,
MESSAGE_REACTION,
MESSAGE_REACTION_ME,
MESSAGE_REACTION_USER,
CHANNEL_BULK_DELETE,
CHANNEL_FOLLOW,
CHANNEL_INVITES,
CHANNEL_PIN,
CHANNEL_PINS,
CHANNEL_PERMISSION,
CHANNEL_TYPING,
GROUP_RECIPIENT,
CURRENT_USER,
CURRENT_USER_GUILDS,
USER_DM,
USER_CONNECTIONS,
LEAVE_GUILD,
USER,
CHANNEL_WEBHOOKS,
GUILD_WEBHOOK,
WEBHOOK,
WEBHOOK_WITH_TOKEN,
SLACK_WEBHOOK,
GITHUB_WEBHOOK,
GATEWAY,
GATEWAY_BOT,
CUSTOM_EMOJI,
GUILD_ICON,
GUILD_SPLASH,
GUILD_DISCOVERY_SPLASH,
GUILD_BANNER,
DEFAULT_USER_AVATAR,
USER_AVATAR,
APPLICATION_ASSET,
ACHIEVEMENT_ICON,
TEAM_ICON,
EMOJI,
EMOJIS,
TEMPLATE,
INVITE,
VOICE_REGIONS
}

View File

@ -1,11 +1,10 @@
// https://discord.com/developers/docs/topics/opcodes-and-status-codes#gateway // https://discord.com/developers/docs/topics/opcodes-and-status-codes#gateway
// https://discord.com/developers/docs/topics/gateway#commands-and-events-gateway-events // https://discord.com/developers/docs/topics/gateway#commands-and-events-gateway-events
import { Emoji } from '../structures/emoji.ts' import { EmojiPayload } from './emojiTypes.ts'
import { Member } from '../structures/member.ts'
import { Role } from '../structures/role.ts'
import { User } from '../structures/user.ts'
import { MemberPayload } from './guildTypes.ts' import { MemberPayload } from './guildTypes.ts'
import { ActivityPayload, PresenceUpdatePayload } from './presenceTypes.ts' import { ActivityPayload, PresenceUpdatePayload } from './presenceTypes.ts'
import { RolePayload } from './roleTypes.ts'
import { UserPayload } from './userTypes.ts'
/** /**
* Gateway OPcodes from Discord docs. * Gateway OPcodes from Discord docs.
@ -124,7 +123,7 @@ enum UpdateStatus {
} }
interface IdentityConnection { interface IdentityConnection {
$os: 'linux' $os: 'darwin' | 'windows' | 'linux' | 'custom os'
$browser: 'discord.deno' $browser: 'discord.deno'
$device: 'discord.deno' $device: 'discord.deno'
} }
@ -139,7 +138,7 @@ interface GuildRequestMembers {
guild_id: string | string[] guild_id: string | string[]
query?: string query?: string
limit: number limit: number
presences?: boolean //do you have any problems? tell me! i am so handsome presences?: boolean
user_ids?: string | string[] user_ids?: string | string[]
nonce?: string nonce?: string
} }
@ -164,7 +163,7 @@ interface Hello {
interface ReadyEvent { interface ReadyEvent {
v: number v: number
user: User user: UserPayload
privateChannels: [] privateChannels: []
guilds: [] guilds: []
session_id: string session_id: string
@ -179,12 +178,12 @@ interface ChannelPinsUpdate {
interface GuildBanAdd { interface GuildBanAdd {
guild_id: string guild_id: string
user: User user: UserPayload
} }
interface GuildBanRemove { interface GuildBanRemove {
guild_id: string guild_id: string
user: User user: UserPayload
} }
interface GuildEmojiUpdate { interface GuildEmojiUpdate {
@ -202,12 +201,12 @@ interface GuildMemberAddExtra {
interface GuildMemberRemove { interface GuildMemberRemove {
guild_id: string guild_id: string
user: User user: UserPayload
} }
interface GuildMemberUpdate { interface GuildMemberUpdate {
guild_id: string guild_id: string
roles: string[] roles: string[]
user: User user: UserPayload
nick?: string | undefined nick?: string | undefined
joined_at: string joined_at: string
premium_since?: string | undefined premium_since?: string | undefined
@ -225,12 +224,12 @@ interface GuildMemberChunk {
interface GuildRoleCreate { interface GuildRoleCreate {
guild_id: string guild_id: string
role: Role role: RolePayload
} }
interface GuildRoleUpdate { interface GuildRoleUpdate {
guild_id: string guild_id: string
role: Role role: RolePayload
} }
interface GuildRoleDelete { interface GuildRoleDelete {
@ -243,10 +242,10 @@ interface InviteCreate {
code: string code: string
created_at: string created_at: string
guild_id?: string guild_id?: string
inviter?: User inviter?: UserPayload
max_age: number max_age: number
max_uses: number max_uses: number
target_user?: User target_user?: UserPayload
target_user_type?: number target_user_type?: number
temporary: boolean temporary: boolean
uses: number uses: number
@ -275,7 +274,7 @@ interface MessageReactionAdd {
channel_id: string channel_id: string
message_id: string message_id: string
guild_id?: string guild_id?: string
emoji: Emoji emoji: EmojiPayload
} }
interface MessageReactionRemove { interface MessageReactionRemove {
@ -283,25 +282,25 @@ interface MessageReactionRemove {
channel_id: string channel_id: string
message_id: string message_id: string
guild_id?: string guild_id?: string
emoji: Emoji emoji: EmojiPayload
} }
interface MessageReactionRemoveAll { interface MessageReactionRemoveAll {
channel_id: string channel_id: string
guild_id?: string guild_id?: string
message_id: string message_id: string
emoji: Emoji emoji: EmojiPayload
} }
interface MessageReactionRemove { interface MessageReactionRemove {
channel_id: string channel_id: string
guild_id?: string guild_id?: string
message_id: string message_id: string
emoji: Emoji emoji: EmojiPayload
} }
interface PresenceUpdate { interface PresenceUpdate {
user: User user: UserPayload
guild_id: string guild_id: string
status: string status: string
activities: ActivityPayload[] activities: ActivityPayload[]
@ -323,7 +322,7 @@ interface Activity {
application_id: string application_id: string
details?: string | undefined details?: string | undefined
state?: string | undefined state?: string | undefined
emoji?: Emoji | undefined emoji?: EmojiPayload | undefined
party?: ActivityParty party?: ActivityParty
assets?: ActivityAssets assets?: ActivityAssets
secrets?: ActivitySecrets secrets?: ActivitySecrets
@ -382,7 +381,7 @@ interface TypeStart {
guild_id?: string guild_id?: string
user_id: string user_id: string
timestamp: number timestamp: number
member?: Member member?: MemberPayload
} }
interface VoiceServerUpdate { interface VoiceServerUpdate {

View File

@ -1,65 +1,64 @@
import { Channel } from '../structures/channel.ts' import { ChannelPayload } from './channelTypes.ts'
import { Emoji } from '../structures/emoji.ts' import { EmojiPayload } from './emojiTypes.ts'
import { Member } from '../structures/member.ts'
import { Role } from '../structures/role.ts'
import { User } from '../structures/user.ts'
import { PresenceUpdatePayload } from './presenceTypes.ts' import { PresenceUpdatePayload } from './presenceTypes.ts'
import { RolePayload } from './roleTypes.ts'
import { UserPayload } from './userTypes.ts'
import { VoiceStatePayload } from './voiceTypes.ts' import { VoiceStatePayload } from './voiceTypes.ts'
interface GuildPayload { interface GuildPayload {
id: string id: string
name: string name: string
icon: string | undefined icon?: string
icon_hash?: string | undefined icon_hash?: string
splash: string | undefined splash?: string
discovery_splash: string | undefined discovery_splash?: string
owner?: boolean owner?: boolean
owner_id: string owner_id: string
permissions?: string permissions?: string
region: string region: string
afk_channel_id: string | undefined afk_channel_id?: string
afk_timeout: number afk_timeout: number
widget_enabled?: boolean widget_enabled?: boolean
widge_channel_id?: string | undefined widge_channel_id?: string
verification_level: string verification_level: string
default_message_notifications: string default_message_notifications: string
explicit_content_filter: string explicit_content_filter: string
roles: Role[] roles: RolePayload[]
emojis: Emoji[] emojis: EmojiPayload[]
features: GuildFeatures[] features: GuildFeatures[]
mfa_level: string mfa_level: string
application_id: string | undefined application_id?: string
system_channel_id: string | undefined system_channel_id?: string
system_channel_flags: string system_channel_flags: string
rules_channel_id: string | undefined rules_channel_id?: string
joined_at?: string joined_at?: string
large?: boolean large?: boolean
unavailable: boolean unavailable: boolean
member_count?: number member_count?: number
voice_states?: VoiceStatePayload[] voice_states?: VoiceStatePayload[]
members?: Member[] members?: MemberPayload[]
channels?: Channel[] channels?: ChannelPayload[]
presences?: PresenceUpdatePayload[] presences?: PresenceUpdatePayload[]
max_presences?: number | undefined max_presences?: number
max_members?: number max_members?: number
vanity_url_code: string | undefined vanity_url_code?: string
description: string | undefined description?: string
banner: string | undefined banner?: string
premium_tier: number premium_tier: number
premium_subscription_count?: number premium_subscription_count?: number
preferred_locale: string preferred_locale: string
public_updates_channel_id: string | undefined public_updates_channel_id?: string
max_video_channel_users?: number max_video_channel_users?: number
approximate_number_count?: number approximate_number_count?: number
approximate_presence_count?: number approximate_presence_count?: number
} }
interface MemberPayload { interface MemberPayload {
user: User user: UserPayload
nick: string | undefined nick?: string
roles: Role[] roles: RolePayload[]
joined_at: string joined_at: string
premium_since?: string | undefined premium_since?: string
deaf: boolean deaf: boolean
mute: boolean mute: boolean
} }

View File

@ -1,13 +1,13 @@
import { Channel } from '../structures/channel.ts' import { ChannelPayload } from './channelTypes.ts'
import { Guild } from '../structures/guild.ts' import { GuildPayload } from './guildTypes.ts'
import { User } from '../structures/user.ts' import { UserPayload } from './userTypes.ts'
export interface InvitePayload { export interface InvitePayload {
code: string code: string
guild?: Guild guild?: GuildPayload
channel: Channel channel: ChannelPayload
inviter?: User inviter?: UserPayload
target_user?: User target_user?: UserPayload
target_user_type?: number target_user_type?: number
approximate_presence_count?: number approximate_presence_count?: number
approximate_member_count?: number approximate_member_count?: number

View File

@ -1,7 +1,7 @@
import { User } from '../structures/user.ts' import { UserPayload } from './userTypes.ts'
interface PresenceUpdatePayload { interface PresenceUpdatePayload {
user: User user: UserPayload
guild_id: string guild_id: string
status: string status: string
activities: ActivityPayload activities: ActivityPayload

View File

@ -15,8 +15,3 @@ export class Snowflake {
return res return res
} }
} }
// BigInt라서 이걸 어케 할까 고심끝에 나온게 toString 읍
// 엄...
// deconstruct가 소멸자임? 색 봐서는 아닌거같은데

View File

@ -1,5 +1,5 @@
import { Guild } from '../structures/guild.ts' import { GuildPayload } from './guildTypes.ts'
import { User } from '../structures/user.ts' import { UserPayload } from './userTypes.ts'
export interface TemplatePayload { export interface TemplatePayload {
code: string code: string
@ -7,10 +7,10 @@ export interface TemplatePayload {
description: string | undefined description: string | undefined
usage_count: number usage_count: number
creator_id: string creator_id: string
creator: User creator: UserPayload
created_at: string created_at: string
updated_at: string updated_at: string
source_guild_id: string source_guild_id: string
serialized_source_guild: Guild serialized_source_guild: GuildPayload
is_dirty: boolean | undefined is_dirty: boolean | undefined
} }

View File

@ -1,5 +1,5 @@
// https://discord.com/developers/docs/topics/opcodes-and-status-codes#voice // https://discord.com/developers/docs/topics/opcodes-and-status-codes#voice
import { Member } from '../structures/member.ts' import { MemberPayload } from './guildTypes.ts'
enum VoiceOpcodes { // VoiceOpcodes 추가 - UnderC - enum VoiceOpcodes { // VoiceOpcodes 추가 - UnderC -
IDENTIFY = 0, IDENTIFY = 0,
@ -31,9 +31,9 @@ enum VoiceCloseCodes {
export interface VoiceStatePayload { export interface VoiceStatePayload {
guild_id?: string guild_id?: string
channel_id: string | undefined channel_id?: string
user_id: string user_id: string
member?: Member member?: MemberPayload
session_id: string session_id: string
deaf: boolean deaf: boolean
mute: boolean mute: boolean

View File

@ -1,13 +1,13 @@
import { User } from '../structures/user.ts' import { UserPayload } from './userTypes.ts'
export interface WebhookPayload { export interface WebhookPayload {
id: string id: string
type: 1 | 2 type: 1 | 2
guild_id?: string guild_id?: string
channel_id: string channel_id: string
user?: User user?: UserPayload
name: string | undefined name?: string
avatar: string | undefined avatar?: string
token?: string token?: string
application_id: string | undefined application_id?: string
} }

View File

@ -8,8 +8,8 @@
"module": "ESNext", "module": "ESNext",
/* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
"lib": [ "lib": [
"esnext", "esnext"
], /* Specify library files to be included in the compilation. */ ] /* Specify library files to be included in the compilation. */,
// "allowJs": true, /* Allow javascript files to be compiled. */ // "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */ // "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
@ -67,4 +67,4 @@
/* Skip type checking of declaration files. */ /* Skip type checking of declaration files. */
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
} }
} }