mirror of
https://github.com/Jerryplusy/rc-plugin.git
synced 2025-10-14 16:19:18 +00:00
✨ feat: 1.0.7 新增自定义对话
1. 新增进阶内容:自定义对话 2. 删除#我靠,将在下一个版本进行重构 3. 整理、优化部分代码
This commit is contained in:
parent
1c69ded59a
commit
140b3de4bd
77
README.md
77
README.md
@ -43,7 +43,7 @@ index -- 主入口
|
||||
## 📔 使用说明
|
||||
|
||||
1.【必要】在`Yunzai-Bot`安装mongodb、axios(0.27.2)、代理工具(tunnel)、TwitterAPI依赖
|
||||
> pnpm add mongodb axios tunnel twitter-api-v2 -w
|
||||
> pnpm add axios tunnel twitter-api-v2 -w
|
||||
|
||||
2.【必要】下载插件
|
||||
> git clone https://gitee.com/kyrzy0416/rconsole-plugin.git ./plugins/rconsole-plugin/
|
||||
@ -56,67 +56,26 @@ sudo apt-get install ffmpeg
|
||||
# Windows 参考:https://www.jianshu.com/p/5015a477de3c
|
||||
````
|
||||
|
||||
## 🧑🌾 进阶
|
||||
【可选】备注:考虑到不是所有电脑都有mongodb,如果要开启`#我靠`功能,需要进行以下操作:
|
||||
## 🧑🌾 【可选】进阶内容
|
||||
这个功能由[烦烦同学](https://github.com/nilfunc
|
||||
)提出的需求,正好符合插件的宗旨`为朋友所写的功能`。在使用这个功能之前需要安装以下:
|
||||
在Yunzai主目录使用以下命令
|
||||
> pnpm add mongoose -w
|
||||
|
||||
### 使用Python、Mongodb爬虫三次元图片
|
||||
首先去test文件跑python代码(要安装`requirements.txt`要求的依赖)
|
||||
> python3 ./test/main.py
|
||||
安装Mongodb(别看错了,下载`4.`版本):
|
||||
> 官网地址:https://www.mongodb.com/try/download/community
|
||||
|
||||
需要把以下代码(apps/mystery.js)注释取消:
|
||||
```javascript
|
||||
// in apps/mystery.js
|
||||
### 使用Mongoose进行自定义对话
|
||||
需要把代码(apps/rchat.js)注释取消(因为不是每个人都想装mongodb):
|
||||
> 注释的地方例如:// import mongoose from "mongoose";
|
||||
> 取消注释快捷键:`ctrl + /`
|
||||
|
||||
// Mongodb初始化
|
||||
import mongodb from 'mongodb'
|
||||
|
||||
// Mongodb初始化
|
||||
function initMongo () {
|
||||
const MongoClient = mongodb.MongoClient
|
||||
const url = 'mongodb://localhost:27017/'
|
||||
return new Promise((resolve, reject) => {
|
||||
MongoClient.connect(url, (err, db) => {
|
||||
const dbo = db.db('test')
|
||||
if (err) {
|
||||
throw err // 和调用 reject(err) 效果类似
|
||||
}
|
||||
let collection = dbo.collection('temp')
|
||||
resolve(collection)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
const mongo = initMongo()
|
||||
// ...
|
||||
{
|
||||
reg: '^#我靠', fnc: 'tuiimg'
|
||||
}
|
||||
// ...
|
||||
async tuiimg (e) {
|
||||
const MAX_SIZE = this.mysteryConfig.tuiimg.count
|
||||
this.reply('这群早晚被你整没了...')
|
||||
let images = []
|
||||
const template = {
|
||||
nickname: this.e.sender.card || this.e.user_id, user_id: this.e.user_id
|
||||
}
|
||||
await mongo.then(conn => {
|
||||
return conn.aggregate([ { $sample: { size: MAX_SIZE } } ]).toArray()
|
||||
}).then((result) => {
|
||||
result.forEach((item) => {
|
||||
images.push({
|
||||
message: segment.image(item.url), ...template
|
||||
})
|
||||
})
|
||||
})
|
||||
return !!(await this.reply(await Bot.makeForwardMsg(images), false, {
|
||||
recallMsg: recallTime
|
||||
}))
|
||||
}
|
||||
```
|
||||
|
||||
> 备注:
|
||||
> 1. linux/windows系统下自己装一个mongodb,上一个密码(不上有风险)
|
||||
> 2. `test/main.py`爬取链接(要有python环境、配合mongodb使用)
|
||||
### 进阶内容使用说明
|
||||
❓ 询问:@机器人 (问题)
|
||||
➕增加问题:@机器人 add(问题)
|
||||
❌删除问题:@机器人 del(问题)
|
||||
⭕更新问题:@机器人 update(问题)
|
||||

|
||||
|
||||
### 其他进阶操作
|
||||
【可选】相关配置(apps/tools.js):
|
||||
|
@ -1,32 +1,10 @@
|
||||
// 主库
|
||||
import { segment } from "oicq";
|
||||
import common from "../../../lib/common/common.js";
|
||||
import fetch from "node-fetch";
|
||||
// 配置文件
|
||||
import config from "../model/index.js";
|
||||
// 其他库
|
||||
import _ from "lodash";
|
||||
// import mongodb from 'mongodb'
|
||||
|
||||
// Mongodb初始化
|
||||
// function initMongo () {
|
||||
// const MongoClient = mongodb.MongoClient
|
||||
// const url = 'mongodb://localhost:27017/'
|
||||
// return new Promise((resolve, reject) => {
|
||||
// MongoClient.connect(url, (err, db) => {
|
||||
// const dbo = db.db('test')
|
||||
// if (err) {
|
||||
// throw err // 和调用 reject(err) 效果类似
|
||||
// }
|
||||
// let collection = dbo.collection('temp')
|
||||
// resolve(collection)
|
||||
// })
|
||||
// })
|
||||
// }
|
||||
//
|
||||
// const mongo = initMongo()
|
||||
// 60s后撤回
|
||||
const recallTime = 109;
|
||||
|
||||
export class mystery extends plugin {
|
||||
constructor() {
|
||||
@ -52,9 +30,6 @@ export class mystery extends plugin {
|
||||
reg: "^#(啊?|啊?)$",
|
||||
fnc: "aaa",
|
||||
},
|
||||
// {
|
||||
// reg: '^#我靠', fnc: 'tuiimg'
|
||||
// }
|
||||
],
|
||||
});
|
||||
this.mysteryConfig = config.getConfig("mystery");
|
||||
@ -271,27 +246,6 @@ export class mystery extends plugin {
|
||||
return true;
|
||||
}
|
||||
|
||||
// async tuiimg (e) {
|
||||
// const MAX_SIZE = this.mysteryConfig.tuiimg.count
|
||||
// this.reply('这群早晚被你整没了...')
|
||||
// let images = []
|
||||
// const template = {
|
||||
// nickname: this.e.sender.card || this.e.user_id, user_id: this.e.user_id
|
||||
// }
|
||||
// await mongo.then(conn => {
|
||||
// return conn.aggregate([ { $sample: { size: MAX_SIZE } } ]).toArray()
|
||||
// }).then((result) => {
|
||||
// result.forEach((item) => {
|
||||
// images.push({
|
||||
// message: segment.image(item.url), ...template
|
||||
// })
|
||||
// })
|
||||
// })
|
||||
// return !!(await this.reply(await Bot.makeForwardMsg(images), false, {
|
||||
// recallMsg: recallTime
|
||||
// }))
|
||||
// }
|
||||
|
||||
// 正则:获取图片
|
||||
getCos6Img(string) {
|
||||
const imgRex = /\/([\w].*?).(jpg|JPG|png|PNG|gif|GIF|jpeg|JPEG|svg)/g;
|
||||
|
111
apps/rchat.js
Normal file
111
apps/rchat.js
Normal file
@ -0,0 +1,111 @@
|
||||
// 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");
|
||||
// }
|
||||
}
|
@ -12,11 +12,10 @@ import HttpProxyAgent from "https-proxy-agent";
|
||||
import { mkdirsSync } from "../utils/file.js";
|
||||
import { downloadBFile, getDownloadUrl, mergeFileToMp4, getDynamic } from "../utils/bilibili.js";
|
||||
import { parseUrl, parseM3u8, downloadM3u8Videos, mergeAcFileToMp4 } from "../utils/acfun.js";
|
||||
import { transMap, douyinTypeMap } from "../utils/constant.js"
|
||||
import { transMap, douyinTypeMap } from "../utils/constant.js";
|
||||
import { retry } from "../utils/common.js";
|
||||
import config from "../model/index.js";
|
||||
|
||||
|
||||
export class tools extends plugin {
|
||||
constructor() {
|
||||
super({
|
||||
@ -63,8 +62,8 @@ export class tools extends plugin {
|
||||
},
|
||||
{
|
||||
reg: "(.*)(doi.org)",
|
||||
fnc: "literature"
|
||||
}
|
||||
fnc: "literature",
|
||||
},
|
||||
],
|
||||
});
|
||||
// http://api.tuwei.space/girl
|
||||
@ -127,9 +126,9 @@ export class tools extends plugin {
|
||||
const url = `https://www.iesdouyin.com/aweme/v1/web/aweme/detail/?aweme_id=${douId}&aid=1128&version_name=23.5.0&device_platform=android&os_version=2333`;
|
||||
// 默认重试3次,每次间隔1s (防止SyntaxError: Unexpected token b in JSON at position 0)
|
||||
retry(
|
||||
await (function () {
|
||||
return fetch(url).then(resp => resp.json())
|
||||
})
|
||||
await function () {
|
||||
return fetch(url).then(resp => resp.json());
|
||||
}
|
||||
).then(async resp_json => {
|
||||
const item = resp_json.aweme_detail;
|
||||
e.reply(`识别:抖音, ${item.desc}`);
|
||||
@ -155,15 +154,15 @@ export class tools extends plugin {
|
||||
message: segment.image(i.url_list[0]),
|
||||
nickname: this.e.sender.card || this.e.user_id,
|
||||
user_id: this.e.user_id,
|
||||
})
|
||||
});
|
||||
// 有水印图片列表
|
||||
// watermark_image_list.push(i.download_url_list[0]);
|
||||
// e.reply(segment.image(i.url_list[0]));
|
||||
}
|
||||
// console.log(no_watermark_image_list)
|
||||
await this.reply(await Bot.makeForwardMsg(no_watermark_image_list))
|
||||
await this.reply(await Bot.makeForwardMsg(no_watermark_image_list));
|
||||
}
|
||||
})
|
||||
});
|
||||
});
|
||||
return true;
|
||||
}
|
||||
@ -387,7 +386,7 @@ export class tools extends plugin {
|
||||
const filePath = `${downloadPath}/${item.url.split("/").pop()}`;
|
||||
this.downloadImg(item.url, downloadPath).then(_ => {
|
||||
e.reply(segment.image(fs.readFileSync(filePath)));
|
||||
fs.unlinkSync(filePath)
|
||||
fs.unlinkSync(filePath);
|
||||
});
|
||||
} else if (item.type === "video") {
|
||||
// 视频
|
||||
@ -582,7 +581,7 @@ export class tools extends plugin {
|
||||
|
||||
// 文献解析
|
||||
async literature(e) {
|
||||
const litReg = /(http:|https:)\/\/doi.org\/[A-Za-z\d._?%&+\-=\/#@]*/
|
||||
const litReg = /(http:|https:)\/\/doi.org\/[A-Za-z\d._?%&+\-=\/#@]*/;
|
||||
const url = litReg.exec(e.msg.trim())[0];
|
||||
const waitList = [
|
||||
"https://sci-hub.se/",
|
||||
@ -594,12 +593,12 @@ export class tools extends plugin {
|
||||
"https://sci-hub.ru/",
|
||||
];
|
||||
const flag = /doi.org\/(.*)/.exec(url)[1];
|
||||
const newWaitList = waitList.map((item) => {
|
||||
const newWaitList = waitList.map(item => {
|
||||
return item + flag;
|
||||
});
|
||||
await Promise.race(newWaitList).then(resp => {
|
||||
e.reply(resp)
|
||||
})
|
||||
e.reply(resp);
|
||||
});
|
||||
}
|
||||
|
||||
async downBili(title, videoUrl, audioUrl) {
|
||||
@ -660,7 +659,7 @@ export class tools extends plugin {
|
||||
resolve(filepath);
|
||||
});
|
||||
});
|
||||
writer.on("error", (err) => {
|
||||
writer.on("error", err => {
|
||||
fs.unlink(filepath, () => {
|
||||
reject(err);
|
||||
});
|
||||
@ -678,7 +677,7 @@ export class tools extends plugin {
|
||||
"User-Agent":
|
||||
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36",
|
||||
},
|
||||
}).then((response) => {
|
||||
}).then(response => {
|
||||
const writer = fs.createWriteStream(filename);
|
||||
response.data.pipe(writer);
|
||||
return new Promise((resolve, reject) => {
|
||||
|
@ -33,8 +33,8 @@
|
||||
title: "#啊?"
|
||||
desc: 啊?
|
||||
- icon: pic5
|
||||
title: "#我靠"
|
||||
desc: 神秘的芒果
|
||||
title: "@"
|
||||
desc: 自定义对话
|
||||
- group: 工具类合集
|
||||
list:
|
||||
- icon: translate
|
||||
|
@ -1,13 +1,12 @@
|
||||
- {
|
||||
version: 1.0.6,
|
||||
version: 1.0.7,
|
||||
data:
|
||||
[
|
||||
增加<span class="cmd">自定义对话</span>进阶功能,
|
||||
增加<span class="cmd">SCI论文</span>解析,
|
||||
适配<span class="cmd">锅巴</span>插件,方便查看和修改配置,
|
||||
增加<span class="cmd">小红书</span>的图片解析,
|
||||
添加<span class="cmd">#R帮助</span>获取插件帮助,
|
||||
添加<span class="cmd">#R版本</span>获取插件版本,
|
||||
更新风控缓解、重构系统文件、增加部分接口撤回操作
|
||||
添加<span class="cmd">抖音</span>实时监听分享链接,
|
||||
],
|
||||
}
|
BIN
img/example6.png
Normal file
BIN
img/example6.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 65 KiB |
Binary file not shown.
Before Width: | Height: | Size: 5.5 KiB After Width: | Height: | Size: 5.9 KiB |
Binary file not shown.
Before Width: | Height: | Size: 5.9 KiB After Width: | Height: | Size: 6.2 KiB |
Loading…
x
Reference in New Issue
Block a user