UNPKG

@twiyin0/koishi-plugin-randomreply

Version:

Random reply your message

50 lines (49 loc) 2.66 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.apply = exports.schema = exports.Rule = exports.usage = exports.name = void 0; const jsx_runtime_1 = require("@satorijs/element/jsx-runtime"); const koishi_1 = require("koishi"); exports.name = 'randomreply'; exports.usage = ` ## 使用说明 <at#> @触发者 <quote#> 回复/引用触发者的消息 &lt;image url="xxxxx"/&gt; 句尾后加一张图片xxxx是图片的地址 <recall#> 撤回消息(需要群聊管理员权限) 示例: <at#>你好啊&lt;image url="https://example.com/a.png"/&gt; image和url间必须有空格 别的好像没什么好说的 url记得加http(s),如果是本地图片请用file:///(绝对路径eg: file:///path/to/image.jpg) 目前仅支持一张图片,能力有限对不住啦 项目参考:[@koishijs/respondent](https://github.com/koishijs/koishi-plugin-respondent) `; exports.Rule = koishi_1.Schema.object({ express: koishi_1.Schema.boolean().description('match启用正则表达式?').default(false), match: koishi_1.Schema.string().description('要匹配的输入。').required(), reply: koishi_1.Schema.array(String).description('要发送的内容数组').required() }); exports.schema = koishi_1.Schema.object({ rules: koishi_1.Schema.array(exports.Rule) .description('条件匹配并随机回复'), }); function apply(ctx, cfg) { ctx.on('message', async (session) => { for (const rule of cfg.rules) { let express = null; express = rule.express ? eval(rule.match) : null; if (express ? session.content.match(express) : session.content.includes(rule.match)) { var getstr = koishi_1.Random.pick(rule.reply); let hasquote = getstr.match(/<quote#>/gi) ? (0, jsx_runtime_1.jsx)("quote", { id: session.messageId }) : null; let hasat = getstr.match(/<at#>/gi) ? (0, jsx_runtime_1.jsx)("at", { id: session.userId }) : null; var imgmatch = getstr.match(/<image url=(.*)\/>/gi)[0]; let hasimg = imgmatch ? koishi_1.h.unescape(imgmatch) : null; if (getstr.match(/<recall#>/gi) && session.subtype !== 'private') await session.bot.deleteMessage(session.channelId, session.messageId); getstr = getstr.replace(/<quote#>/gi, '').replace(/<at#>/gi, '').replace(/<recall#>/gi, '').replace((/<image url=(.*)\/>/gi), ''); session.send((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [hasquote, hasat, getstr] }) + hasimg); } } }); } exports.apply = apply;