🦄 refactor: 分离自定义对话

This commit is contained in:
zhiyu1998 2023-02-24 00:49:16 +08:00
parent b549baa99e
commit c1a1a65507
6 changed files with 1 additions and 137 deletions

View File

@ -60,28 +60,7 @@ sudo apt-get install ffmpeg
# Windows 参考https://www.jianshu.com/p/5015a477de3c # Windows 参考https://www.jianshu.com/p/5015a477de3c
```` ````
## 🧑‍🌾 【可选】进阶内容 ## 🧑‍🌾 进阶内容
这个功能由[烦烦同学](https://github.com/nilfunc
)提出的需求,正好符合插件的宗旨`为朋友所写的功能`。在使用这个功能之前需要安装以下:
在Yunzai主目录使用以下命令
> pnpm add mongoose -w
安装Mongodb别看错了下载`4.`版本):
> 官网地址https://www.mongodb.com/try/download/community
### 使用Mongoose进行自定义对话
需要把代码(apps/rchat.js)注释取消因为不是每个人都想装mongodb
> 注释的地方例如:// import mongoose from "mongoose";
> 取消注释快捷键:`ctrl + /`
### 进阶内容使用说明
❓ 询问:@机器人 (问题)
➕增加问题:@机器人 add问题
❌删除问题:@机器人 del问题
⭕更新问题:@机器人 update问题
![help](./img/example6.png)
### 其他进阶操作
【可选】相关配置(apps/tools.js) 【可选】相关配置(apps/tools.js)
> 小蓝鸟api:https://developer.twitter.com/en > 小蓝鸟api:https://developer.twitter.com/en
注册完之后将`Bearer Token`填入config/tools.yaml` 注册完之后将`Bearer Token`填入config/tools.yaml`

View File

@ -1,111 +0,0 @@
// import mongoose from "mongoose";
// mongoose.connect("mongodb://127.0.0.1:27017/rconsole");
// const Chat = mongoose.model("chats", new mongoose.Schema({ q: String, ans: String }));
export class rchat extends plugin {
constructor(e) {
super({
name: "自定义回复",
dsc: "R插件插件自定义回复",
event: "message",
priority: 500,
rule: [
// {
// reg: (e === undefined ? false : e.atme)
// ? "^[^add|del|update](.*)"
// : "#rchat(.*)",
// fnc: "queryChat",
// },
// {
// reg: (e === undefined ? false : e.atme) ? "add(.*)" : "#rchat add(.*)",
// fnc: "addCustomContent",
// },
// {
// reg: (e === undefined ? false : e.atme) ? "del(.*)" : "#rchat del(.*)",
// fnc: "delCustomContent",
// },
// {
// reg: (e === undefined ? false : e.atme) ? "update(.*)" : "#rchat update(.*)",
// fnc: "updateCustomContent",
// },
],
});
}
// async queryChat(e) {
// // 获取到想要聊天的内容
// const content = e.msg.trim();
// // 模糊查询
// await Chat.find({ q: new RegExp(content) }).then(res => {
// // 原答案
// // console.log(res);
// for (let epoch of res) {
// if (epoch.q.trim() === content) {
// e.reply(epoch.ans);
// return true;
// }
// }
// // 回复最接近的结果
// e.reply(res[0].ans);
// });
// }
//
// async addCustomContent(e) {
// const q = /add*(.*)/.exec(e.msg)[1].trim();
// await new Chat({ q, ans: "" }).save();
// await e.reply(`问题:${q},需要怎么回答?`, false, { at: true });
// this.setContext("addCustomAns");
// }
//
// async addCustomAns() {
// // 如果不回复或者回复其他
// if (!this.e.msg) {
// return true;
// }
// // 当前消息
// const curMsg = this.e;
// // 上一个消息
// const preMsg = this.getContext();
// // console.log(preMsg)
// // console.log(preMsg.addCustomAns)
// const q = /add*(.*)/.exec(preMsg.addCustomAns.msg)[1].trim();
// const ans = curMsg.msg.trim();
// await Chat.updateOne({ q }, { ans });
// this.finish("addCustomAns");
// }
//
// async delCustomContent(e) {
// const removeContent = /del*(.*)/.exec(e.msg)[1].trim();
// await Chat.deleteOne({ q: removeContent }).then(res => {
// e.reply(`已经删除${removeContent}`);
// });
// return true;
// }
//
// async updateCustomContent(e) {
// const updateContent = /update*(.*)/.exec(e.msg)[1].trim();
// await Chat.findOne({ q: updateContent }).then(res => {
// e.reply(`我觉得:${res.q},应该回答${res.ans},你觉得我该怎么回答?`);
// });
// this.setContext("updateCustomAns");
// return true;
// }
//
// async updateCustomAns() {
// // 如果不回复或者回复其他
// if (!this.e.msg) {
// return true;
// }
// // 当前消息
// const curMsg = this.e;
// // 上一个消息
// const preMsg = this.getContext();
// const q = /update*(.*)/.exec(preMsg.updateCustomAns.msg)[1].trim();
// const ans = curMsg.msg.trim();
// await Chat.findOneAndUpdate({ q }, { $set: { ans } }).then(res => {
// curMsg.reply(`明白了,${q},应该回答${ans}`);
// });
// this.finish("updateCustomAns");
// }
}

View File

@ -32,9 +32,6 @@
- icon: pic4 - icon: pic4
title: "#啊?" title: "#啊?"
desc: 啊? desc: 啊?
- icon: pic5
title: "@"
desc: 自定义对话
- group: 工具类合集 - group: 工具类合集
list: list:
- icon: translate - icon: translate

View File

@ -2,7 +2,6 @@
version: 1.0.7, version: 1.0.7,
data: data:
[ [
增加<span class="cmd">自定义对话</span>进阶功能,
增加<span class="cmd">SCI论文</span>解析, 增加<span class="cmd">SCI论文</span>解析,
适配<span class="cmd">锅巴</span>插件,方便查看和修改配置, 适配<span class="cmd">锅巴</span>插件,方便查看和修改配置,
增加<span class="cmd">小红书</span>的图片解析, 增加<span class="cmd">小红书</span>的图片解析,

Binary file not shown.

Before

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.2 KiB