From cae2070ed8a2ac4f0650704bf32b1f2fcb17ba54 Mon Sep 17 00:00:00 2001 From: Shigma Date: Mon, 11 Sep 2023 15:42:49 +0800 Subject: [PATCH] feat(satori): update protocol structure --- packages/core/src/bot.ts | 2 +- packages/core/src/index.ts | 2 +- .../core/src/{universal.ts => protocol.ts} | 46 +++++++++++-------- packages/core/src/session.ts | 3 +- 4 files changed, 30 insertions(+), 23 deletions(-) rename packages/core/src/{universal.ts => protocol.ts} (91%) diff --git a/packages/core/src/bot.ts b/packages/core/src/bot.ts index 06b64f35..2f036884 100644 --- a/packages/core/src/bot.ts +++ b/packages/core/src/bot.ts @@ -3,7 +3,7 @@ import { Context, Fragment } from '.' import { Adapter } from './adapter' import { MessageEncoder } from './message' import { SendOptions, Session } from './session' -import { Universal } from './universal' +import { Universal } from './protocol' import WebSocket from 'ws' export interface Bot extends Universal.Methods, Universal.User { diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 60801899..0614e0a8 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -21,7 +21,7 @@ export * from './adapter' export * from './internal' export * from './message' export * from './session' -export * from './universal' +export * from './protocol' declare global { namespace Satori { diff --git a/packages/core/src/universal.ts b/packages/core/src/protocol.ts similarity index 91% rename from packages/core/src/universal.ts rename to packages/core/src/protocol.ts index 48623ae1..5153a97b 100644 --- a/packages/core/src/universal.ts +++ b/packages/core/src/protocol.ts @@ -2,6 +2,8 @@ import Element from '@satorijs/element' import { SendOptions } from './session' import { Dict } from 'cosmokit' +export { Universal as Satori } + export namespace Universal { export interface Method { name: string @@ -84,10 +86,10 @@ export namespace Universal { // role setGuildMemberRole(guildId: string, userId: string, roleId: string): Promise unsetGuildMemberRole(guildId: string, userId: string, roleId: string): Promise - getGuildRoleList(guildId: string, next?: string): Promise> - getGuildRoleIter(guildId: string): AsyncIterable - createGuildRole(guildId: string, data: Partial): Promise - modifyGuildRole(guildId: string, roleId: string, data: Partial): Promise + getGuildRoleList(guildId: string, next?: string): Promise> + getGuildRoleIter(guildId: string): AsyncIterable + createGuildRole(guildId: string, data: Partial): Promise + modifyGuildRole(guildId: string, roleId: string, data: Partial): Promise deleteGuildRole(guildId: string, roleId: string): Promise // channel @@ -124,7 +126,7 @@ export namespace Universal { guildName?: string } - export interface Role { + export interface GuildRole { id: string name: string color: number @@ -134,29 +136,28 @@ export namespace Universal { mentionable: boolean } - export interface UserBase { + export interface User { + id: string + name: string + /** @deprecated */ + userId: string + /** @deprecated */ username?: string - nickname?: string avatar?: string discriminator?: string isBot?: boolean } - export interface User extends UserBase { - userId: string - } - - export interface GuildMember extends User { + export interface GuildMember { + user: User + nickname?: string + avatar?: string roles?: string[] - } - - export interface Author extends GuildMember { anonymous?: string } - export interface Role { - id: string - } + /** @deprecated */ + export type Author = Partial & User> export interface Message { messageId?: string @@ -166,7 +167,8 @@ export namespace Universal { content?: string elements?: Element[] timestamp?: number - author?: Author + author?: User + member?: Partial quote?: Message isDirect?: boolean /** @deprecated please use `isDirect` instead */ @@ -205,7 +207,11 @@ export namespace Universal { } export interface EventData { - role?: Role + role?: GuildRole argv?: Argv + channel?: Channel + guild?: Guild + member?: GuildMember + user?: User } } diff --git a/packages/core/src/session.ts b/packages/core/src/session.ts index b0b03126..d706c56f 100644 --- a/packages/core/src/session.ts +++ b/packages/core/src/session.ts @@ -1,7 +1,7 @@ import { defineProperty, isNullable } from 'cosmokit' import { Context } from '.' import { Bot } from './bot' -import { Universal } from './universal' +import { Universal } from './protocol' import Element from '@satorijs/element' export interface SendOptions { @@ -29,6 +29,7 @@ export namespace Session { elements?: Element[] timestamp?: number author?: Universal.Author + member?: Universal.GuildMember quote?: Universal.Message channelName?: string guildName?: string