mirror of
https://github.com/discordeno/discordeno.git
synced 2026-05-30 23:40:07 +00:00
Merge remote-tracking branch 'origin/master' into origin/new-api-draft
This commit is contained in:
13
.vscode/setting.json
vendored
13
.vscode/setting.json
vendored
@@ -1,20 +1,9 @@
|
||||
{
|
||||
"deno.enable": true,
|
||||
"editor.formatOnSave": true,
|
||||
"[typescript]": {
|
||||
"editor.defaultFormatter": "axetroy.vscode-deno"
|
||||
},
|
||||
"[typescriptreact]": {
|
||||
"editor.defaultFormatter": "axetroy.vscode-deno"
|
||||
},
|
||||
"[javascript]": {
|
||||
"editor.defaultFormatter": "axetroy.vscode-deno"
|
||||
},
|
||||
"[javascriptreact]": {
|
||||
"editor.defaultFormatter": "axetroy.vscode-deno"
|
||||
},
|
||||
"[markdown]": {
|
||||
"editor.defaultFormatter": "axetroy.vscode-deno"
|
||||
},
|
||||
"[json]": {
|
||||
"editor.defaultFormatter": "axetroy.vscode-deno"
|
||||
}
|
||||
|
||||
43
CONTRIBUTING.md
Normal file
43
CONTRIBUTING.md
Normal file
@@ -0,0 +1,43 @@
|
||||
# Fundamental Design Goals
|
||||
|
||||
This document serves to outline the overall design goals of the project. Please see below a list of these fundamentals.
|
||||
|
||||
## Do not allow anything Discord does not permit
|
||||
Prevent any and all attempts of making user bots. If someone connects and the client.user is not a bot user then throw an error immediately.
|
||||
|
||||
Do not support non-bot features like Group DMs or dm calls etc...
|
||||
|
||||
## Prettier Philosophy Regarding Options
|
||||
|
||||
Avoid options/customizable whenever possible. Always enforce default values. Except in cases like intents where the user should be able to pick which intents to listen for.
|
||||
|
||||
## Security
|
||||
|
||||
Permission checks should be done by the library! We can throw a custom error that shows which permissions are missing in order to run this request and save an API call. This will also prevent bots from getting banned due to Missing Access errors.
|
||||
|
||||
Typescript 3.8 provides **TRUE** private props and methods that no one can access. We will use this to our advantage to truly make a proper API. This isn't a silly `_` to mark it as a private but the user should NEVER be able to access it no matter what.
|
||||
|
||||
## Functional API
|
||||
|
||||
Events emitted by the client, for example the message creation event, should not emit a `Message` class instance, but instead a *POJO* (Plain Ol' JavaScript Object). This will overall make a cleaner and more performant API, while removing the headaches of extending built-in classes, and inheritance.
|
||||
|
||||
Use functions when possible instead of an event emitter to prevent emitter related memory leak issues or a number of other headaches that arise.
|
||||
|
||||
TLDR: Avoid `classes` whenever possible. Avoid `loops` whenever possible(opt for iterations like .forEach, map reduce, some find etc...)
|
||||
|
||||
## Documentation
|
||||
|
||||
Use `/** Description here */` comments above all properties and methods to describe it so that VSC and other good IDE's with intellisense can pick it up and provide the documentation right inside the IDE preventing a developer from needing Discord API docs or even Deno documentation.
|
||||
|
||||
We should have a step by step guide nonetheless but this is a POST v1 launch.
|
||||
We should have a template repo to creating a boilerplate bot.
|
||||
|
||||
## Backwards Compatibility BS
|
||||
|
||||
Backwards compatibility is the death of code. It causes clutter and uglyness to pile up and makes developers lazier. There will be no such thing as backwards compatibility reasons in Discordeno. We will always support the latest and greatest of JS. The end! Users can fork the lib at any commit to keep older versions until they are ready to update.
|
||||
|
||||
That said, we don't expect many things to be changing drastically after v1. As you can imagine Typescript allows the latest and greatest of JS so we will be ahead of the curve for years to come.
|
||||
|
||||
## Style Guide
|
||||
|
||||
Prettier is our style guide. No discussions around styling ever. The options are set and that is all. When you code let prettier handle the styling. PERIOD!
|
||||
@@ -6,7 +6,14 @@ export const baseEndpoints = {
|
||||
|
||||
export const endpoints = {
|
||||
GATEWAY_BOT: `${baseEndpoints.BASE_URL}/gateway/bot`,
|
||||
GUILD_AUDIT_LOGS: (id: string) => `${baseEndpoints.BASE_URL}/guilds/${id}/audit-logs`,
|
||||
GUILD_BANNER: (id: string, icon: string) => `${baseEndpoints.CDN_URL}/banners/${id}/${icon}`,
|
||||
GUILD_CHANNELS: (id: string) => `${baseEndpoints.BASE_URL}/guilds/${id}/channels`,
|
||||
GUILD_EMOJI: (id: string, emojiID: string) => `${baseEndpoints.BASE_URL}/guilds/${id}/emojis/${emojiID}`,
|
||||
GUILD_EMOJIS: (id: string) => `${baseEndpoints.BASE_URL}/guilds/${id}/emojis`,
|
||||
GUILD_ICON: (id: string, icon: string) => `${baseEndpoints.CDN_URL}/icons/${id}/${icon}`,
|
||||
GUILD_PRUNE: (id: string) => `${baseEndpoints.BASE_URL}/guilds/${id}/prune`,
|
||||
GUILD_ROLE: (id: string, roleID: string) => `${baseEndpoints.BASE_URL}/guilds/${id}/roles/${roleID}`,
|
||||
GUILD_ROLES: (id: string) => `${baseEndpoints.BASE_URL}/guilds/${id}/roles`,
|
||||
GUILD_SPLASH: (id: string, icon: string) => `${baseEndpoints.CDN_URL}/splashes/${id}/${icon}`
|
||||
}
|
||||
|
||||
@@ -7,10 +7,10 @@ class RequestManager {
|
||||
client: Client;
|
||||
token: string;
|
||||
|
||||
constructor(client: Client, token: string) {
|
||||
this.client = client
|
||||
this.token = token
|
||||
}
|
||||
constructor(client: Client, token: string) {
|
||||
this.client = client
|
||||
this.token = token
|
||||
}
|
||||
|
||||
async get(url: string) {
|
||||
const headers = this.getDiscordHeaders();
|
||||
@@ -44,4 +44,4 @@ class RequestManager {
|
||||
}
|
||||
}
|
||||
|
||||
export default RequestManager
|
||||
export default RequestManager
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
class ShardingManager extends Map {
|
||||
}
|
||||
class ShardingManager extends Map {}
|
||||
|
||||
export default ShardingManager
|
||||
|
||||
@@ -9,10 +9,6 @@ import {
|
||||
isWebSocketPongEvent,
|
||||
WebSocket
|
||||
} from 'https://deno.land/std/ws/mod.ts'
|
||||
// import { encode } from "https://deno.land/std/strings/mod.ts"
|
||||
// import { BufReader } from "https://deno.land/std/io/bufio.ts"
|
||||
// import { TextProtoReader } from "https://deno.land/std/textproto/mod.ts"
|
||||
import { blue, green, red, yellow } from 'https://deno.land/std/fmt/colors.ts';
|
||||
import Gateway from './gateway.ts'
|
||||
import { ClientOptions, FulfilledClientOptions } from '../types/options.ts'
|
||||
import { CollectedMessageType } from '../types/message-type.ts'
|
||||
|
||||
3
structures/channel.ts
Normal file
3
structures/channel.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export const createChannel = (data: unknown) => {
|
||||
console.log(data)
|
||||
}
|
||||
@@ -2,4 +2,8 @@ export interface EmojiPayload {
|
||||
name: string;
|
||||
id?: string;
|
||||
animated?: boolean;
|
||||
}
|
||||
}
|
||||
|
||||
export const createEmoji = (data: unknown) => {
|
||||
console.log(data)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
import Client from "../module/Client"
|
||||
import { endpoints } from "../constants/discord"
|
||||
import { formatImageURL } from "../utils/cdn"
|
||||
import Client from '../module/Client'
|
||||
import { endpoints } from '../constants/discord'
|
||||
import { formatImageURL } from '../utils/cdn'
|
||||
import { createRole } from './role'
|
||||
import { createEmoji } from './emoji'
|
||||
import { createVoiceState } from './voiceState'
|
||||
import { createMember } from './member'
|
||||
import { createChannel } from './channel'
|
||||
import { createPresence } from './presence'
|
||||
|
||||
export interface CreateGuildPayload {
|
||||
/** The guild id */
|
||||
@@ -132,44 +138,250 @@ export interface Guild {
|
||||
|
||||
export type ImageSize = 16 | 32 | 64 | 128 | 256 | 512 | 1024 | 2048
|
||||
export type ImageFormats = 'jpg' | 'jpeg' | 'png' | 'webp' | 'gif'
|
||||
export type ChannelType = 'text' | 'dm' | 'news' | 'voice' | 'category' | 'store'
|
||||
|
||||
export type Permission =
|
||||
| `CREATE_INSTANT_INVITE`
|
||||
| `KICK_MEMBERS`
|
||||
| `BAN_MEMBERS`
|
||||
| `ADMINISTRATOR`
|
||||
| `MANAGE_CHANNELS`
|
||||
| `MANAGE_GUILD`
|
||||
| `ADD_REACTIONS`
|
||||
| `VIEW_AUDIT_LOG`
|
||||
| `VIEW_CHANNEL`
|
||||
| `SEND_MESSAGES`
|
||||
| `SEND_TTS_MESSAGES`
|
||||
| `MANAGE_MESSAGES`
|
||||
| `EMBED_LINKS`
|
||||
| `ATTACH_FILES`
|
||||
| `READ_MESSAGE_HISTORY`
|
||||
| `MENTION_EVERYONE`
|
||||
| `USE_EXTERNAL_EMOJIS`
|
||||
| `CONNECT`
|
||||
| `SPEAK`
|
||||
| `MUTE_MEMBERS`
|
||||
| `DEAFEN_MEMBERS`
|
||||
| `MOVE_MEMBERS`
|
||||
| `USE_VAD`
|
||||
| `PRIORITY_SPEAKER`
|
||||
| `STREAM`
|
||||
| `CHANGE_NICKNAME`
|
||||
| `MANAGE_NICKNAMES`
|
||||
| `MANAGE_ROLES`
|
||||
| `MANAGE_WEBHOOKS`
|
||||
| `MANAGE_EMOJIS`
|
||||
|
||||
export interface Overwrite {
|
||||
/** The role or user id */
|
||||
id: string
|
||||
/** Whether this is a role or a member */
|
||||
type: 'role' | 'member'
|
||||
/** The permissions that this id is allowed to do. (This will mark it as a green check.) */
|
||||
allow: Permission[]
|
||||
/** The permissions that this id is NOT allowed to do. (This will mark it as a red x.) */
|
||||
deny: Permission[]
|
||||
}
|
||||
|
||||
export enum ChannelTypes {
|
||||
text,
|
||||
dm,
|
||||
voice,
|
||||
category = 4,
|
||||
news,
|
||||
store
|
||||
}
|
||||
|
||||
export enum Permissions {
|
||||
CREATE_INSTANT_INVITE = 0x00000001,
|
||||
KICK_MEMBERS = 0x00000002,
|
||||
BAN_MEMBERS = 0x00000004,
|
||||
ADMINISTRATOR = 0x00000008,
|
||||
MANAGE_CHANNELS = 0x00000010,
|
||||
MANAGE_GUILD = 0x00000020,
|
||||
ADD_REACTIONS = 0x00000040,
|
||||
VIEW_AUDIT_LOG = 0x00000080,
|
||||
VIEW_CHANNEL = 0x00000400,
|
||||
SEND_MESSAGES = 0x00000800,
|
||||
SEND_TTS_MESSAGES = 0x00001000,
|
||||
MANAGE_MESSAGES = 0x00002000,
|
||||
EMBED_LINKS = 0x00004000,
|
||||
ATTACH_FILES = 0x00008000,
|
||||
READ_MESSAGE_HISTORY = 0x00010000,
|
||||
MENTION_EVERYONE = 0x00020000,
|
||||
USE_EXTERNAL_EMOJIS = 0x00040000,
|
||||
CONNECT = 0x00100000,
|
||||
SPEAK = 0x00200000,
|
||||
MUTE_MEMBERS = 0x00400000,
|
||||
DEAFEN_MEMBERS = 0x00800000,
|
||||
MOVE_MEMBERS = 0x01000000,
|
||||
USE_VAD = 0x02000000,
|
||||
PRIORITY_SPEAKER = 0x00000100,
|
||||
STREAM = 0x00000200,
|
||||
CHANGE_NICKNAME = 0x04000000,
|
||||
MANAGE_NICKNAMES = 0x08000000,
|
||||
MANAGE_ROLES = 0x10000000,
|
||||
MANAGE_WEBHOOKS = 0x20000000,
|
||||
MANAGE_EMOJIS = 0x40000000
|
||||
}
|
||||
|
||||
export interface ChannelCreateOptions {
|
||||
/** The type of the channel */
|
||||
type?: ChannelType
|
||||
/** The channel topic. (0-1024 characters) */
|
||||
topic?: string
|
||||
/** The bitrate(in bits) of the voice channel. */
|
||||
bitrate?: number
|
||||
/** The user limit of the voice channel. */
|
||||
user_limit?: number
|
||||
/** The amount of seconds a user has to wait before sending another message. (0-21600 seconds). Bots, as well as users with the permission `manage_messages or manage_channel` are unaffected. */
|
||||
rate_limit_per_user?: number
|
||||
/** The sorting position of the channel */
|
||||
position?: number
|
||||
/** The channel's permission overwrites */
|
||||
permission_overwrites?: Overwrite[]
|
||||
/** The id of the parent category for the channel */
|
||||
parent_id?: string
|
||||
/** Whether the channel is nsfw */
|
||||
nsfw?: boolean
|
||||
/** The reason to add in the Audit Logs. */
|
||||
reason?: string
|
||||
}
|
||||
|
||||
export interface CreateEmojisOptions {
|
||||
/** The roles for which this emoji will be whitelisted. Only the users with one of these roles can use this emoji. */
|
||||
roles: string[]
|
||||
/** The reason to have in the Audit Logs. */
|
||||
reason: string
|
||||
}
|
||||
|
||||
export interface EditEmojisOptions {
|
||||
/** The name of the emoji */
|
||||
name: string
|
||||
/** The roles for which this emoji will be whitelisted. Only the users with one of these roles can use this emoji. */
|
||||
roles: string[]
|
||||
}
|
||||
|
||||
export interface CreateRoleOptions {
|
||||
name?: string
|
||||
permissions?: Permission[]
|
||||
color?: number
|
||||
hoist?: boolean
|
||||
mentionable?: boolean
|
||||
}
|
||||
|
||||
export interface PrunePayload {
|
||||
pruned: number
|
||||
}
|
||||
|
||||
export const createGuild = (data: CreateGuildPayload, client: Client) => {
|
||||
const guild: Guild = {
|
||||
id: data.id,
|
||||
name: data.name,
|
||||
icon: data.icon,
|
||||
splash: data.splash,
|
||||
ownerID: data.owner_id,
|
||||
region: data.region,
|
||||
afkChannelID: data.afk_channel_id,
|
||||
afkTimeout: data.afk_timeout,
|
||||
verificationLevel: data.verification_level,
|
||||
roles: data.roles.map(role => createRole(role)),
|
||||
emojis: data.emojis.map(emoji => createEmoji(emoji)),
|
||||
features: data.features,
|
||||
mfaLevel: data.mfa_level,
|
||||
systemChannelID: data.system_channel_id,
|
||||
joinedAt: Date.parse(data.joined_at),
|
||||
large: data.large,
|
||||
unavailable: data.unavailable,
|
||||
memberCount: data.member_count,
|
||||
voiceStates: data.voice_states.map(voiceState => createVoiceState(voiceState)),
|
||||
members: data.members.map(member => createMember(member)),
|
||||
channels: data.channels.map(channel => createChannel(channel)),
|
||||
presences: data.presences.map(presence => createPresence(presence)),
|
||||
maxPresences: data.max_presences,
|
||||
maxMembers: data.max_members,
|
||||
vanityURLCode: data.vanity_url_code,
|
||||
description: data.description,
|
||||
banner: data.banner,
|
||||
premiumTier: data.premium_tier,
|
||||
premiumSubscriptionCount: data.premium_subscription_count,
|
||||
preferredLocale: data.preferred_locale,
|
||||
iconURL: (size: ImageSize = 128, format?: ImageFormats) => data.icon ? formatImageURL(endpoints.GUILD_ICON(data.id, data.icon), size, format) : undefined,
|
||||
splashURL: (size: ImageSize = 128, format?: ImageFormats) => data.splash ? formatImageURL(endpoints.GUILD_SPLASH(data.id, data.splash), size, format) : undefined,
|
||||
bannerURL: (size: ImageSize = 128, format?: ImageFormats) => data.banner ? formatImageURL(endpoints.GUILD_BANNER(data.id, data.banner), size, format) : undefined,
|
||||
createChannel: (name, )
|
||||
}
|
||||
const guild: Guild = {
|
||||
id: data.id,
|
||||
name: data.name,
|
||||
icon: data.icon,
|
||||
splash: data.splash,
|
||||
ownerID: data.owner_id,
|
||||
region: data.region,
|
||||
afkChannelID: data.afk_channel_id,
|
||||
afkTimeout: data.afk_timeout,
|
||||
verificationLevel: data.verification_level,
|
||||
roles: data.roles.map(role => createRole(role)),
|
||||
emojis: data.emojis.map(emoji => createEmoji(emoji)),
|
||||
features: data.features,
|
||||
mfaLevel: data.mfa_level,
|
||||
systemChannelID: data.system_channel_id,
|
||||
joinedAt: Date.parse(data.joined_at),
|
||||
large: data.large,
|
||||
unavailable: data.unavailable,
|
||||
memberCount: data.member_count,
|
||||
voiceStates: data.voice_states.map(voiceState => createVoiceState(voiceState)),
|
||||
members: data.members.map(member => createMember(member)),
|
||||
channels: data.channels.map(channel => createChannel(channel)),
|
||||
presences: data.presences.map(presence => createPresence(presence)),
|
||||
maxPresences: data.max_presences,
|
||||
maxMembers: data.max_members,
|
||||
vanityURLCode: data.vanity_url_code,
|
||||
description: data.description,
|
||||
banner: data.banner,
|
||||
premiumTier: data.premium_tier,
|
||||
premiumSubscriptionCount: data.premium_subscription_count,
|
||||
preferredLocale: data.preferred_locale,
|
||||
iconURL: (size, format) =>
|
||||
data.icon ? formatImageURL(endpoints.GUILD_ICON(data.id, data.icon), size, format) : undefined,
|
||||
splashURL: (size, format) =>
|
||||
data.splash ? formatImageURL(endpoints.GUILD_SPLASH(data.id, data.splash), size, format) : undefined,
|
||||
bannerURL: (size, format) =>
|
||||
data.banner ? formatImageURL(endpoints.GUILD_BANNER(data.id, data.banner), size, format) : undefined,
|
||||
createChannel: (name, options) => {
|
||||
// TODO: Check if the bot has `MANAGE_CHANNELS` permission before making a channel
|
||||
return client.RequestManager.post(endpoints.GUILD_CHANNELS(data.id), {
|
||||
name,
|
||||
type: options?.type ? ChannelTypes[options.type] : undefined,
|
||||
permission_overwrites: options?.permission_overwrites
|
||||
? options.permission_overwrites.map(perm => ({
|
||||
...perm,
|
||||
allow: perm.allow.map(p => Permissions[p]),
|
||||
deny: perm.deny.map(p => Permissions[p])
|
||||
}))
|
||||
: undefined,
|
||||
...options
|
||||
})
|
||||
},
|
||||
createEmoji: (name, image, options) => {
|
||||
// TODO: Check if the bot has `MANAGE_EMOJIS` permission
|
||||
return client.RequestManager.post(endpoints.GUILD_EMOJIS(data.id), {
|
||||
...options,
|
||||
name,
|
||||
image
|
||||
})
|
||||
},
|
||||
editEmoji: (id, options) => {
|
||||
// TODO: check if the bot has `MANAGE_EMOJIS` permission
|
||||
return client.RequestManager.patch(endpoints.GUILD_EMOJI(data.id, id), {
|
||||
name: options.name,
|
||||
roles: options.roles
|
||||
})
|
||||
},
|
||||
deleteEmoji: (id, reason) => {
|
||||
// TODO: check if the bot has `MANAGE_EMOJIS` permission
|
||||
return client.RequestManager.delete(endpoints.GUILD_EMOJI(data.id, id), { reason })
|
||||
},
|
||||
createRole: async options => {
|
||||
// TODO: check if the bot has the `MANAGE_ROLES` permission.
|
||||
const role = await client.RequestManager.post(endpoints.GUILD_ROLES(data.id), {
|
||||
...options,
|
||||
permissions: options.permissions?.map(perm => Permissions[perm])
|
||||
})
|
||||
// TODO: cache this role
|
||||
|
||||
return guild
|
||||
return role
|
||||
},
|
||||
editRole: (id, options) => {
|
||||
return client.RequestManager.patch(endpoints.GUILD_ROLE(data.id, id), options)
|
||||
},
|
||||
deleteRole: id => {
|
||||
return client.RequestManager.delete(endpoints.GUILD_ROLE(data.id, id))
|
||||
},
|
||||
getPruneCount: async days => {
|
||||
if (days < 1) throw `The number of days to count prune for must be 1 or more.`
|
||||
// TODO: check if the bot has `KICK_MEMBERS` permission
|
||||
const result = (await client.RequestManager.get(endpoints.GUILD_PRUNE(data.id), { days })) as PrunePayload
|
||||
return result.pruned
|
||||
},
|
||||
pruneMembers: days => {
|
||||
if (days < 1) throw `The number of days must be 1 or more.`
|
||||
// TODO: check if the bot has `KICK_MEMBERS` permission.
|
||||
return client.RequestManager.post(endpoints.GUILD_PRUNE(data.id), { days })
|
||||
},
|
||||
getAuditLogs: options => {
|
||||
// TODO: check if the bot has VIEW_AUDIT_LOGS permission
|
||||
return client.RequestManager.get(endpoints.GUILD_AUDIT_LOGS(data.id), {
|
||||
...options,
|
||||
limit: options.limit && options.limit >= 1 && options.limit <= 100 ? options.limit : 50
|
||||
})
|
||||
},
|
||||
leaveVoiceChannel: () => {}
|
||||
}
|
||||
|
||||
return guild
|
||||
}
|
||||
|
||||
3
structures/member.ts
Normal file
3
structures/member.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export const createMember = (data: unknown) => {
|
||||
console.log(data)
|
||||
}
|
||||
@@ -41,4 +41,8 @@ export interface ClientStatusPayload {
|
||||
|
||||
/** The user's status set for an active web (browser, bot account) application session */
|
||||
web?: StatusType;
|
||||
}
|
||||
}
|
||||
|
||||
export const createPresence = (data: unknown) => {
|
||||
console.log(data)
|
||||
}
|
||||
|
||||
3
structures/role.ts
Normal file
3
structures/role.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export const createRole = (data: unknown) => {
|
||||
console.log(data)
|
||||
}
|
||||
3
structures/voiceState.ts
Normal file
3
structures/voiceState.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export const createVoiceState = (data: unknown) => {
|
||||
console.log(data)
|
||||
}
|
||||
212
types/discord.ts
212
types/discord.ts
@@ -1,12 +1,12 @@
|
||||
export interface DiscordPayload {
|
||||
/** OP code for the payload */
|
||||
op: number
|
||||
/** The real event data. Any JSON value basically. */
|
||||
d: unknown
|
||||
/** The sequence number, used for resuming sessions and heartbeats. ONLY for OPCode 0 */
|
||||
s?: number
|
||||
/** The event name for this payload. ONLY for OPCode 0 */
|
||||
t?: string
|
||||
/** OP code for the payload */
|
||||
op: number
|
||||
/** The real event data. Any JSON value basically. */
|
||||
d: unknown
|
||||
/** The sequence number, used for resuming sessions and heartbeats. ONLY for OPCode 0 */
|
||||
s?: number
|
||||
/** The event name for this payload. ONLY for OPCode 0 */
|
||||
t?: string
|
||||
}
|
||||
|
||||
export interface DiscordBotGatewayData {
|
||||
@@ -26,7 +26,7 @@ export interface DiscordBotGatewayData {
|
||||
}
|
||||
|
||||
export interface DiscordHeartbeatPayload {
|
||||
heartbeat_interval: number
|
||||
heartbeat_interval: number
|
||||
}
|
||||
|
||||
export enum GatewayOpcode {
|
||||
@@ -44,115 +44,115 @@ export enum GatewayOpcode {
|
||||
}
|
||||
|
||||
export enum GatewayCloseEventCode {
|
||||
UnknownError = 4000,
|
||||
UnknownOpcode,
|
||||
DecodeError,
|
||||
NotAuthenticated,
|
||||
AuthenticationFailed,
|
||||
AlreadyAuthenticated,
|
||||
InvalidSeq = 4007,
|
||||
RateLimited,
|
||||
SessionTimeout,
|
||||
InvalidShard,
|
||||
ShardingRequired
|
||||
UnknownError = 4000,
|
||||
UnknownOpcode,
|
||||
DecodeError,
|
||||
NotAuthenticated,
|
||||
AuthenticationFailed,
|
||||
AlreadyAuthenticated,
|
||||
InvalidSeq = 4007,
|
||||
RateLimited,
|
||||
SessionTimeout,
|
||||
InvalidShard,
|
||||
ShardingRequired
|
||||
}
|
||||
|
||||
export enum VoiceOpcode {
|
||||
Identify,
|
||||
SelectProtocol,
|
||||
Ready,
|
||||
Heartbeat,
|
||||
SessionDescription,
|
||||
Speaking,
|
||||
HeartbeatACK,
|
||||
Resume,
|
||||
Hello,
|
||||
Resumed,
|
||||
ClientDisconnect = 13
|
||||
Identify,
|
||||
SelectProtocol,
|
||||
Ready,
|
||||
Heartbeat,
|
||||
SessionDescription,
|
||||
Speaking,
|
||||
HeartbeatACK,
|
||||
Resume,
|
||||
Hello,
|
||||
Resumed,
|
||||
ClientDisconnect = 13
|
||||
}
|
||||
|
||||
export enum VoiceCloseEventCode {
|
||||
UnknownOpcode = 4001,
|
||||
NotAuthenticated = 4003,
|
||||
AuthenticationFailed,
|
||||
AlreadyAuthenticated,
|
||||
SessionNoLongerValid,
|
||||
SessionTimeout = 4009,
|
||||
ServerNotFound = 4011,
|
||||
UnknownProtocol,
|
||||
Disconnected = 4014,
|
||||
VoiceServerCrashed,
|
||||
UnknownEncryptionMode
|
||||
UnknownOpcode = 4001,
|
||||
NotAuthenticated = 4003,
|
||||
AuthenticationFailed,
|
||||
AlreadyAuthenticated,
|
||||
SessionNoLongerValid,
|
||||
SessionTimeout = 4009,
|
||||
ServerNotFound = 4011,
|
||||
UnknownProtocol,
|
||||
Disconnected = 4014,
|
||||
VoiceServerCrashed,
|
||||
UnknownEncryptionMode
|
||||
}
|
||||
|
||||
export enum HttpResponseCode {
|
||||
Ok = 200,
|
||||
Created,
|
||||
NoContent = 204,
|
||||
NotModified = 304,
|
||||
BadRequest = 400,
|
||||
Unauthorized = 401,
|
||||
Forbidden = 403,
|
||||
NotFound,
|
||||
MethodNotAllowed,
|
||||
TooManyRequests = 429,
|
||||
GatewayUnavailable = 502,
|
||||
// ServerError left untyped because it's 5xx.
|
||||
Ok = 200,
|
||||
Created,
|
||||
NoContent = 204,
|
||||
NotModified = 304,
|
||||
BadRequest = 400,
|
||||
Unauthorized = 401,
|
||||
Forbidden = 403,
|
||||
NotFound,
|
||||
MethodNotAllowed,
|
||||
TooManyRequests = 429,
|
||||
GatewayUnavailable = 502
|
||||
// ServerError left untyped because it's 5xx.
|
||||
}
|
||||
|
||||
export enum JSONErrorCode {
|
||||
UnknownAccount = 10001,
|
||||
UnknownApplication,
|
||||
UnknownChannel,
|
||||
UnknownGuild,
|
||||
UnknownIntegration,
|
||||
UnknownInvite,
|
||||
UnknownMember,
|
||||
UnknownMessge,
|
||||
UnknownOverwrite,
|
||||
UnknownProvider,
|
||||
UnknownRole,
|
||||
UnknownToken = 10012,
|
||||
UnknownUser,
|
||||
UnknownEmoji,
|
||||
UnknownWebhook,
|
||||
BotsCannotUse = 20001,
|
||||
OnlyBotsCanUse,
|
||||
MaxGuildsReached = 30001,
|
||||
MaxFriendsReached,
|
||||
MaxPinsReached,
|
||||
MaxGuildRolesReached = 30005,
|
||||
MaxReactionsReached = 30010,
|
||||
MaxGuildChannelsReached = 30013,
|
||||
MaxInvitesReached = 30016,
|
||||
Unathorized = 40001,
|
||||
UserIsBannedFromGuild = 40007,
|
||||
MissingAccess = 50001,
|
||||
InvalidAccountType = 50002,
|
||||
CannotExecuteOnDMChannel,
|
||||
WidgetDisabled,
|
||||
CannotEditMessageByAnotherUser,
|
||||
CannotSendEmptyMessage,
|
||||
CannotSendMessageToUser,
|
||||
CannotSendMessageInVoiceChannel,
|
||||
ChannelVerificationTooHigh,
|
||||
OAuth2ApplicationNoBot,
|
||||
OAuth2ApplicationLimitReached,
|
||||
InvalidOAuthState,
|
||||
MissingPermissions,
|
||||
InvalidAuthenticationToken,
|
||||
NoteIsTooLong,
|
||||
TooFewOrTooManyMessagesToDelete,
|
||||
MessageCanOnlyBePinnedInParentChannel = 50019,
|
||||
InviteCodeTakenOrInvalid,
|
||||
CannotExecuteOnSystemMessage,
|
||||
InvalidOAuth2AccessToken,
|
||||
MessageProvidedTooOldToBulkDelet = 50034,
|
||||
InvalidFormBody,
|
||||
InviteAcceptedToGuildApplicationBotNotIn,
|
||||
InvalidAPIVersion = 50041,
|
||||
ReactionBlocked = 90001,
|
||||
ResourceOverloaded = 130000
|
||||
UnknownAccount = 10001,
|
||||
UnknownApplication,
|
||||
UnknownChannel,
|
||||
UnknownGuild,
|
||||
UnknownIntegration,
|
||||
UnknownInvite,
|
||||
UnknownMember,
|
||||
UnknownMessge,
|
||||
UnknownOverwrite,
|
||||
UnknownProvider,
|
||||
UnknownRole,
|
||||
UnknownToken = 10012,
|
||||
UnknownUser,
|
||||
UnknownEmoji,
|
||||
UnknownWebhook,
|
||||
BotsCannotUse = 20001,
|
||||
OnlyBotsCanUse,
|
||||
MaxGuildsReached = 30001,
|
||||
MaxFriendsReached,
|
||||
MaxPinsReached,
|
||||
MaxGuildRolesReached = 30005,
|
||||
MaxReactionsReached = 30010,
|
||||
MaxGuildChannelsReached = 30013,
|
||||
MaxInvitesReached = 30016,
|
||||
Unathorized = 40001,
|
||||
UserIsBannedFromGuild = 40007,
|
||||
MissingAccess = 50001,
|
||||
InvalidAccountType = 50002,
|
||||
CannotExecuteOnDMChannel,
|
||||
WidgetDisabled,
|
||||
CannotEditMessageByAnotherUser,
|
||||
CannotSendEmptyMessage,
|
||||
CannotSendMessageToUser,
|
||||
CannotSendMessageInVoiceChannel,
|
||||
ChannelVerificationTooHigh,
|
||||
OAuth2ApplicationNoBot,
|
||||
OAuth2ApplicationLimitReached,
|
||||
InvalidOAuthState,
|
||||
MissingPermissions,
|
||||
InvalidAuthenticationToken,
|
||||
NoteIsTooLong,
|
||||
TooFewOrTooManyMessagesToDelete,
|
||||
MessageCanOnlyBePinnedInParentChannel = 50019,
|
||||
InviteCodeTakenOrInvalid,
|
||||
CannotExecuteOnSystemMessage,
|
||||
InvalidOAuth2AccessToken,
|
||||
MessageProvidedTooOldToBulkDelet = 50034,
|
||||
InvalidFormBody,
|
||||
InviteAcceptedToGuildApplicationBotNotIn,
|
||||
InvalidAPIVersion = 50041,
|
||||
ReactionBlocked = 90001,
|
||||
ResourceOverloaded = 130000
|
||||
}
|
||||
|
||||
export interface Properties {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { ImageSize, ImageFormats } from "../structures/guild"
|
||||
import { ImageSize, ImageFormats } from '../structures/guild'
|
||||
|
||||
export const formatImageURL = (url: string, size: ImageSize = 128, format?: ImageFormats) => {
|
||||
return `${url}.${format || url.includes("/a_") ? "gif" : 'jpg'}/?size=${size}`
|
||||
return `${url}.${format || url.includes('/a_') ? 'gif' : 'jpg'}/?size=${size}`
|
||||
}
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
import { blue, green, red, yellow } from "https://deno.land/std/fmt/colors.ts"
|
||||
import { blue, green, red, yellow } from 'https://deno.land/std/fmt/colors.ts'
|
||||
|
||||
export const getTime = () => {
|
||||
const now = new Date()
|
||||
const hours = now.getHours()
|
||||
const minute = now.getMinutes()
|
||||
const now = new Date()
|
||||
const hours = now.getHours()
|
||||
const minute = now.getMinutes()
|
||||
|
||||
let hour = hours
|
||||
let amOrPm = `AM`
|
||||
if (hour > 12) {
|
||||
amOrPm = `PM`
|
||||
hour = hour - 12
|
||||
}
|
||||
let hour = hours
|
||||
let amOrPm = `AM`
|
||||
if (hour > 12) {
|
||||
amOrPm = `PM`
|
||||
hour = hour - 12
|
||||
}
|
||||
|
||||
return `${hour >= 10 ? hour : `0${hour}`}:${minute >= 10 ? minute : `0${minute}`} ${amOrPm}`
|
||||
return `${hour >= 10 ? hour : `0${hour}`}:${minute >= 10 ? minute : `0${minute}`} ${amOrPm}`
|
||||
}
|
||||
|
||||
export const logGreen = (text: string) => {
|
||||
console.log(green(`[${getTime()}] => ${text}`))
|
||||
console.log(green(`[${getTime()}] => ${text}`))
|
||||
}
|
||||
|
||||
export const logBlue = (text: string) => {
|
||||
console.log(blue(`[${getTime()}] => ${text}`))
|
||||
console.log(blue(`[${getTime()}] => ${text}`))
|
||||
}
|
||||
|
||||
export const logRed = (text: string) => {
|
||||
console.log(red(`[${getTime()}] => ${text}`))
|
||||
console.log(red(`[${getTime()}] => ${text}`))
|
||||
}
|
||||
|
||||
export const logYellow = (text: string) => {
|
||||
console.log(yellow(`[${getTime()}] => ${text}`))
|
||||
console.log(yellow(`[${getTime()}] => ${text}`))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user