import { definePlugin } from 'kivibot' import type { oicq, AllMessageEvent } from 'kivibot' interface Word { keyword: string | RegExp | (string | RegExp)[] | ((event: AllMessageEvent) => boolean) reply: oicq.Sendable | oicq.Sendable[] | ((event: AllMessageEvent) => oicq.Sendable | Promise) groupOnly?: boolean adminOnly?: boolean } // 忽略的 QQ 号列表 const ignoreUinList: number[] = [] // 开启的群列表 const enableGroupList: number[] = [] const wordList: Word[] = [ { keyword: ['早', '早安', '早啊', '早上好', '早上好啊', '早安啊'], reply: ['早什么早'], }, ] export default definePlugin({ name: 'keyword', version: '1.0.0', setup(ctx) { ctx.handle('message', async (event) => { if (ignoreUinList.includes(event.sender.user_id)) return if (ctx.isGroupMsg(event) && !enableGroupList.includes(event.group_id)) return for (const word of wordList) { const keywords = ctx.ensureArray(word.keyword) for (const keyword of keywords) { let matched = false if (ctx.isString(keyword)) { if (event.raw_message.includes(keyword)) { if (word.adminOnly && !ctx.isAdmin(event)) { return } if (word.groupOnly && !ctx.isGroupMsg(event)) { return } matched = true } } if (keyword instanceof RegExp) { if (keyword.test(event.raw_message)) { if (word.adminOnly && !ctx.isAdmin(event)) { return } if (word.groupOnly && !ctx.isGroupMsg(event)) { return } matched = true return } } if (ctx.isFunction(keyword)) { if (keyword(event)) { if (word.adminOnly && !ctx.isAdmin(event)) { return } if (word.groupOnly && !ctx.isGroupMsg(event)) { return } matched = true return } } if (matched) { const replyContent = ctx.isFunction(word.reply) ? await word.reply(event) : ctx.randomItem(ctx.ensureArray(word.reply)) event.reply(replyContent) } } } }) }, })