@satorijs/core
Advanced tools
Comparing version 1.0.0 to 1.0.1
import * as cordis from 'cordis'; | ||
import { Awaitable, Dict } from 'cosmokit'; | ||
import segment from '@satorijs/message'; | ||
export interface Methods { | ||
@@ -90,2 +91,3 @@ sendMessage(channelId: string, content: string, guildId?: string): Promise<string[]>; | ||
} | ||
type EventCallback<C extends Context = Context, T = void> = (this: C[typeof Context.session], session: C[typeof Context.session]) => T; | ||
} | ||
@@ -103,3 +105,3 @@ export class Session<C extends Context = Context> { | ||
} | ||
export interface Bot extends Bot.Config, Methods, User { | ||
export interface Bot extends Methods, User { | ||
} | ||
@@ -112,5 +114,4 @@ export abstract class Bot<C extends Context = Context, T extends Bot.Config = Bot.Config> { | ||
platform: string; | ||
hidden?: boolean; | ||
selfId: string; | ||
internal?: any; | ||
selfId?: string; | ||
adapter?: Adapter<this>; | ||
@@ -134,31 +135,64 @@ error?: Error; | ||
platform?: string; | ||
selfId?: string; | ||
} | ||
type Status = 'offline' | 'online' | 'connect' | 'disconnect' | 'reconnect'; | ||
} | ||
export type Filter<C extends Context = Context> = (session: C[typeof Context.session]) => boolean; | ||
export interface Context { | ||
filter: Filter<this>; | ||
any(): this; | ||
never(): this; | ||
union(arg: Filter<this> | this): this; | ||
intersect(arg: Filter<this> | this): this; | ||
exclude(arg: Filter<this> | this): this; | ||
user(...values: string[]): this; | ||
self(...values: string[]): this; | ||
guild(...values: string[]): this; | ||
channel(...values: string[]): this; | ||
platform(...values: string[]): this; | ||
private(...values: string[]): this; | ||
} | ||
export class Selector<C extends Context = Context> { | ||
private app; | ||
static readonly methods: string[]; | ||
constructor(app: C); | ||
protected get caller(): Context; | ||
any(): Context; | ||
never(): Context; | ||
union(arg: Filter | C): Context; | ||
intersect(arg: Filter | C): Context; | ||
exclude(arg: Filter | C): Context; | ||
user(...values: string[]): Context; | ||
self(...values: string[]): Context; | ||
guild(...values: string[]): Context; | ||
channel(...values: string[]): Context; | ||
platform(...values: string[]): Context; | ||
private(...values: string[]): Context; | ||
} | ||
export { segment, segment as h }; | ||
type Genres = 'friend' | 'channel' | 'guild' | 'guild-member' | 'guild-role' | 'guild-file' | 'guild-emoji'; | ||
type Actions = 'added' | 'deleted' | 'updated'; | ||
type SessionEventCallback<C extends Context = Context, T = void> = (this: C[typeof Context.session], session: C[typeof Context.session]) => T; | ||
export interface Events<C extends Context = Context> extends cordis.Events<C>, Record<`${Genres}-${Actions}`, SessionEventCallback<C>> { | ||
'message': SessionEventCallback<C>; | ||
'message-deleted': SessionEventCallback<C>; | ||
'message-updated': SessionEventCallback<C>; | ||
'reaction-added': SessionEventCallback<C>; | ||
'reaction-deleted': SessionEventCallback<C>; | ||
'reaction-deleted/one': SessionEventCallback<C>; | ||
'reaction-deleted/all': SessionEventCallback<C>; | ||
'reaction-deleted/emoji': SessionEventCallback<C>; | ||
'send': SessionEventCallback<C>; | ||
'friend-request': SessionEventCallback<C>; | ||
'guild-request': SessionEventCallback<C>; | ||
'guild-member-request': SessionEventCallback<C>; | ||
'guild-member/role': SessionEventCallback<C>; | ||
'guild-member/ban': SessionEventCallback<C>; | ||
'guild-member/nickname': SessionEventCallback<C>; | ||
'notice/poke': SessionEventCallback<C>; | ||
'notice/lucky-king': SessionEventCallback<C>; | ||
'notice/honor': SessionEventCallback<C>; | ||
'notice/honor/talkative': SessionEventCallback<C>; | ||
'notice/honor/performer': SessionEventCallback<C>; | ||
'notice/honor/emotion': SessionEventCallback<C>; | ||
'before-send': SessionEventCallback<C, boolean>; | ||
export interface Events<C extends Context = Context> extends cordis.Events<C>, Record<`${Genres}-${Actions}`, Session.EventCallback<C>> { | ||
'message': Session.EventCallback<C>; | ||
'message-deleted': Session.EventCallback<C>; | ||
'message-updated': Session.EventCallback<C>; | ||
'reaction-added': Session.EventCallback<C>; | ||
'reaction-deleted': Session.EventCallback<C>; | ||
'reaction-deleted/one': Session.EventCallback<C>; | ||
'reaction-deleted/all': Session.EventCallback<C>; | ||
'reaction-deleted/emoji': Session.EventCallback<C>; | ||
'send': Session.EventCallback<C>; | ||
'friend-request': Session.EventCallback<C>; | ||
'guild-request': Session.EventCallback<C>; | ||
'guild-member-request': Session.EventCallback<C>; | ||
'guild-member/role': Session.EventCallback<C>; | ||
'guild-member/ban': Session.EventCallback<C>; | ||
'guild-member/nickname': Session.EventCallback<C>; | ||
'notice/poke': Session.EventCallback<C>; | ||
'notice/lucky-king': Session.EventCallback<C>; | ||
'notice/honor': Session.EventCallback<C>; | ||
'notice/honor/talkative': Session.EventCallback<C>; | ||
'notice/honor/performer': Session.EventCallback<C>; | ||
'notice/honor/emotion': Session.EventCallback<C>; | ||
'before-send': Session.EventCallback<C, void | boolean>; | ||
'bot-added'(client: Bot<C>): void; | ||
@@ -171,4 +205,5 @@ 'bot-removed'(client: Bot<C>): void; | ||
export interface Context { | ||
[Context.events]: Events<Context>; | ||
[Context.events]: Events<this>; | ||
[Context.session]: Session<Context>; | ||
options: Context.Config; | ||
bots: Bot<this>[] & Dict<Bot<this>> & { | ||
@@ -178,4 +213,5 @@ counter: number; | ||
} | ||
export class Context<T extends Context.Config = Context.Config> extends cordis.Context<T> { | ||
export class Context extends cordis.Context { | ||
static readonly session: unique symbol; | ||
constructor(options?: Context.Config); | ||
} | ||
@@ -187,3 +223,3 @@ export namespace Context { | ||
export abstract class Adapter<T extends Bot = Bot> { | ||
static reusable: boolean; | ||
static schema: boolean; | ||
start(bot: T): Promise<void>; | ||
@@ -196,8 +232,9 @@ stop(bot: T): Promise<void>; | ||
protected bot: T; | ||
static reusable: boolean; | ||
constructor(ctx: Context, bot: T); | ||
} | ||
abstract class Server<T extends Bot = Bot> extends Adapter<T> { | ||
protected bots: T[]; | ||
bots: T[]; | ||
fork(ctx: Context, bot: T): void; | ||
} | ||
} |
{ | ||
"name": "@satorijs/core", | ||
"description": "Core components of Satorijs", | ||
"version": "1.0.0", | ||
"main": "lib/index.js", | ||
"version": "1.0.1", | ||
"main": "lib/index.cjs", | ||
"module": "lib/index.mjs", | ||
"typings": "lib/index.d.ts", | ||
"files": [ | ||
"lib", | ||
"index.js" | ||
"lib" | ||
], | ||
@@ -34,4 +34,6 @@ "author": "Shigma <shigma10826@gmail.com>", | ||
"dependencies": { | ||
"cordis": "^2.0.3" | ||
"@satorijs/message": "^1.0.1", | ||
"cordis": "^2.0.4", | ||
"cosmokit": "^1.2.1" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
46392
3
6
568
1
4
+ Added@satorijs/message@^1.0.1
+ Addedcosmokit@^1.2.1
+ Added@satorijs/message@1.0.1(transitive)
Updatedcordis@^2.0.4