Co-Authored-By: khk4912 <30457148+khk4912@users.noreply.github.com>
This commit is contained in:
Catry 2020-10-23 12:16:29 +09:00
parent e85f86df6d
commit 8d4859c6d4
14 changed files with 126 additions and 13 deletions

View file

@ -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
}
}

View file

@ -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

View file

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

View file

@ -1,4 +1,3 @@
// 일단 대충 여러 봇 라이브러리에서 본 구조 가져오는 중..
import { Client } from '../models/client.ts'
export class Base {

11
src/structures/cdn.ts Normal file
View file

@ -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
}

View file

@ -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 `<a:${this.name}:${this.id}>`
}
constructor (client: Client, data: EmojiPayload) {
super(client)
this.id = data.id

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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
}
}

23
src/structures/webhook.ts Normal file
View file

@ -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
}
}

2
src/types/cdnTypes.ts Normal file
View file

@ -0,0 +1,2 @@
export type ImageSize = 16 | 32 | 64 | 128 | 256 | 512 | 1024 | 2048
export type ImageFormats = "jpg" | "jpeg" | "png" | "webp" | "gif"

View file

@ -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) =>