From cfcdd3cfe8d4bfe8fe132e704a9ddd4f223b3e91 Mon Sep 17 00:00:00 2001 From: abdulrahman1s Date: Mon, 30 May 2022 08:06:23 +0200 Subject: [PATCH] docs: Use deps.ts instead of import map. (cuz docland didn't support import map) --- deno.json | 1 - deps.ts | 5 +++++ import.json | 9 --------- scripts/build_npm.ts | 1 - src/client/BaseClient.ts | 3 +-- src/client/Client.ts | 4 ++-- src/client/actions/ChannelCreate.ts | 4 ++-- src/client/actions/ChannelUpdate.ts | 4 ++-- src/client/actions/Message.ts | 4 ++-- src/client/actions/MessageUpdate.ts | 4 ++-- src/client/actions/ServerDelete.ts | 4 ++-- src/client/actions/ServerMemberUpdate.ts | 4 ++-- src/client/actions/ServerUpdate.ts | 4 ++-- src/client/actions/UserUpdate.ts | 4 ++-- src/managers/ChannelManager.ts | 8 ++++---- src/managers/MessageManager.ts | 14 +++++++------- src/managers/RoleManager.ts | 6 +++--- src/managers/ServerChannelManager.ts | 6 +++--- src/managers/ServerManager.ts | 6 +++--- src/managers/ServerMemberManager.ts | 6 +++--- src/managers/UserManager.ts | 12 ++++++------ src/structures/Category.ts | 8 ++++---- src/structures/Channel.ts | 4 ++-- src/structures/DMChannel.ts | 4 ++-- src/structures/GroupChannel.ts | 4 ++-- src/structures/Message.ts | 21 ++++++++------------- src/structures/MessageEmbed.ts | 12 ++++++------ src/structures/NotesChannel.ts | 4 ++-- src/structures/Role.ts | 6 +++--- src/structures/Server.ts | 8 ++++---- src/structures/ServerChannel.ts | 4 ++-- src/structures/ServerMember.ts | 10 +++++----- src/structures/TextChannel.ts | 4 ++-- src/structures/User.ts | 18 ++++++++---------- src/structures/VoiceChannel.ts | 4 ++-- src/util/Collection.ts | 2 +- src/util/UUID.ts | 2 +- 37 files changed, 107 insertions(+), 121 deletions(-) create mode 100644 deps.ts delete mode 100644 import.json diff --git a/deno.json b/deno.json index 26822be..465e657 100644 --- a/deno.json +++ b/deno.json @@ -1,5 +1,4 @@ { - "importMap": "import.json", "compilerOptions": { "strict": true }, diff --git a/deps.ts b/deps.ts new file mode 100644 index 0000000..52f5b76 --- /dev/null +++ b/deps.ts @@ -0,0 +1,5 @@ +export { EventEmitter } from 'https://deno.land/std@0.132.0/node/events.ts' +export { randomBytes } from 'https://deno.land/std@0.132.0/node/crypto.ts' +export { Collection } from 'https://esm.sh/@discordjs/collection@0.6.0' +export * as API from 'https://deno.land/x/revolt_api@0.4.0/types.ts' +export * from 'https://deno.land/x/revoltio_rest@v1.1.3/mod.ts' \ No newline at end of file diff --git a/import.json b/import.json deleted file mode 100644 index a72ecec..0000000 --- a/import.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "imports": { - "revolt-api-types": "https://deno.land/x/revolt_api@0.4.0/types.ts", - "events": "https://deno.land/std@0.132.0/node/events.ts", - "crypto": "https://deno.land/std@0.132.0/node/crypto.ts", - "collection": "https://esm.sh/@discordjs/collection@0.6.0", - "@revoltio/rest": "https://deno.land/x/revoltio_rest@v1.1.3/mod.ts" - } -} diff --git a/scripts/build_npm.ts b/scripts/build_npm.ts index 5416df6..1d13c87 100644 --- a/scripts/build_npm.ts +++ b/scripts/build_npm.ts @@ -19,7 +19,6 @@ await build({ compilerOptions: { target: 'ES2021', }, - importMap: './import.json', mappings: { 'https://deno.land/x/revoltio_rest@v1.1.3/mod.ts': { name: '@revoltio/rest', diff --git a/src/client/BaseClient.ts b/src/client/BaseClient.ts index e82718d..6bd8dce 100644 --- a/src/client/BaseClient.ts +++ b/src/client/BaseClient.ts @@ -1,7 +1,6 @@ // deno-lint-ignore-file no-explicit-any -import { EventEmitter } from 'events'; +import { EventEmitter, REST, RESTOptions } from '../../deps.ts'; import { Client } from './mod.ts'; -import { REST, RESTOptions } from '@revoltio/rest'; import type { Channel, DMChannel, diff --git a/src/client/Client.ts b/src/client/Client.ts index adbc722..3b294fc 100644 --- a/src/client/Client.ts +++ b/src/client/Client.ts @@ -1,4 +1,4 @@ -import type { RevoltConfig } from 'revolt-api-types'; +import type { API } from '../../deps.ts'; import { BaseClient, WebSocketShard } from './mod.ts'; import { ActionManager } from './actions/ActionManager.ts'; import { Error } from '../errors/mod.ts'; @@ -12,7 +12,7 @@ export class Client extends BaseClient { readonly servers = new ServerManager(this); readonly users = new UserManager(this); user: ClientUser | null = null; - configuration?: RevoltConfig; + configuration?: API.RevoltConfig; readyAt: Date | null = null; get readyTimestamp(): number | null { diff --git a/src/client/actions/ChannelCreate.ts b/src/client/actions/ChannelCreate.ts index 76d4204..0dacebd 100644 --- a/src/client/actions/ChannelCreate.ts +++ b/src/client/actions/ChannelCreate.ts @@ -1,9 +1,9 @@ -import type { Channel as APIChannel } from 'revolt-api-types'; +import type { API } from '../../../deps.ts'; import { Action } from './Action.ts'; import { Events } from '../../util/Constants.ts'; export class ChannelCreateAction extends Action { - async handle(data: APIChannel): Promise { + async handle(data: API.Channel): Promise { const channel = this.client.channels._add(data); if (channel) { diff --git a/src/client/actions/ChannelUpdate.ts b/src/client/actions/ChannelUpdate.ts index bb93f4e..9c721dc 100644 --- a/src/client/actions/ChannelUpdate.ts +++ b/src/client/actions/ChannelUpdate.ts @@ -1,9 +1,9 @@ -import type { Channel as APIChannel } from 'revolt-api-types'; +import type { API } from '../../../deps.ts'; import { Action } from './Action.ts'; import { Events } from '../../util/Constants.ts'; export class ChannelUpdateAction extends Action { - handle(data: { id: string; data: APIChannel }): unknown { + handle(data: { id: string; data: API.Channel }): unknown { const oldChannel = this.client.channels.cache.get(data.id); if (oldChannel) { diff --git a/src/client/actions/Message.ts b/src/client/actions/Message.ts index ada4ce1..e579fec 100644 --- a/src/client/actions/Message.ts +++ b/src/client/actions/Message.ts @@ -1,9 +1,9 @@ -import type { Message as APIMessage } from 'revolt-api-types'; +import type { API } from '../../../deps.ts'; import { Action } from './Action.ts'; import { Events, SYSTEM_USER_ID } from '../../util/Constants.ts'; export class MessageAction extends Action { - async handle(data: APIMessage): Promise { + async handle(data: API.Message): Promise { const channel = this.client.channels.cache.get(data.channel); if (channel?.isText()) { diff --git a/src/client/actions/MessageUpdate.ts b/src/client/actions/MessageUpdate.ts index 8692b0e..bccf69d 100644 --- a/src/client/actions/MessageUpdate.ts +++ b/src/client/actions/MessageUpdate.ts @@ -1,9 +1,9 @@ -import type { Message as APIMessage } from 'revolt-api-types'; +import type { API } from '../../../deps.ts'; import { Action } from './Action.ts'; import { Events } from '../../util/Constants.ts'; export class MessageUpdateAction extends Action { - handle(data: { id: string; channel: string; data: APIMessage }): unknown { + handle(data: { id: string; channel: string; data: API.Message }): unknown { const channel = this.client.channels.cache.get(data.channel); if (!channel?.isText()) return; diff --git a/src/client/actions/ServerDelete.ts b/src/client/actions/ServerDelete.ts index f0b048e..a32355b 100644 --- a/src/client/actions/ServerDelete.ts +++ b/src/client/actions/ServerDelete.ts @@ -1,9 +1,9 @@ -import type { Server as APIServer } from 'revolt-api-types'; +import type { API } from '../../../deps.ts'; import { Action } from './Action.ts'; import { Events } from '../../util/Constants.ts'; export class ServerDeleteAction extends Action { - handle(data: APIServer): unknown { + handle(data: API.Server): unknown { const server = this.client.servers.cache.get(data._id); if (server) { diff --git a/src/client/actions/ServerMemberUpdate.ts b/src/client/actions/ServerMemberUpdate.ts index 7d28897..b50f101 100644 --- a/src/client/actions/ServerMemberUpdate.ts +++ b/src/client/actions/ServerMemberUpdate.ts @@ -1,9 +1,9 @@ -import type { Member as APIMember } from 'revolt-api-types'; +import type { API } from '../../../deps.ts'; import { Action } from './Action.ts'; import { Events } from '../../util/Constants.ts'; export class ServerMemberUpdateAction extends Action { - handle(data: { id: string; data: APIMember }): unknown { + handle(data: { id: string; data: API.Member }): unknown { const server = this.client.servers.cache.get(data.id); const oldMember = server?.members.cache.get(data.data?._id?.user); diff --git a/src/client/actions/ServerUpdate.ts b/src/client/actions/ServerUpdate.ts index 8548cb3..204cc39 100644 --- a/src/client/actions/ServerUpdate.ts +++ b/src/client/actions/ServerUpdate.ts @@ -1,9 +1,9 @@ -import type { Server as APIServer } from 'revolt-api-types'; +import type { API } from '../../../deps.ts'; import { Action } from './Action.ts'; import { Events } from '../../util/Constants.ts'; export class ServerUpdateAction extends Action { - handle(data: { id: string; data: APIServer }): unknown { + handle(data: { id: string; data: API.Server }): unknown { const oldServer = this.client.servers.cache.get(data.id); if (oldServer) { diff --git a/src/client/actions/UserUpdate.ts b/src/client/actions/UserUpdate.ts index 0e906ce..56aabf3 100644 --- a/src/client/actions/UserUpdate.ts +++ b/src/client/actions/UserUpdate.ts @@ -1,10 +1,10 @@ -import type { User as APIUser } from 'revolt-api-types'; +import type { API } from '../../../deps.ts'; import { Action } from './Action.ts'; import { ClientUser } from '../../structures/ClientUser.ts'; import { Events } from '../../util/Constants.ts'; export class UserUpdateAction extends Action { - handle(data: { id: string; data: APIUser }): unknown { + handle(data: { id: string; data: API.User }): unknown { const oldUser = this.client.users.cache.get(data.id); if (oldUser) { diff --git a/src/managers/ChannelManager.ts b/src/managers/ChannelManager.ts index f795a08..b5646dd 100644 --- a/src/managers/ChannelManager.ts +++ b/src/managers/ChannelManager.ts @@ -1,4 +1,4 @@ -import type { Channel as APIChannel } from 'revolt-api-types'; +import type { API } from '../../deps.ts'; import { BaseManager } from './BaseManager.ts'; import { TypeError } from '../errors/mod.ts'; import { @@ -10,12 +10,12 @@ import { VoiceChannel, } from '../structures/mod.ts'; -export type ChannelResolvable = Channel | APIChannel | string; +export type ChannelResolvable = Channel | API.Channel | string; -export class ChannelManager extends BaseManager { +export class ChannelManager extends BaseManager { holds = null; - _add(data: APIChannel): Channel { + _add(data: API.Channel): Channel { let channel: Channel; switch (data.channel_type) { diff --git a/src/managers/MessageManager.ts b/src/managers/MessageManager.ts index e21789d..7bbbe73 100644 --- a/src/managers/MessageManager.ts +++ b/src/managers/MessageManager.ts @@ -1,10 +1,10 @@ -import type { Message as APIMessage } from 'revolt-api-types'; +import type { API } from '../../deps.ts'; import { BaseManager } from './BaseManager.ts'; import { TypeError } from '../errors/mod.ts'; import { Channel, Message } from '../structures/mod.ts'; import { Collection, UUID } from '../util/mod.ts'; -export type MessageResolvable = Message | APIMessage | string; +export type MessageResolvable = Message | API.Message | string; export interface EditMessageOptions { content?: string; @@ -32,7 +32,7 @@ export interface MessageQueryOptions { nearby?: string; } -export class MessageManager extends BaseManager { +export class MessageManager extends BaseManager { holds = Message; constructor(protected readonly channel: Channel) { super(channel.client); @@ -52,7 +52,7 @@ export class MessageManager extends BaseManager { attachments, }, }, - ) as APIMessage; + ) as API.Message; return this._add(data); } @@ -111,7 +111,7 @@ export class MessageManager extends BaseManager { const response = (await this.client.api.post(`/channels/${this.channel.id}/search`, { query: query as Required, - })) as APIMessage[]; + })) as API.Message[]; return response.reduce((coll, cur) => { const msg = this._add(cur); coll.set(msg.id, msg); @@ -130,7 +130,7 @@ export class MessageManager extends BaseManager { if (id) { const data = await this.client.api.get( `/channels/${this.channel.id}/messages/${id}`, - ) as APIMessage; + ) as API.Message; return this._add(data); } @@ -141,7 +141,7 @@ export class MessageManager extends BaseManager { { query: query as Required }, ); - return (messages as APIMessage[]).reduce((coll, cur) => { + return (messages as API.Message[]).reduce((coll, cur) => { const msg = this._add(cur); coll.set(msg.id, msg); return coll; diff --git a/src/managers/RoleManager.ts b/src/managers/RoleManager.ts index 93ffec9..3f9027c 100644 --- a/src/managers/RoleManager.ts +++ b/src/managers/RoleManager.ts @@ -1,17 +1,17 @@ -import type { Role as APIRole } from 'revolt-api-types'; +import type { API } from '../../deps.ts'; import { BaseManager } from './BaseManager.ts'; import { TypeError } from '../errors/mod.ts'; import { Role, Server } from '../structures/mod.ts'; export type RoleResolvable = Role | string; -export class RoleManager extends BaseManager { +export class RoleManager extends BaseManager { holds = Role; constructor(protected readonly server: Server) { super(server.client); } - _add(data: APIRole & { id: string }): Role { + _add(data: API.Role & { id: string }): Role { const role = new Role(this.server, data); this.cache.set(role.id, role); return role; diff --git a/src/managers/ServerChannelManager.ts b/src/managers/ServerChannelManager.ts index 9520ae0..51c72f4 100644 --- a/src/managers/ServerChannelManager.ts +++ b/src/managers/ServerChannelManager.ts @@ -1,4 +1,4 @@ -import type { Channel as APIChannel } from 'revolt-api-types'; +import type { API } from '../../deps.ts'; import { BaseManager } from './BaseManager.ts'; import { TypeError } from '../errors/mod.ts'; import { @@ -10,7 +10,7 @@ import { import { UUID } from '../util/mod.ts'; type APIServerChannel = Extract< - APIChannel, + API.Channel, { channel_type: 'TextChannel' | 'VoiceChannel' } >; @@ -28,7 +28,7 @@ export class ServerChannelManager extends BaseManager { super(server.client); } - _add(data: APIChannel): ServerChannel { + _add(data: API.Channel): ServerChannel { let channel: ServerChannel; switch (data.channel_type) { diff --git a/src/managers/ServerManager.ts b/src/managers/ServerManager.ts index be33d96..bb3868d 100644 --- a/src/managers/ServerManager.ts +++ b/src/managers/ServerManager.ts @@ -1,17 +1,17 @@ -import type { Server as APIServer } from 'revolt-api-types'; +import type { API } from '../../deps.ts'; import { BaseManager } from './BaseManager.ts'; import { TypeError } from '../errors/mod.ts'; import { Server } from '../structures/mod.ts'; import { UUID } from '../util/mod.ts'; -export type ServerResolvable = Server | APIServer | string; +export type ServerResolvable = Server | API.Server | string; export interface EditServerOptions { name?: string; description?: string; } -export class ServerManager extends BaseManager { +export class ServerManager extends BaseManager { readonly holds = Server; _remove(id: string): void { diff --git a/src/managers/ServerMemberManager.ts b/src/managers/ServerMemberManager.ts index 036ec5f..08f90fd 100644 --- a/src/managers/ServerMemberManager.ts +++ b/src/managers/ServerMemberManager.ts @@ -1,10 +1,10 @@ -import type { Member as APIMember } from 'revolt-api-types'; +import type { API } from '../../deps.ts'; import { BaseManager } from './BaseManager.ts'; import { TypeError } from '../errors/mod.ts'; import { Server, ServerMember, User } from '../structures/mod.ts'; import { Collection } from '../util/mod.ts'; -export type ServerMemberResolvable = ServerMember | User | APIMember | string; +export type ServerMemberResolvable = ServerMember | User | API.Member | string; export interface EditServerMemberOptions { nickname?: string; @@ -12,7 +12,7 @@ export interface EditServerMemberOptions { roles?: string[]; } -export class ServerMemberManager extends BaseManager { +export class ServerMemberManager extends BaseManager { holds = ServerMember; constructor(protected readonly server: Server) { super(server.client); diff --git a/src/managers/UserManager.ts b/src/managers/UserManager.ts index b8157f3..a747f30 100644 --- a/src/managers/UserManager.ts +++ b/src/managers/UserManager.ts @@ -1,11 +1,11 @@ -import type { User as APIUser } from 'revolt-api-types'; +import type { API } from '../../deps.ts'; import { BaseManager } from './BaseManager.ts'; import { TypeError } from '../errors/mod.ts'; import { Message, User } from '../structures/mod.ts'; -export type UserResolvable = User | APIUser | Message | string; +export type UserResolvable = User | API.User | Message | string; -export class UserManager extends BaseManager { +export class UserManager extends BaseManager { holds = User; async fetch(user: UserResolvable, { force = true } = {}): Promise { @@ -18,14 +18,14 @@ export class UserManager extends BaseManager { if (user) return user; } - const data = await this.client.api.get(`/users/${id}`) as APIUser; + const data = await this.client.api.get(`/users/${id}`) as API.User; return this._add(data); } resolve(resolvable: Message | User): User; - resolve(resolvable: string | APIUser): User | null; - resolve(resolvable: User | APIUser | string | Message): User | null { + resolve(resolvable: string | API.User): User | null; + resolve(resolvable: User | API.User | string | Message): User | null { if (resolvable instanceof Message) return resolvable.author; return super.resolve(resolvable); } diff --git a/src/structures/Category.ts b/src/structures/Category.ts index ad481d8..85806f5 100644 --- a/src/structures/Category.ts +++ b/src/structures/Category.ts @@ -1,16 +1,16 @@ -import type { Category as APICategory } from 'revolt-api-types'; +import type { API } from '../../deps.ts'; import { Base, Server, ServerChannel } from './mod.ts'; import { Collection } from '../util/mod.ts'; -export class Category extends Base { +export class Category extends Base { name!: string; protected _children: string[] = []; - constructor(public server: Server, data: APICategory) { + constructor(public server: Server, data: API.Category) { super(server.client); this._patch(data); } - protected _patch(data: APICategory): this { + protected _patch(data: API.Category): this { super._patch(data); if (data.title) { diff --git a/src/structures/Channel.ts b/src/structures/Channel.ts index d0be690..3d13850 100644 --- a/src/structures/Channel.ts +++ b/src/structures/Channel.ts @@ -1,4 +1,4 @@ -import type { Channel as APIChannel } from 'revolt-api-types'; +import type { API } from '../../deps.ts'; import { Base, DMChannel, @@ -9,7 +9,7 @@ import { } from './mod.ts'; import { ChannelTypes, UUID } from '../util/mod.ts'; -export abstract class Channel +export abstract class Channel extends Base { type: ChannelTypes | 'UNKNOWN' = 'UNKNOWN'; diff --git a/src/structures/DMChannel.ts b/src/structures/DMChannel.ts index 350d8b0..15dfb1d 100644 --- a/src/structures/DMChannel.ts +++ b/src/structures/DMChannel.ts @@ -1,4 +1,4 @@ -import type { Channel as APIChannel } from 'revolt-api-types'; +import type { API } from '../../deps.ts'; import { Channel, Message } from './mod.ts'; import { TextBasedChannel } from './interfaces/mod.ts'; import { @@ -13,7 +13,7 @@ import { DEFAULT_PERMISSION_DM, } from '../util/mod.ts'; -type APIDirectChannel = Extract; +type APIDirectChannel = Extract; export class DMChannel extends Channel implements TextBasedChannel { diff --git a/src/structures/GroupChannel.ts b/src/structures/GroupChannel.ts index cf26197..b0f42df 100644 --- a/src/structures/GroupChannel.ts +++ b/src/structures/GroupChannel.ts @@ -1,4 +1,4 @@ -import type { Channel as APIChannel } from 'revolt-api-types'; +import type { API } from '../../deps.ts'; import type { Message, User } from './mod.ts'; import type { TextBasedChannel } from './interfaces/mod.ts'; import type { Client } from '../client/Client.ts'; @@ -12,7 +12,7 @@ import { } from '../managers/mod.ts'; import { ChannelPermissions, ChannelTypes, Collection } from '../util/mod.ts'; -type APIGroupChannel = Extract; +type APIGroupChannel = Extract; export class GroupChannel extends Channel implements TextBasedChannel { diff --git a/src/structures/Message.ts b/src/structures/Message.ts index eaf2b30..cf284d2 100644 --- a/src/structures/Message.ts +++ b/src/structures/Message.ts @@ -1,9 +1,4 @@ -import type { - Embed, - File, - Message as APIMessage, - SystemMessage, -} from 'revolt-api-types'; +import type { API } from '../../deps.ts'; import { Base, DMChannel, @@ -17,21 +12,21 @@ import { import { Client } from '../client/Client.ts'; import { UUID } from '../util/mod.ts'; -export class Message extends Base { +export class Message extends Base { content = ''; channelId!: string; authorId!: string; - embeds: Embed[] = []; - attachments: File[] = []; + embeds: API.Embed[] = []; + attachments: API.File[] = []; mentions = new Mentions(this, []); - type: Uppercase = 'TEXT'; + type: Uppercase = 'TEXT'; editedAt: Date | null = null; - constructor(client: Client, data: APIMessage) { + constructor(client: Client, data: API.Message) { super(client); this._patch(data); } - protected _patch(data: APIMessage): this { + protected _patch(data: API.Message): this { super._patch(data); if (Array.isArray(data.embeds)) { @@ -60,7 +55,7 @@ export class Message extends Base { if (data.system) { this.type = data.system.type.toUpperCase() as Uppercase< - SystemMessage['type'] + API.SystemMessage['type'] >; } diff --git a/src/structures/MessageEmbed.ts b/src/structures/MessageEmbed.ts index 0ada877..963a0c0 100644 --- a/src/structures/MessageEmbed.ts +++ b/src/structures/MessageEmbed.ts @@ -1,11 +1,11 @@ -import type { Embed, Special } from 'revolt-api-types'; +import type { API } from '../../deps.ts'; -export type EmbedImage = Extract; -export type EmbedVideo = Extract; -export type EmbedSpecial = Special; +export type EmbedImage = Extract; +export type EmbedVideo = Extract; +export type EmbedSpecial = API.Special; export class MessageEmbed { - type: Embed['type'] = 'Website'; + type: API.Embed['type'] = 'Website'; url?: string; special?: EmbedSpecial; title?: string; @@ -16,7 +16,7 @@ export class MessageEmbed { icon_url?: string; color?: string; - constructor(data: Partial = {}) { + constructor(data: Partial = {}) { Object.assign(this, data); } diff --git a/src/structures/NotesChannel.ts b/src/structures/NotesChannel.ts index 4020ba9..81beb1d 100644 --- a/src/structures/NotesChannel.ts +++ b/src/structures/NotesChannel.ts @@ -1,4 +1,4 @@ -import type { Channel as APIChannel } from 'revolt-api-types'; +import type { API } from '../../deps.ts'; import { Channel, Message, User } from './mod.ts'; import { TextBasedChannel } from './interfaces/mod.ts'; import { Client } from '../client/Client.ts'; @@ -9,7 +9,7 @@ import { } from '../managers/mod.ts'; import { ChannelTypes, Collection } from '../util/mod.ts'; -type APINotesChannel = Extract; +type APINotesChannel = Extract; export class NotesChannel extends Channel implements TextBasedChannel { diff --git a/src/structures/Role.ts b/src/structures/Role.ts index 03d4448..6ce998a 100644 --- a/src/structures/Role.ts +++ b/src/structures/Role.ts @@ -1,4 +1,4 @@ -import type { Role as APIRole } from 'revolt-api-types'; +import type { API } from '../../deps.ts'; import { Base, Overwrite, Server } from './mod.ts'; import { ChannelPermissions, UUID } from '../util/mod.ts'; @@ -8,12 +8,12 @@ export class Role extends Base { hoist = false; rank!: number; overwrite!: Overwrite; - constructor(public server: Server, data: APIRole & { id: string }) { + constructor(public server: Server, data: API.Role & { id: string }) { super(server.client); this._patch(data); } - protected _patch(data: APIRole & { _id?: string }): this { + protected _patch(data: API.Role & { _id?: string }): this { super._patch(data); if (data.name) this.name = data.name; diff --git a/src/structures/Server.ts b/src/structures/Server.ts index f0142b6..5f4fc06 100644 --- a/src/structures/Server.ts +++ b/src/structures/Server.ts @@ -1,4 +1,4 @@ -import type { Server as APIServer } from 'revolt-api-types'; +import type { API } from '../../deps.ts'; import { Base, Category, ServerMember, User } from './mod.ts'; import { Client } from '../client/Client.ts'; import { @@ -8,7 +8,7 @@ import { } from '../managers/mod.ts'; import { Collection, ServerPermissions, UUID } from '../util/mod.ts'; -export class Server extends Base { +export class Server extends Base { name!: string; description: string | null = null; ownerId!: string; @@ -23,12 +23,12 @@ export class Server extends Base { permissions!: ServerPermissions; categories = new Collection(); - constructor(client: Client, data: APIServer) { + constructor(client: Client, data: API.Server) { super(client); this._patch(data); } - protected _patch(data: APIServer): this { + protected _patch(data: API.Server): this { super._patch(data); if (Array.isArray(data.categories)) { diff --git a/src/structures/ServerChannel.ts b/src/structures/ServerChannel.ts index fc5d483..160175c 100644 --- a/src/structures/ServerChannel.ts +++ b/src/structures/ServerChannel.ts @@ -1,10 +1,10 @@ -import type { Channel as APIChannel } from 'revolt-api-types'; +import type { API } from '../../deps.ts'; import { Category, Channel, Server } from './mod.ts'; import { Client } from '../client/Client.ts'; import { ChannelPermissions, Collection } from '../util/mod.ts'; type APIServerChannel = Extract< - APIChannel, + API.Channel, { channel_type: 'TextChannel' | 'VoiceChannel' } >; diff --git a/src/structures/ServerMember.ts b/src/structures/ServerMember.ts index d2e9759..4fabe48 100644 --- a/src/structures/ServerMember.ts +++ b/src/structures/ServerMember.ts @@ -1,17 +1,17 @@ -import type { File, Member as APIMember } from 'revolt-api-types'; +import type { API } from '../../deps.ts'; import { Base, Server, User } from './mod.ts'; import { Client } from '../client/Client.ts'; -export class ServerMember extends Base { +export class ServerMember extends Base { serverId!: string; nickname: string | null = null; - avatar: File | null = null; - constructor(client: Client, data: APIMember) { + avatar: API.File | null = null; + constructor(client: Client, data: API.Member) { super(client); this._patch(data); } - protected _patch(data: APIMember): this { + protected _patch(data: API.Member): this { super._patch(data); if ('nickname' in data) { diff --git a/src/structures/TextChannel.ts b/src/structures/TextChannel.ts index 3218b83..5890e5b 100644 --- a/src/structures/TextChannel.ts +++ b/src/structures/TextChannel.ts @@ -1,4 +1,4 @@ -import type { Channel as APIChannel } from 'revolt-api-types'; +import type { API } from '../../deps.ts'; import { Message, ServerChannel } from './mod.ts'; import { TextBasedChannel } from './interfaces/mod.ts'; import { Client } from '../client/Client.ts'; @@ -9,7 +9,7 @@ import { } from '../managers/mod.ts'; import { ChannelTypes, Collection } from '../util/mod.ts'; -type APITextChannel = Extract; +type APITextChannel = Extract; export class TextChannel extends ServerChannel implements TextBasedChannel { diff --git a/src/structures/User.ts b/src/structures/User.ts index e3652f6..d7cd7f6 100644 --- a/src/structures/User.ts +++ b/src/structures/User.ts @@ -1,15 +1,11 @@ -import type { - File, - Presence as APIPresence, - User as APIUser, -} from 'revolt-api-types'; +import type { API } from '../../deps.ts'; import { Base, DMChannel } from './mod.ts'; import { Client } from '../client/Client.ts'; import { Badges, Presence, UUID } from '../util/mod.ts'; -export class User extends Base { +export class User extends Base { username!: string; - avatar: File | null = null; + avatar: API.File | null = null; status = { text: null, presence: Presence.INVISIBLE, @@ -20,12 +16,12 @@ export class User extends Base { badges!: Badges; bot = false; - constructor(client: Client, data: APIUser) { + constructor(client: Client, data: API.User) { super(client); this._patch(data); } - protected _patch(data: APIUser): this { + protected _patch(data: API.User): this { super._patch(data); if (data.username) { @@ -46,7 +42,9 @@ export class User extends Base { if ('status' in data) { const presence = data.status?.presence - ? Presence[data.status.presence.toUpperCase() as Uppercase] + ? Presence[ + data.status.presence.toUpperCase() as Uppercase + ] : Presence.INVISIBLE; this.status.presence = presence; this.status.text = data.status?.text ?? null; diff --git a/src/structures/VoiceChannel.ts b/src/structures/VoiceChannel.ts index a42aaa3..313d38b 100644 --- a/src/structures/VoiceChannel.ts +++ b/src/structures/VoiceChannel.ts @@ -1,9 +1,9 @@ -import type { Channel as APIChannel } from 'revolt-api-types'; +import type { API } from '../../deps.ts'; import { ServerChannel } from './mod.ts'; import { Client } from '../lib.ts'; import { ChannelTypes } from '../util/mod.ts'; -type APIVoiceChannel = Extract; +type APIVoiceChannel = Extract; export class VoiceChannel extends ServerChannel { readonly type = ChannelTypes.VOICE; diff --git a/src/util/Collection.ts b/src/util/Collection.ts index 864ea77..ab6749c 100644 --- a/src/util/Collection.ts +++ b/src/util/Collection.ts @@ -1 +1 @@ -export { Collection } from 'https://esm.sh/@discordjs/collection@0.6.0'; +export { Collection } from '../../deps.ts'; diff --git a/src/util/UUID.ts b/src/util/UUID.ts index f550592..c787370 100644 --- a/src/util/UUID.ts +++ b/src/util/UUID.ts @@ -1,4 +1,4 @@ -import { randomBytes } from 'crypto'; +import { randomBytes } from '../../deps.ts'; export class UUID extends null { static readonly ENCODING = '0123456789ABCDEFGHJKMNPQRSTVWXYZ';