1. Added RoomManagerBot for cross-room permission and leave syncing based on native power levels. 3. Added invite() to MatrixSession and added onMemberLeave/onPowerLevel hooks to Dispatcher. 4. Updated README and example configs.
48 lines
1.9 KiB
TypeScript
48 lines
1.9 KiB
TypeScript
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<string>;
|
|
reply(msg: InboundMessage, text: string): Promise<string>;
|
|
kick(roomId: string, userId: string, reason?: string): Promise<void>;
|
|
invite(roomId: string, userId: 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>;
|
|
onMemberLeave?(ev: MemberEvent, ctx: BotContext): Promise<void>;
|
|
onPowerLevel?(ev: PowerLevelEvent, ctx: BotContext): Promise<void>;
|
|
registerCrons?(ctx: BotContext): CronSpec[];
|
|
}
|