diff --git a/packages/core/src/adapter.ts b/packages/core/src/adapter.ts index 520cdd22..0bd68d07 100644 --- a/packages/core/src/adapter.ts +++ b/packages/core/src/adapter.ts @@ -1,6 +1,5 @@ import { Awaitable, remove, Time } from 'cosmokit' -import { Status } from '@satorijs/protocol' -import { WebSocket } from 'undios' +import { Status, WebSocket } from '@satorijs/protocol' import { z } from 'cordis' import { Context } from '.' import { Bot } from './bot' diff --git a/packages/element/src/index.ts b/packages/element/src/index.ts index 3ae36ba1..d9d5f0e1 100644 --- a/packages/element/src/index.ts +++ b/packages/element/src/index.ts @@ -7,11 +7,13 @@ declare global { message: { id?: string forward?: boolean + children?: any[] } quote: { id?: string name?: string avatar?: string + children?: any[] } at: { id?: string diff --git a/packages/protocol/src/index.ts b/packages/protocol/src/index.ts index 2948538a..59c7991d 100644 --- a/packages/protocol/src/index.ts +++ b/packages/protocol/src/index.ts @@ -333,3 +333,60 @@ export interface GatewayBody { logins: Login[] } } + +export namespace WebSocket { + /** The connection is not yet open. */ + export const CONNECTING = 0 + /** The connection is open and ready to communicate. */ + export const OPEN = 1 + /** The connection is in the process of closing. */ + export const CLOSING = 2 + /** The connection is closed. */ + export const CLOSED = 3 + + export type ReadyState = + | typeof CONNECTING + | typeof OPEN + | typeof CLOSING + | typeof CLOSED + + export interface EventMap { + open: Event + error: ErrorEvent + message: MessageEvent + close: CloseEvent + } + + export interface EventListener { + (event: Event): void + } + + export interface Event { + type: string + target: WebSocket + } + + export interface CloseEvent extends Event { + code: number + reason: string + } + + export interface MessageEvent extends Event { + data: string + } + + export interface ErrorEvent extends Event { + message?: string + } +} + +export interface WebSocket { + readonly url?: string + readonly protocol?: string + readonly readyState?: number + close(code?: number, reason?: string): void + send(data: string): void + dispatchEvent?(event: any): boolean + addEventListener(type: K, listener: (event: WebSocket.EventMap[K]) => void): void + removeEventListener(type: K, listener: (event: WebSocket.EventMap[K]) => void): void +}