import { BotStore } from '../db/bot-store'; import { CronSpec, InboundMessage, MemberEvent, ParsedCommand, PowerLevelEvent, } from '../command/types'; /** * 注入给每个 bot 的运行时上下文:出站能力 + 已隔离的存储。 * bot 永远不直接碰 matrix client,便于单测(mock 本接口即可)。 */ export interface BotContext { readonly account: string; send(roomId: string, text: string, replyToEventId?: string): Promise; reply(msg: InboundMessage, text: string): Promise; kick(roomId: string, userId: string, reason?: string): Promise; invite(roomId: string, userId: string): Promise; getMemberCount(roomId: string): Promise; getJoinedMembers(roomId: string): Promise; /** 读取用户在房间内的 power level,用于按房间权限判断管理员(读不到返回 0)。 */ getPowerLevel(roomId: string, userId: string): Promise; 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; onMessage?(msg: InboundMessage, ctx: BotContext): Promise; onCommand?(cmd: ParsedCommand, ctx: BotContext): Promise; onMemberJoin?(ev: MemberEvent, ctx: BotContext): Promise; onMemberLeave?(ev: MemberEvent, ctx: BotContext): Promise; onPowerLevel?(ev: PowerLevelEvent, ctx: BotContext): Promise; registerCrons?(ctx: BotContext): CronSpec[]; }