diff --git a/.vscode/settings.json b/.vscode/settings.json index 0dd8765..7848ab6 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,5 +2,8 @@ "deno.enable": true, "deno.lint": false, "deno.unstable": false, - "deepscan.enable": true + "deepscan.enable": true, + "deno.import_intellisense_origins": { + "https://deno.land": true + } } \ No newline at end of file diff --git a/src/models/client.ts b/src/models/client.ts index a200c95..c77a9f4 100644 --- a/src/models/client.ts +++ b/src/models/client.ts @@ -1,12 +1,14 @@ import { User } from '../structures/user.ts' import { GatewayIntents } from '../types/gatewayTypes.ts' import { Gateway } from './gateway.ts' +import { Rest } from "./rest.ts" /** * Discord Client. */ export class Client { gateway?: Gateway + rest?: Rest user?: User ping = 0 diff --git a/src/models/gateway.ts b/src/models/gateway.ts index 4885bf4..09fbffe 100644 --- a/src/models/gateway.ts +++ b/src/models/gateway.ts @@ -180,6 +180,10 @@ class Gateway { this.websocket.onclose = this.onclose.bind(this) this.websocket.onerror = this.onerror.bind(this) } + + close () { + this.websocket.close(1000) + } } export { Gateway } diff --git a/src/models/rest.ts b/src/models/rest.ts index 0632b43..5226e90 100644 --- a/src/models/rest.ts +++ b/src/models/rest.ts @@ -1 +1,12 @@ -// rest api \ No newline at end of file +import { Client } from "./client.ts"; + +class Rest { + client: Client + constructor(client: Client) { + this.client = client + } + + //TODO: make endpoints function +} + +export { Rest } \ No newline at end of file diff --git a/src/structures/base.ts b/src/structures/base.ts index 9bd008b..6f99de4 100644 --- a/src/structures/base.ts +++ b/src/structures/base.ts @@ -1,4 +1,3 @@ -// 일단 대충 여러 봇 라이브러리에서 본 구조 가져오는 중.. import { Client } from '../models/client.ts' export class Base { diff --git a/src/structures/cdn.ts b/src/structures/cdn.ts new file mode 100644 index 0000000..a56520c --- /dev/null +++ b/src/structures/cdn.ts @@ -0,0 +1,11 @@ +import { ImageFormats, ImageSize } from "../types/cdnTypes.ts"; + +export const ImageURL = ( + url: string, + format: ImageFormats, + size?: ImageSize | 128 +) => { + if (url.includes('a_')) { + return url + '.gif' + '?size=' + size + } else return url + '.' + format + '?size=' + size +} \ No newline at end of file diff --git a/src/structures/emoji.ts b/src/structures/emoji.ts index 23b2883..a419515 100644 --- a/src/structures/emoji.ts +++ b/src/structures/emoji.ts @@ -12,6 +12,13 @@ export class Emoji extends Base implements EmojiPayload { managed?: boolean animated?: boolean available?: boolean + + get CustomEmoji () { + if (this.animated === false) { + return `<:${this.name}:${this.id}>` + } else return `` + } + constructor (client: Client, data: EmojiPayload) { super(client) this.id = data.id diff --git a/src/structures/invite.ts b/src/structures/invite.ts index 50743f5..723c2f5 100644 --- a/src/structures/invite.ts +++ b/src/structures/invite.ts @@ -15,6 +15,11 @@ export class Invite extends Base implements InvitePayload { approximate_presence_count?: number approximate_member_count?: number + + get link () { + return `discord.gg/${this.code}` + } + constructor (client: Client, data: InvitePayload) { super(client) this.code = data.code diff --git a/src/structures/role.ts b/src/structures/role.ts index 2148bbf..a286f3d 100644 --- a/src/structures/role.ts +++ b/src/structures/role.ts @@ -12,6 +12,10 @@ export class Role extends Base implements RolePayload { managed: boolean mentionable: boolean + get mention () { + return `<@&${this.id}>` + } + constructor (client: Client, data: RolePayload) { super(client) this.id = data.id diff --git a/src/structures/textChannel.ts b/src/structures/textChannel.ts index 83c9392..ce8af41 100644 --- a/src/structures/textChannel.ts +++ b/src/structures/textChannel.ts @@ -23,6 +23,11 @@ export class TextChannel extends GuildChannel implements ChannelPayload { parent_id?: string | undefined last_pin_timestamp?: string | undefined + + get mention () { + return `<#${this.id}>` + } + constructor (client: Client, data: ChannelPayload) { super(client, data) this.id = data.id diff --git a/src/structures/user.ts b/src/structures/user.ts index ea7f64e..afb64ff 100644 --- a/src/structures/user.ts +++ b/src/structures/user.ts @@ -17,6 +17,14 @@ export class User extends Base implements UserPayload { premium_type?: 0 | 1 | 2 public_flags?: number + get nickMention () { + return `<@!${this.id}>` + } + + get mention () { + return `<@${this.id}>` + } + constructor (client: Client, data: UserPayload) { super(client) this.id = data.id diff --git a/src/structures/voicestate.ts b/src/structures/voicestate.ts new file mode 100644 index 0000000..369e438 --- /dev/null +++ b/src/structures/voicestate.ts @@ -0,0 +1,33 @@ +import { Client } from "../models/client.ts" +import { VoiceStatePayload } from "../types/voiceTypes.ts" +import { Base } from "./base.ts" +import { Member } from "./member.ts" + +export class VoiceState extends Base implements VoiceStatePayload { + guild_id?: string + channel_id: string | undefined + user_id: string + member?: Member + session_id: string + deaf: boolean + mute: boolean + self_deaf: boolean + self_mute: boolean + self_stream?: boolean + self_video: boolean + suppress: boolean + + constructor (client: Client, data: VoiceStatePayload) { + super(client) + this.channel_id = data.channel_id + this.session_id = data.session_id + this.user_id = data.user_id + this.deaf = data.deaf + this.mute = data.mute + this.self_deaf = data.self_deaf + this.self_mute = data.self_mute + this.self_stream = data.self_stream + this.self_video = data.self_video + this.suppress = data.suppress + } +} \ No newline at end of file diff --git a/src/structures/webhook.ts b/src/structures/webhook.ts new file mode 100644 index 0000000..aa9ab2c --- /dev/null +++ b/src/structures/webhook.ts @@ -0,0 +1,23 @@ +import { Client } from "../models/client.ts" +import { WebhookPayload } from "../types/webhookTypes.ts" +import { Base } from "./base.ts" +import { User } from "./user.ts" + +export class VoiceState extends Base implements WebhookPayload { + id: string + type: 1 | 2 + guild_id?: string + channel_id: string + user?: User + name: string | undefined + avatar: string | undefined + token?: string + application_id: string | undefined + + constructor (client: Client, data: WebhookPayload) { + super(client) + this.id = data.id + this.type = data.type + this.channel_id = data.channel_id + } +} \ No newline at end of file diff --git a/src/test/config.ts.sample b/src/test/config.ts.sample index 3f6b2f9..44a8029 100644 --- a/src/test/config.ts.sample +++ b/src/test/config.ts.sample @@ -1 +1,2 @@ const TOKEN = '' +export { TOKEN } diff --git a/src/types/cdnTypes.ts b/src/types/cdnTypes.ts new file mode 100644 index 0000000..56e2be2 --- /dev/null +++ b/src/types/cdnTypes.ts @@ -0,0 +1,2 @@ +export type ImageSize = 16 | 32 | 64 | 128 | 256 | 512 | 1024 | 2048 +export type ImageFormats = "jpg" | "jpeg" | "png" | "webp" | "gif" \ No newline at end of file diff --git a/src/types/endpoint.ts b/src/types/endpoint.ts index 503519b..c7c68b6 100644 --- a/src/types/endpoint.ts +++ b/src/types/endpoint.ts @@ -134,32 +134,32 @@ const GATEWAY_BOT = `${DISCORD_API_URL}/v${DISCORD_API_VERSION}/gateway/bot` //CDN Endpoints const CUSTOM_EMOJI = (emojiID: string) => - `${DISCORD_CDN_URL}/emojis/${emojiID}.png` + `${DISCORD_CDN_URL}/emojis/${emojiID}` const GUILD_ICON = (guildID: string, iconID: number) => - `${DISCORD_CDN_URL}/icons/${guildID}/${iconID}.png` + `${DISCORD_CDN_URL}/icons/${guildID}/${iconID}` const GUILD_SPLASH = (guildID: string, guildSPLASH: string) => - `${DISCORD_CDN_URL}/splashes/${guildID}/${guildSPLASH}.png` + `${DISCORD_CDN_URL}/splashes/${guildID}/${guildSPLASH}` const GUILD_DISCOVERY_SPLASH = ( guildID: string, guildDiscoverySplash: string ) => - `${DISCORD_CDN_URL}/discovery-splashes/${guildID}/${guildDiscoverySplash}.png ` + `${DISCORD_CDN_URL}/discovery-splashes/${guildID}/${guildDiscoverySplash}` const GUILD_BANNER = (guildID: string, guildBANNER: string) => - `${DISCORD_CDN_URL}/banners/${guildID}/${guildBANNER}.png` + `${DISCORD_CDN_URL}/banners/${guildID}/${guildBANNER}` const DEFAULT_USER_AVATAR = (iconID: string) => - `${DISCORD_CDN_URL}/embed/avatars/${iconID}.png` + `${DISCORD_CDN_URL}/embed/avatars/${iconID}` const USER_AVATAR = (userID: string, iconID: string) => - `${DISCORD_CDN_URL}/avatars/${userID}/${iconID}.png` + `${DISCORD_CDN_URL}/avatars/${userID}/${iconID}` const APPLICATION_ASSET = (applicationID: string, assetID: number) => - `${DISCORD_CDN_URL}/app-icons/${applicationID}/${assetID}.png` + `${DISCORD_CDN_URL}/app-icons/${applicationID}/${assetID}` const ACHIEVEMENT_ICON = ( applicationID: string, achievementID: string, iconHASH: string ) => - `${DISCORD_CDN_URL}/app-assets/${applicationID}/achievements/${achievementID}/icons/${iconHASH}.png` + `${DISCORD_CDN_URL}/app-assets/${applicationID}/achievements/${achievementID}/icons/${iconHASH}` const TEAM_ICON = (teamID: string, iconID: string) => - `${DISCORD_CDN_URL}/team-icons/${teamID}/${iconID}.png` + `${DISCORD_CDN_URL}/team-icons/${teamID}/${iconID}` //Emoji Endpoints const EMOJI = (guildID: string, emojiID: string) => diff --git a/src/types/gatewayTypes.ts b/src/types/gatewayTypes.ts index 11a232c..59782d5 100644 --- a/src/types/gatewayTypes.ts +++ b/src/types/gatewayTypes.ts @@ -1,6 +1,7 @@ // https://discord.com/developers/docs/topics/opcodes-and-status-codes#gateway // https://discord.com/developers/docs/topics/gateway#commands-and-events-gateway-events import { Emoji } from '../structures/emoji.ts' +import { Member } from '../structures/member.ts' import { Role } from '../structures/role.ts' import { User } from '../structures/user.ts' import { MemberPayload } from './guildTypes.ts' @@ -360,6 +361,7 @@ interface ActivityAssets { small_image?: string small_text?: string } + interface ActivitySecrets { join?: string spectate?: string @@ -375,5 +377,24 @@ enum ActivityFlags { PLAY = 1 << 5 } +interface TypeStart { + channel_id: string + guild_id?: string + user_id: string + timestamp: number + member?: Member +} + +interface VoiceServerUpdate { + token: string + guild_id: string + endpoint: string +} + +interface WebhooksUpdate { + guild_id: string + channel_id: string +} + //https://discord.com/developers/docs/topics/gateway#typing-start-typing-start-event-fields export { GatewayCloseCodes, GatewayOpcodes, GatewayIntents, GatewayEvents }