add RESTManager#endpoints

This commit is contained in:
DjDeveloperr 2021-04-04 13:15:37 +05:30
parent de7996d552
commit 1c7416628d
7 changed files with 117611 additions and 7 deletions

116161
harmony.js Normal file

File diff suppressed because it is too large Load diff

1291
src/rest/endpoints.ts Normal file

File diff suppressed because it is too large Load diff

View file

@ -11,6 +11,7 @@ import {
METHODS METHODS
} from './types.ts' } from './types.ts'
import { Constants } from '../types/constants.ts' import { Constants } from '../types/constants.ts'
import { RESTEndpoints } from './endpoints.ts'
export class DiscordAPIError extends Error { export class DiscordAPIError extends Error {
name = 'DiscordAPIError' name = 'DiscordAPIError'
@ -171,6 +172,7 @@ export class RESTManager {
canary?: boolean canary?: boolean
/** Optional Harmony Client object */ /** Optional Harmony Client object */
client?: Client client?: Client
endpoints: RESTEndpoints
constructor(options?: RESTOptions) { constructor(options?: RESTOptions) {
this.api = builder(this) this.api = builder(this)
@ -181,6 +183,7 @@ export class RESTManager {
if (options?.userAgent !== undefined) this.userAgent = options.userAgent if (options?.userAgent !== undefined) this.userAgent = options.userAgent
if (options?.canary !== undefined) this.canary = options.canary if (options?.canary !== undefined) this.canary = options.canary
if (options?.client !== undefined) this.client = options.client if (options?.client !== undefined) this.client = options.client
this.endpoints = new RESTEndpoints(this)
this.handleRateLimits() this.handleRateLimits()
} }

View file

@ -29,7 +29,7 @@ export interface GuildChannelPayload extends ChannelPayload {
export interface GuildTextBasedChannelPayload export interface GuildTextBasedChannelPayload
extends TextChannelPayload, extends TextChannelPayload,
GuildChannelPayload { GuildChannelPayload {
topic?: string topic?: string
} }
@ -37,7 +37,7 @@ export interface GuildTextChannelPayload extends GuildTextBasedChannelPayload {
rate_limit_per_user: number rate_limit_per_user: number
} }
export interface GuildNewsChannelPayload extends GuildTextBasedChannelPayload { } export interface GuildNewsChannelPayload extends GuildTextBasedChannelPayload {}
export interface GuildVoiceChannelPayload extends GuildChannelPayload { export interface GuildVoiceChannelPayload extends GuildChannelPayload {
bitrate: string bitrate: string
@ -56,7 +56,7 @@ export interface GroupDMChannelPayload extends DMChannelPayload {
export interface GuildCategoryChannelPayload export interface GuildCategoryChannelPayload
extends ChannelPayload, extends ChannelPayload,
GuildChannelPayload { } GuildChannelPayload {}
export interface ModifyChannelPayload { export interface ModifyChannelPayload {
name?: string name?: string
@ -67,7 +67,7 @@ export interface ModifyChannelPayload {
} }
export interface ModifyGuildCategoryChannelPayload export interface ModifyGuildCategoryChannelPayload
extends ModifyChannelPayload { } extends ModifyChannelPayload {}
export interface ModifyGuildTextBasedChannelPayload export interface ModifyGuildTextBasedChannelPayload
extends ModifyChannelPayload { extends ModifyChannelPayload {
@ -81,7 +81,7 @@ export interface ModifyGuildTextChannelPayload
} }
export interface ModifyGuildNewsChannelPayload export interface ModifyGuildNewsChannelPayload
extends ModifyGuildTextBasedChannelPayload { } extends ModifyGuildTextBasedChannelPayload {}
export interface ModifyVoiceChannelPayload extends ModifyChannelPayload { export interface ModifyVoiceChannelPayload extends ModifyChannelPayload {
bitrate?: number | null bitrate?: number | null
@ -96,7 +96,7 @@ export interface ModifyChannelOption {
nsfw?: boolean | null nsfw?: boolean | null
} }
export interface ModifyGuildCategoryChannelOption extends ModifyChannelOption { } export interface ModifyGuildCategoryChannelOption extends ModifyChannelOption {}
export interface ModifyGuildTextBasedChannelOption extends ModifyChannelOption { export interface ModifyGuildTextBasedChannelOption extends ModifyChannelOption {
type?: number type?: number
@ -109,7 +109,7 @@ export interface ModifyGuildTextChannelOption
} }
export interface ModifyGuildNewsChannelOption export interface ModifyGuildNewsChannelOption
extends ModifyGuildTextBasedChannelOption { } extends ModifyGuildTextBasedChannelOption {}
export interface ModifyVoiceChannelOption extends ModifyChannelOption { export interface ModifyVoiceChannelOption extends ModifyChannelOption {
bitrate?: number | null bitrate?: number | null
@ -382,3 +382,32 @@ export interface MessageInteractionPayload {
name: string name: string
user: UserPayload user: UserPayload
} }
export interface EditMessagePayload {
content?: string
embed?: EmbedPayload
allowed_mentions?: AllowedMentionsPayload
flags?: number
}
export interface CreateMessagePayload extends EditMessagePayload {
nonce?: string
tts?: boolean
message_reference?: MessageReference
file?: MessageAttachment
files?: MessageAttachment[]
}
export interface CreateWebhookMessageBasePayload {
content?: string
embeds?: EmbedPayload[]
tts?: boolean
file?: MessageAttachment
files?: MessageAttachment[]
allowed_mentions?: AllowedMentionsPayload
}
export interface CreateWebhookMessagePayload extends CreateMessagePayload {
username?: string
avatar_url?: string
}

View file

@ -10,3 +10,9 @@ export interface EmojiPayload {
animated?: boolean animated?: boolean
available?: boolean available?: boolean
} }
export interface CreateEmojiPayload {
name: string
image: string
roles?: string[]
}

View file

@ -23,6 +23,7 @@ import { PresenceUpdatePayload } from './gateway.ts'
import { RolePayload } from './role.ts' import { RolePayload } from './role.ts'
import { UserPayload } from './user.ts' import { UserPayload } from './user.ts'
import { VoiceStatePayload } from './voice.ts' import { VoiceStatePayload } from './voice.ts'
import { WebhookPayload } from './webhook.ts'
export interface GuildPayload { export interface GuildPayload {
id: string id: string
@ -326,3 +327,99 @@ export interface GuildBeginPrunePayload {
compute_prune_count?: boolean compute_prune_count?: boolean
include_roles?: string[] include_roles?: string[]
} }
export enum AuditLogEvents {
GuildUpdate = 1,
ChannelCreate = 10,
ChannelUpdate = 11,
ChannelDelete = 12,
ChannelOverwriteCreate = 13,
ChannelOverwriteUpdate = 14,
ChannelOverwriteDelete = 15,
MemberKick = 20,
MemberPrune = 21,
MemberBanAdd = 22,
MemberBanRemove = 23,
MemberUpdate = 24,
MemberRoleUpdate = 25,
MemberMove = 26,
MemberDisconnect = 27,
BotAdd = 28,
RoleCreate = 30,
RoleUpdate = 31,
RoleDelete = 32,
InviteCreate = 40,
InviteUpdate = 41,
InviteDelete = 42,
WebhookCreate = 50,
WebhookUpdate = 51,
WebhookDelete = 52,
EmojiCreate = 60,
EmojiUpdate = 61,
EmojiDelete = 62,
MessageDelete = 72,
MessageBulkDelete = 73,
MessagePin = 74,
MessageUnpin = 75,
IntegrationCreate = 80,
IntegrationUpdate = 81,
IntegrationDelete = 82
}
export interface AuditLogPayload {
/** list of webhooks found in the audit log */
webhooks: WebhookPayload[]
/** list of users found in the audit log */
users: UserPayload[]
/** list of audit log entries */
audit_log_entries: AuditLogEntryPayload[]
/** list of partial integration objects */
integrations: GuildIntegrationPayload[]
}
export interface AuditLogEntryPayload {
/** id of the affected entity (webhook, user, role, etc.) */
target_id: string | null
/** changes made to the target_id */
changes?: AuditLogChangePayload[]
/** the user who made the changes */
user_id: string
/** id of the entry */
id: string
/** type of action that occurred */
action_type: AuditLogEvents
/** additional info for certain action types */
options?: OptionalAuditEntryInfoPayload
/** the reason for the change (0-512 characters) */
reason?: string
}
export interface OptionalAuditEntryInfoPayload {
/** number of days after which inactive members were kicked */
delete_member_days: string
/** number of members removed by the prune */
members_removed: string
/** channel in which the entities were targeted */
channel_id: string
/** id of the message that was targeted */
message_id: string
/** number of entities that were targeted */
count: string
/** id of the overwritten entity */
id: string
/** type of overwritten entity - "0" for "role" or "1" for "member" */
type: string
/** name of the role if type is "0" (not present if type is "1") */
role_name: string
}
/** > info
> If `new_value` is not present in the change object, while `old_value` is, that means the property that was changed has been reset, or set to `null` */
export interface AuditLogChangePayload {
/** new value of the key */
new_value?: any
/** old value of the key */
old_value?: any
/** name of audit log [change key](#DOCS_RESOURCES_AUDIT_LOG/audit-log-change-object-audit-log-change-key) */
key: string
}

View file

@ -20,3 +20,20 @@ export interface PartialInvitePayload {
channel: Channel channel: Channel
guild?: Guild guild?: Guild
} }
export interface InviteMetadataPayload {
/** number of times this invite has been used */
uses: number
/** max number of times this invite can be used */
max_uses: number
/** duration (in seconds) after which the invite expires */
max_age: number
/** whether this invite only grants temporary membership */
temporary: boolean
/** when this invite was created */
created_at: Date
}
export interface InviteWithMetadataPayload
extends InvitePayload,
InviteMetadataPayload {}