Skip to content

Commit

Permalink
feat(satori): update protocol structure
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Sep 11, 2023
1 parent ef9db03 commit cae2070
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 23 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
46 changes: 26 additions & 20 deletions packages/core/src/universal.ts → packages/core/src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -84,10 +86,10 @@ export namespace Universal {
// role
setGuildMemberRole(guildId: string, userId: string, roleId: string): Promise<void>
unsetGuildMemberRole(guildId: string, userId: string, roleId: string): Promise<void>
getGuildRoleList(guildId: string, next?: string): Promise<List<Role>>
getGuildRoleIter(guildId: string): AsyncIterable<Role>
createGuildRole(guildId: string, data: Partial<Role>): Promise<string>
modifyGuildRole(guildId: string, roleId: string, data: Partial<Role>): Promise<void>
getGuildRoleList(guildId: string, next?: string): Promise<List<GuildRole>>
getGuildRoleIter(guildId: string): AsyncIterable<GuildRole>
createGuildRole(guildId: string, data: Partial<GuildRole>): Promise<string>
modifyGuildRole(guildId: string, roleId: string, data: Partial<GuildRole>): Promise<void>
deleteGuildRole(guildId: string, roleId: string): Promise<void>

// channel
Expand Down Expand Up @@ -124,7 +126,7 @@ export namespace Universal {
guildName?: string
}

export interface Role {
export interface GuildRole {
id: string
name: string
color: number
Expand All @@ -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<Omit<GuildMember, 'user'> & User>

export interface Message {
messageId?: string
Expand All @@ -166,7 +167,8 @@ export namespace Universal {
content?: string
elements?: Element[]
timestamp?: number
author?: Author
author?: User
member?: Partial<GuildMember>
quote?: Message
isDirect?: boolean
/** @deprecated please use `isDirect` instead */
Expand Down Expand Up @@ -205,7 +207,11 @@ export namespace Universal {
}

export interface EventData {
role?: Role
role?: GuildRole
argv?: Argv
channel?: Channel
guild?: Guild
member?: GuildMember
user?: User
}
}
3 changes: 2 additions & 1 deletion packages/core/src/session.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -29,6 +29,7 @@ export namespace Session {
elements?: Element[]
timestamp?: number
author?: Universal.Author
member?: Universal.GuildMember
quote?: Universal.Message
channelName?: string
guildName?: string
Expand Down

0 comments on commit cae2070

Please sign in to comment.