为你机器人部分或全部服务加入一个用户协议来限制用户行为,idea来源: 求插件:用户许可协议 (eula)
感谢实现了「求插件」板块中的需求!
大家有任何想要的插件,也欢迎来「求插件」板块发帖哦~
迟到的更新记录,顺便顶顶
1.0.4 更新记录
- 注册了 Eula 服务,其他插件开发者可以通过
ctx.eula
来获得 eula 支持了 - (breaking) 更改了认证方式,这是一个破坏性更新,但是提供了一个修复命令,通过私聊机器人并发送
eulafix --revise
来修复(请先确保自身权限至少为 5)
写给开发者:如何使用 eula 能力?
首先需要添加 eula 开发模式依赖:
# yarn:
yarn add koishi-plugin-eula -d
# or use npm
npm i koishi-plugin-eula -d
并且可以在 package.json
中加入如下 koishi 字段来声明 eula 依赖:
//package.json
...
"koishi": {
...,
"service": {
"required": [..., "eula"]
},
...
},
...
然后,在您的插件中引入类型依赖来获得类型提示
以及添加 using 引用来让 koishi 正确的加载插件顺序:
import {} from 'koishi-plugin-eula'
export const using = ['eula', ...]
最后,在您的插件中通过 eula/update
事件来获得 eula 状态,并根据状态自行调整:
ctx.on('eula/update', (session: Session, eula: boolean) => {
//more core
})
经过如上方式便可在您的插件中使用 eula 流程,或者基于 eula 的认证能力扩展出更多的玩法。
API
服务:eula
ctx.eula.vertify()
一般情况下,更推荐使用
eula/update
事件来获得认证状态,这将得到完整 Session 支持
验证该用户是否同意 eula
- userId:
number
用户 id,即 session.user.id
扩展事件
事件:eula/before
命令触发 eula 流程前发生该事件
事件:eula/update
当用户回复 eula 后触发,这将传入一个 eula: boolean 来告知用户同意与否
为什么我用过这个时候提示未知错误
1.1.0 更新记录
- 修复了在使用
eula
命令时提示未知错误的错误 (@lalala121 ) - 协议文本被移动至
本地化 - eula.eulaMessage.text
,现在可以支持多语言协议文本了 - 加入了英文翻译
- 加入了协议生效的最高用户等级配置,这样可以跳过高权限用户了
- 加入了可以配置需要限制的指令列表功能
- 白名单:仅对列表中的命令生效
- 黑名单:对列表中之外的命令生效
- 移除了
0.x
升级提示 - 移除了
eulafix
指令
以下为重启后在频道使用的报错:1000|2|等待数据库实例
1000|2|2023-07-08 19:42:14 [I] locales loading locale en.yml
1000|2|2023-07-08 19:42:15 [I] blockly No plugin loaded
1000|2|2023-07-08 19:42:16 [S] KBot KBot 内置插件加载完毕
1000|2|2023-07-08 19:42:16 [I] locales loading locale zh.yml
1000|2| at Context.set (C:\Users\Dnyo\AppData\Roaming\Koishi\Desktop\data\instances\default\node_modules\cordis\lib\index.cjs:663:17)
1000|2|2023-07-08 19:42:24 [W] app Error: service component:html has been registered
1000|2| at Context.component (C:\Users\Dnyo\AppData\Roaming\Koishi\Desktop\data\instances\default\node_modules\cordis\lib\index.cjs:621:)
1000|2| at Internal.component (C:\Users\Dnyo\AppData\Roaming\Koishi\Desktop\data\instances\default\node_modules@satorijs\core\lib\index.cjs:80:18)
1000|2| at runMicrotasks ()
1000|2| at Puppeteer.start (C:\Users\Dnyo\AppData\Roaming\Koishi\Desktop\data\instances\default\node_modules@seidko\koishi-plugin-puppeteer\lib\index.js:63:18)
1000|2| at async C:\Users\Dnyo\AppData\Roaming\Koishi\Desktop\data\instances\default\node_modules\cordis\lib\index.cjs:714:7
1000|2| at processTicksAndRejections (node:internal/process/task_queues:96:5)
1000|2| at async Promise.all (index 28)
1000|2| at async Lifecycle.start (C:\Users\Dnyo\AppData\Roaming\Koishi\Desktop\data\instances\default\node_modules\cordis\lib\index.cjs:164:5)
1000|2| at async Lifecycle.flush (C:\Users\Dnyo\AppData\Roaming\Koishi\Desktop\data\instances\default\node_modules\cordis\lib\index.cjs:77:7)
1000|2|2023-07-08 19:43:55 [I] app unload plugin eula:lotzz1
1000|2|2023-07-08 19:44:25 [I] app apply plugin eula:lotzz1
1000|2|2023-07-08 19:44:26 [I] app unload plugin eula:lotzz1
1000|2|2023-07-08 19:44:45 [I] app apply plugin eula:lotzz1
1000|2| at settle (C:\Users\Dnyo\AppData\Roaming\Koishi\Desktop\data\instances\default\node_modules\axios\dist\node\axios.cjs:1909:12)
1000|2|2023-07-08 19:45:43 [W] app AxiosError: Request failed with status code 404
1000|2| at IncomingMessage.emit (node:events:525:)
1000|2| at IncomingMessage.handleStreamEnd (C:\Users\Dnyo\AppData\Roaming\Koishi\Desktop\data\instances\default\node_modules\axios\dist\node\axios.cjs:2989:11)
1000|2| at processTicksAndRejections (node:internal/process/task_queues:83:21)
1000|2| at endReadableNT (node:internal/streams/readable:1:12)
1000|2| at settle (C:\Users\Dnyo\AppData\Roaming\Koishi\Desktop\data\instances\default\node_modules\axios\dist\node\axios.cjs:1909:12)
1000|2|2023-07-08 19:45:43 [W] app AxiosError: Request failed with status code 404
1000|2| at IncomingMessage.emit (node:events:525:)
1000|2| at IncomingMessage.handleStreamEnd (C:\Users\Dnyo\AppData\Roaming\Koishi\Desktop\data\instances\default\node_modules\axios\dist\node\axios.cjs:2989:11)
1000|2| at processTicksAndRejections (node:internal/process/task_queues:83:21)
1000|2| at endReadableNT (node:internal/streams/readable:1:12)
1000|2| at settle (C:\Users\Dnyo\AppData\Roaming\Koishi\Desktop\data\instances\default\node_modules\axios\dist\node\axios.cjs:1909:12)
1000|2|2023-07-08 19:45:44 [W] app AxiosError: Request failed with status code 404
1000|2| at IncomingMessage.emit (node:events:525:)
1000|2| at IncomingMessage.handleStreamEnd (C:\Users\Dnyo\AppData\Roaming\Koishi\Desktop\data\instances\default\node_modules\axios\dist\node\axios.cjs:2989:11)
1000|2| at processTicksAndRejections (node:internal/process/task_queues:83:21)
1000|2| at endReadableNT (node:internal/streams/readable:1:12)
1000|2| at settle (C:\Users\Dnyo\AppData\Roaming\Koishi\Desktop\data\instances\default\node_modules\axios\dist\node\axios.cjs:1909:12)
1000|2|2023-07-08 19:45:44 [W] app AxiosError: Request failed with status code 404
1000|2| at IncomingMessage.emit (node:events:525:)
1000|2| at IncomingMessage.handleStreamEnd (C:\Users\Dnyo\AppData\Roaming\Koishi\Desktop\data\instances\default\node_modules\axios\dist\node\axios.cjs:2989:11)
1000|2| at processTicksAndRejections (node:internal/process/task_queues:83:21)
1000|2| at endReadableNT (node:internal/streams/readable:1:12)
1000|2|2023-07-08 19:45:54 [I] eula [platfrom: qqguild]user 16140721060688695728 同意 eula
1000|2| at settle (C:\Users\Dnyo\AppData\Roaming\Koishi\Desktop\data\instances\default\node_modules\axios\dist\node\axios.cjs:1909:12)
1000|2|2023-07-08 19:45:54 [W] app AxiosError: Request failed with status code 404
1000|2| at IncomingMessage.emit (node:events:525:)
1000|2| at IncomingMessage.handleStreamEnd (C:\Users\Dnyo\AppData\Roaming\Koishi\Desktop\data\instances\default\node_modules\axios\dist\node\axios.cjs:2989:11)
1000|2| at processTicksAndRejections (node:internal/process/task_queues:83:21)
1000|2| at endReadableNT (node:internal/streams/readable:1:12)
1000|2| at settle (C:\Users\Dnyo\AppData\Roaming\Koishi\Desktop\data\instances\default\node_modules\axios\dist\node\axios.cjs:1909:12)
1000|2|2023-07-08 19:45:54 [W] app AxiosError: Request failed with status code 404
1000|2| at IncomingMessage.emit (node:events:525:)
1000|2| at IncomingMessage.handleStreamEnd (C:\Users\Dnyo\AppData\Roaming\Koishi\Desktop\data\instances\default\node_modules\axios\dist\node\axios.cjs:2989:11)
1000|2| at processTicksAndRejections (node:internal/process/task_queues:83:21)
1000|2| at endReadableNT (node:internal/streams/readable:1:12)
1000|2| at settle (C:\Users\Dnyo\AppData\Roaming\Koishi\Desktop\data\instances\default\node_modules\axios\dist\node\axios.cjs:1909:12)
1000|2|2023-07-08 19:46:17 [W] app AxiosError: Request failed with status code 404
1000|2| at IncomingMessage.emit (node:events:525:)
1000|2| at IncomingMessage.handleStreamEnd (C:\Users\Dnyo\AppData\Roaming\Koishi\Desktop\data\instances\default\node_modules\axios\dist\node\axios.cjs:2989:11)
1000|2| at processTicksAndRejections (node:internal/process/task_queues:83:21)
1000|2| at endReadableNT (node:internal/streams/readable:1:12)
1000|2| at settle (C:\Users\Dnyo\AppData\Roaming\Koishi\Desktop\data\instances\default\node_modules\axios\dist\node\axios.cjs:1909:12)
1000|2|2023-07-08 19:46:17 [W] app AxiosError: Request failed with status code 404
1000|2| at IncomingMessage.emit (node:events:525:)
1000|2| at IncomingMessage.handleStreamEnd (C:\Users\Dnyo\AppData\Roaming\Koishi\Desktop\data\instances\default\node_modules\axios\dist\node\axios.cjs:2989:11)
1000|2| at processTicksAndRejections (node:internal/process/task_queues:83:21)
1000|2| at endReadableNT (node:internal/streams/readable:1:12)
1000|2| at settle (C:\Users\Dnyo\AppData\Roaming\Koishi\Desktop\data\instances\default\node_modules\axios\dist\node\axios.cjs:1909:12)
1000|2|2023-07-08 19:46:18 [W] app AxiosError: Request failed with status code 404
1000|2| at IncomingMessage.emit (node:events:525:)
1000|2| at IncomingMessage.handleStreamEnd (C:\Users\Dnyo\AppData\Roaming\Koishi\Desktop\data\instances\default\node_modules\axios\dist\node\axios.cjs:2989:11)
1000|2| at processTicksAndRejections (node:internal/process/task_queues:83:21)
1000|2| at endReadableNT (node:internal/streams/readable:1:12)
1000|2| at settle (C:\Users\Dnyo\AppData\Roaming\Koishi\Desktop\data\instances\default\node_modules\axios\dist\node\axios.cjs:1909:12)
1000|2|2023-07-08 19:46:18 [W] app AxiosError: Request failed with status code 404
1000|2| at IncomingMessage.emit (node:events:525:)
1000|2| at IncomingMessage.handleStreamEnd (C:\Users\Dnyo\AppData\Roaming\Koishi\Desktop\data\instances\default\node_modules\axios\dist\node\axios.cjs:2989:11)
1000|2| at processTicksAndRejections (node:internal/process/task_queues:83:21)
1000|2| at endReadableNT (node:internal/streams/readable:1:12)
1000|2|2023-07-08 19:46:23 [I] eula [platfrom: qqguild]user 16140721060688695728 /同意 eula
1000|2| at settle (C:\Users\Dnyo\AppData\Roaming\Koishi\Desktop\data\instances\default\node_modules\axios\dist\node\axios.cjs:1909:12)
1000|2|2023-07-08 19:46:23 [W] app AxiosError: Request failed with status code 404
1000|2| at IncomingMessage.emit (node:events:525:)
1000|2| at IncomingMessage.handleStreamEnd (C:\Users\Dnyo\AppData\Roaming\Koishi\Desktop\data\instances\default\node_modules\axios\dist\node\axios.cjs:2989:11)
1000|2| at processTicksAndRejections (node:internal/process/task_queues:83:21)
1000|2| at endReadableNT (node:internal/streams/readable:1:12)
1000|2| at settle (C:\Users\Dnyo\AppData\Roaming\Koishi\Desktop\data\instances\default\node_modules\axios\dist\node\axios.cjs:1909:12)
1000|2|2023-07-08 19:46:23 [W] app AxiosError: Request failed with status code 404
1000|2| at IncomingMessage.emit (node:events:525:)
1000|2| at IncomingMessage.handleStreamEnd (C:\Users\Dnyo\AppData\Roaming\Koishi\Desktop\data\instances\default\node_modules\axios\dist\node\axios.cjs:2989:11)
1000|2| at processTicksAndRejections (node:internal/process/task_queues:83:21)
1000|2| at endReadableNT (node:internal/streams/readable:1:12)
截图如下: