init
This commit is contained in:
commit
440f572834
53 files changed
+12776
No files matched your search
@@ -0,0 +1,43 @@
|
||||
import { BotStore } from '../db/bot-store';
|
||||
import {
|
||||
CronSpec,
|
||||
InboundMessage,
|
||||
MemberEvent,
|
||||
ParsedCommand,
|
||||
} from '../command/types';
|
||||
|
||||
/**
|
||||
* 注入给每个 bot 的运行时上下文:出站能力 + 已隔离的存储。
|
||||
* bot 永远不直接碰 matrix client,便于单测(mock 本接口即可)。
|
||||
*/
|
||||
export interface BotContext {
|
||||
readonly account: string;
|
||||
send(roomId: string, text: string, replyToEventId?: string): Promise<string>;
|
||||
reply(msg: InboundMessage, text: string): Promise<string>;
|
||||
kick(roomId: string, userId: string, reason?: string): Promise<void>;
|
||||
getMemberCount(roomId: string): Promise<number>;
|
||||
getJoinedMembers(roomId: string): Promise<string[]>;
|
||||
/** 读取用户在房间内的 power level,用于按房间权限判断管理员(读不到返回 0)。 */
|
||||
getPowerLevel(roomId: string, userId: string): Promise<number>;
|
||||
readonly db: BotStore;
|
||||
}
|
||||
|
||||
/**
|
||||
* 每个房间机器人实现的契约。一个 bot = 一个独立功能模块。
|
||||
* 所有钩子均可选,bot 只实现自己关心的事件。
|
||||
*/
|
||||
export interface RoomBot {
|
||||
/** 唯一名字,同时作为 DB scope。 */
|
||||
readonly name: string;
|
||||
/** 使用哪个账号(对应 config.accounts 的 key)。 */
|
||||
readonly account: string;
|
||||
/** 管理哪些房间。 */
|
||||
readonly rooms: string[];
|
||||
|
||||
/** 平台完成所有会话登录后调用一次,适合发送上线通知、做初始化等。 */
|
||||
onReady?(ctx: BotContext): Promise<void>;
|
||||
onMessage?(msg: InboundMessage, ctx: BotContext): Promise<void>;
|
||||
onCommand?(cmd: ParsedCommand, ctx: BotContext): Promise<void>;
|
||||
onMemberJoin?(ev: MemberEvent, ctx: BotContext): Promise<void>;
|
||||
registerCrons?(ctx: BotContext): CronSpec[];
|
||||
}
|
||||
Reference in new issue
Block a user