el-bot
Version:
A quick qq bot framework for mirai.
34 lines (31 loc) • 750 B
text/typescript
import type { Bot } from 'el-bot'
import type * as Config from '../../types/config'
import { renderString } from '../../utils'
interface ReportOptions {
/**
* 报告事件类型
*/
type: string
/**
* 报告对象
*/
target: Config.Target
/**
* 报告消息模版
*/
content: string
}
export default function (ctx: Bot, options: ReportOptions[] = []) {
if (!ctx.webhook) {
ctx.logger.error('[report] 您须先开启 webhook')
return
}
options.forEach((option) => {
ctx.webhook?.on(option.type, (data: any) => {
ctx.logger.debug(data)
const text = renderString(option.content, data, 'data')
if (option.target)
ctx.sender.sendMessageByConfig(text, option.target)
})
})
}