mirror of
https://github.com/Jerryplusy/rc-plugin.git
synced 2025-10-14 16:19:18 +00:00
🪛 chore: 清除 lagrange 配置
This commit is contained in:
parent
44894b8259
commit
4a28205a67
@ -1,6 +1,6 @@
|
||||
import config from "../model/config.js";
|
||||
import schedule from 'node-schedule';
|
||||
import { REDIS_YUNZAI_ISOVERSEA, REDIS_YUNZAI_LAGRANGE, REDIS_YUNZAI_WHITELIST } from "../constants/constant.js";
|
||||
import { REDIS_YUNZAI_ISOVERSEA, REDIS_YUNZAI_WHITELIST } from "../constants/constant.js";
|
||||
import { deleteFolderRecursive, readCurrentDir } from "../utils/file.js";
|
||||
import { redisExistAndGetKey, redisGetKey, redisSetKey } from "../utils/redis-util.js";
|
||||
|
||||
@ -21,11 +21,6 @@ export class switchers extends plugin {
|
||||
fnc: "setOversea",
|
||||
permission: "master",
|
||||
},
|
||||
{
|
||||
reg: "^#设置拉格朗日$",
|
||||
fnc: "setLagrange",
|
||||
permission: "master",
|
||||
},
|
||||
{
|
||||
reg: "^清理垃圾$",
|
||||
fnc: "clearTrash",
|
||||
@ -80,35 +75,6 @@ export class switchers extends plugin {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置拉格朗日
|
||||
* @param e
|
||||
* @returns {Promise<boolean>}
|
||||
*/
|
||||
async setLagrange(e) {
|
||||
try {
|
||||
// 查看当前设置
|
||||
let driver = (await redisGetKey(REDIS_YUNZAI_LAGRANGE))?.driver;
|
||||
// 如果是第一次
|
||||
if (driver === undefined) {
|
||||
await redisSetKey(REDIS_YUNZAI_LAGRANGE, { driver: 1 });
|
||||
driver = 1;
|
||||
}
|
||||
// 异常检测,之前算法出现问题,如果出现异常就检测纠正
|
||||
if (driver === -1) {
|
||||
driver = 1;
|
||||
}
|
||||
// 设置
|
||||
driver ^= 1;
|
||||
await redisSetKey(REDIS_YUNZAI_LAGRANGE, { driver });
|
||||
e.reply(`当前驱动:${ driver ? '拉格朗日' : '其他驱动' }`);
|
||||
return true;
|
||||
} catch (err) {
|
||||
e.reply(`设置拉格朗日时发生错误: ${ err.message }`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 手动清理垃圾
|
||||
* @param e
|
||||
|
@ -20,7 +20,6 @@ import {
|
||||
HELP_DOC,
|
||||
MESSAGE_RECALL_TIME,
|
||||
REDIS_YUNZAI_ISOVERSEA,
|
||||
REDIS_YUNZAI_LAGRANGE,
|
||||
REDIS_YUNZAI_WHITELIST,
|
||||
SUMMARY_PROMPT,
|
||||
transMap,
|
||||
@ -85,7 +84,7 @@ import {
|
||||
downloadImg,
|
||||
estimateReadingTime,
|
||||
formatBiliInfo,
|
||||
retryAxiosReq, saveJsonToFile,
|
||||
retryAxiosReq,
|
||||
secondsToTime,
|
||||
testProxy,
|
||||
truncateString,
|
||||
@ -94,7 +93,6 @@ import {
|
||||
import { convertFlvToMp4 } from "../utils/ffmpeg-util.js";
|
||||
import { checkAndRemoveFile, deleteFolderRecursive, getMediaFilesAndOthers, mkdirIfNotExists } from "../utils/file.js";
|
||||
import GeneralLinkAdapter from "../utils/general-link-adapter.js";
|
||||
import { LagrangeAdapter } from "../utils/lagrange-adapter.js";
|
||||
import { contentEstimator } from "../utils/link-share-summary-util.js";
|
||||
import { deepSeekChat, llmRead } from "../utils/llm-util.js";
|
||||
import { getDS } from "../utils/mihoyo.js";
|
||||
@ -105,7 +103,7 @@ import { genVerifyFp } from "../utils/tiktok.js";
|
||||
import Translate from "../utils/trans-strategy.js";
|
||||
import { mid2id } from "../utils/weibo.js";
|
||||
import { convertToSeconds, removeParams, ytbFormatTime } from "../utils/youtube.js";
|
||||
import { ytDlpGetTilt, ytDlpHelper, ytDlpGetThumbnail, ytDlpGetDuration } from "../utils/yt-dlp-util.js";
|
||||
import { ytDlpGetDuration, ytDlpGetThumbnail, ytDlpGetTilt, ytDlpHelper } from "../utils/yt-dlp-util.js";
|
||||
import { textArrayToMakeForward } from "../utils/yunzai-util.js";
|
||||
|
||||
export class tools extends plugin {
|
||||
@ -2969,22 +2967,6 @@ export class tools extends plugin {
|
||||
return (await redisGetKey(REDIS_YUNZAI_ISOVERSEA)).os;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否是拉格朗日驱动
|
||||
* @returns {Promise<Boolean>}
|
||||
*/
|
||||
async isLagRangeDriver() {
|
||||
// 如果第一次使用没有值就设置
|
||||
if (!(await redisExistKey(REDIS_YUNZAI_LAGRANGE))) {
|
||||
await redisSetKey(REDIS_YUNZAI_LAGRANGE, {
|
||||
driver: 0,
|
||||
});
|
||||
return true;
|
||||
}
|
||||
// 如果有就取出来
|
||||
return (await redisGetKey(REDIS_YUNZAI_LAGRANGE)).driver;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断当前用户是否是信任用户
|
||||
* @param userId
|
||||
@ -3011,17 +2993,6 @@ export class tools extends plugin {
|
||||
*/
|
||||
async sendVideoToUpload(e, path, videoSizeLimit = this.videoSizeLimit) {
|
||||
try {
|
||||
// logger.info(videoSizeLimit);
|
||||
const isLag = await this.isLagRangeDriver();
|
||||
// 判断是否是拉格朗日
|
||||
if (isLag === 1) {
|
||||
// 构造拉格朗日适配器
|
||||
const lagrange = new LagrangeAdapter(this.toolsConfig.lagrangeForwardWebSocket);
|
||||
// 上传群文件
|
||||
await lagrange.uploadGroupFile(e.user_id || e.sender.card, e.group_id, path);
|
||||
// 上传完直接返回
|
||||
return;
|
||||
}
|
||||
// 判断文件是否存在
|
||||
if (!fs.existsSync(path)) {
|
||||
return e.reply('视频不存在');
|
||||
|
@ -43,8 +43,6 @@ queueConcurrency: 1 # 【目前只涉及哔哩哔哩的下载】根据服务器
|
||||
|
||||
videoDownloadConcurrency: 1 # 下载视频是否使用多线程,如果不使用默认是1,如果使用根据服务器进行选择,如果不确定是否可以用4即可,高性能服务器随意4~12都可以,看CPU的实力
|
||||
|
||||
lagrangeForwardWebSocket: 'ws://127.0.0.1:9091/' # 格式:ws://地址:端口/,拉格朗日正向连接地址,用于适配拉格朗日上传群文件,解决部分用户无法查看视频问题
|
||||
|
||||
autoclearTrashtime: '0 0 8 * * ?' #每天早上8点自动清理视频缓存,cron可自定义时间
|
||||
|
||||
aiBaseURL: '' # 用于识图的接口,kimi默认接口为:https://api.moonshot.cn,其他服务商自己填写
|
||||
|
@ -74,12 +74,6 @@ export const DIVIDING_LINE = "\n━━━{}━━━"
|
||||
*/
|
||||
export const REDIS_YUNZAI_ISOVERSEA = "Yz:rconsole:tools:oversea";
|
||||
|
||||
/**
|
||||
* 保存判断机子是否使用的是拉格朗日
|
||||
* @type {string}
|
||||
*/
|
||||
export const REDIS_YUNZAI_LAGRANGE = "Yz:rconsole:tools:lagrange";
|
||||
|
||||
/**
|
||||
* 缓存音乐搜索列表
|
||||
* @type {string}
|
||||
|
@ -185,7 +185,7 @@ export function supportGuoba() {
|
||||
},
|
||||
{
|
||||
field: "tools.biliUseBBDown",
|
||||
label: "使用BBDown下载",
|
||||
label: "BBDown接管下载",
|
||||
bottomHelpMessage:
|
||||
"【默认不开启,涉及范围只有哔哩哔哩,开启后默认最高画质发送】如果不爱折腾就使用默认下载方式,如果喜欢折腾就开启,开启后下载更强劲,并且一劳永逸!",
|
||||
component: "Switch",
|
||||
@ -367,17 +367,6 @@ export function supportGuoba() {
|
||||
placeholder: "不确定用1即可,高性能服务器随意4~12都可以,看CPU的实力",
|
||||
},
|
||||
},
|
||||
{
|
||||
field: "tools.lagrangeForwardWebSocket",
|
||||
label: "Lagrange.Core-WebSocket连接地址",
|
||||
bottomHelpMessage:
|
||||
"格式:ws://地址:端口/,拉格朗日正向连接地址,用于适配拉格朗日上传群文件,解决部分用户无法查看视频问题",
|
||||
component: "Input",
|
||||
required: false,
|
||||
componentProps: {
|
||||
placeholder: "请输入拉格朗日正向WebSocket连接地址",
|
||||
},
|
||||
},
|
||||
{
|
||||
field: "tools.aiBaseURL",
|
||||
label: "AI接口地址",
|
||||
|
@ -1,138 +0,0 @@
|
||||
import { randomUUID } from 'crypto'
|
||||
import path from "path";
|
||||
import fs from 'fs'
|
||||
import { WebSocket } from 'ws'
|
||||
|
||||
export class LagrangeAdapter {
|
||||
/**
|
||||
* 构造拉格朗日适配器
|
||||
* @param wsAddr 形如:ws://127.0.0.1:9091/
|
||||
*/
|
||||
constructor(wsAddr) {
|
||||
this.ws = new WebSocket(wsAddr)
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传群文件
|
||||
* @param bot_id - 云崽机器人id
|
||||
* @param group_id - 群号
|
||||
* @param file - 文件所在位置
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async uploadGroupFile(bot_id, group_id, file) {
|
||||
file = await this.formatFile(file)
|
||||
if (!file.match(/^file:\/\//)) {
|
||||
file = await this.fileToPath(file)
|
||||
file = await this.formatFile(file)
|
||||
}
|
||||
file = file.replace(/^file:\/\//, '')
|
||||
const name = path.basename(file) || Date.now() + path.extname(file)
|
||||
logger.info("[R插件][拉格朗日适配器] 连接到拉格朗日");
|
||||
logger.info(bot_id, group_id, file, name);
|
||||
this.ws.on("open", () => {
|
||||
this.upload_private_file_api(bot_id, group_id, file, name);
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传群文件的拉格朗日API
|
||||
* @param {string} id - 机器人QQ 通过e.bot、Bot调用无需传入
|
||||
* @param {number} group_id - 群号
|
||||
* @param {string} file - 本地文件路径
|
||||
* @param {string} name - 储存名称
|
||||
* @param {string} folder - 目标文件夹 默认群文件根目录
|
||||
*/
|
||||
async upload_private_file_api(id, group_id, file, name, folder = '/') {
|
||||
const params = { group_id, file, name, folder }
|
||||
const echo = randomUUID()
|
||||
/** 序列化 */
|
||||
const log = JSON.stringify({ echo, action: "upload_group_file", params })
|
||||
logger.info("[R插件][拉格朗日适配器] 发送视频中...");
|
||||
/** 发送到拉格朗日 */
|
||||
this.ws.send(log);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理segment中的i||i.file,主要用于一些sb字段,标准化他们
|
||||
* @param {string|object} file - i.file
|
||||
*/
|
||||
async formatFile(file) {
|
||||
const str = function () {
|
||||
if (file.includes('gchat.qpic.cn') && !file.startsWith('https://')) {
|
||||
return `https://${ file }`
|
||||
} else if (file.startsWith('base64://')) {
|
||||
return file
|
||||
} else if (file.startsWith('http://') || file.startsWith('https://')) {
|
||||
return file
|
||||
} else if (fs.existsSync(path.resolve(file.replace(/^file:\/\//, '')))) {
|
||||
return `file://${ path.resolve(file.replace(/^file:\/\//, '')) }`
|
||||
} else if (fs.existsSync(path.resolve(file.replace(/^file:\/\/\//, '')))) {
|
||||
return `file://${ path.resolve(file.replace(/^file:\/\/\//, '')) }`
|
||||
}
|
||||
return file
|
||||
}
|
||||
|
||||
switch (typeof file) {
|
||||
case 'object':
|
||||
/** 这里会有复读这样的直接原样不动把message发过来... */
|
||||
if (file.url) {
|
||||
if (file?.url?.includes('gchat.qpic.cn') && !file?.url?.startsWith('https://')) return `https://${ file.url }`
|
||||
return file.url
|
||||
}
|
||||
|
||||
/** 老插件渲染出来的图有这个字段 */
|
||||
if (file?.type === 'Buffer') return Buffer.from(file?.data)
|
||||
if (Buffer.isBuffer(file) || file instanceof Uint8Array) return file
|
||||
|
||||
/** 流 */
|
||||
if (file instanceof fs.ReadStream) return await Bot.Stream(file, { base: true })
|
||||
|
||||
/** i.file */
|
||||
if (file.file) return str(file.file)
|
||||
return file
|
||||
case 'string':
|
||||
return str(file)
|
||||
default:
|
||||
return file
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 传入文件,返回本地路径
|
||||
* 可以是http://、file://、base64://、buffer
|
||||
* @param {file://|base64://|http://|buffer} file
|
||||
* @param {string} _path - 可选,不传默认为图片
|
||||
*/
|
||||
async fileToPath(file, _path) {
|
||||
if (!_path) _path = `./temp/FileToUrl/${ Date.now() }.png`
|
||||
if (Buffer.isBuffer(file) || file instanceof Uint8Array) {
|
||||
fs.writeFileSync(_path, file)
|
||||
return _path
|
||||
} else if (file instanceof fs.ReadStream) {
|
||||
const buffer = await Bot.Stream(file)
|
||||
fs.writeFileSync(_path, buffer)
|
||||
return _path
|
||||
} else if (fs.existsSync(file.replace(/^file:\/\//, ''))) {
|
||||
fs.copyFileSync(file.replace(/^file:\/\//, ''), _path)
|
||||
return _path
|
||||
} else if (fs.existsSync(file.replace(/^file:\/\/\//, ''))) {
|
||||
fs.copyFileSync(file.replace(/^file:\/\/\//, ''), _path)
|
||||
return _path
|
||||
} else if (file.startsWith('base64://')) {
|
||||
const buffer = Buffer.from(file.replace(/^base64:\/\//, ''), 'base64')
|
||||
fs.writeFileSync(_path, buffer)
|
||||
return _path
|
||||
} else if (/^http(s)?:\/\//.test(file)) {
|
||||
const res = await fetch(file)
|
||||
if (!res.ok) {
|
||||
throw new Error(`请求错误!状态码: ${ res.status }`)
|
||||
} else {
|
||||
const buffer = Buffer.from(await res.arrayBuffer())
|
||||
fs.writeFileSync(_path, buffer)
|
||||
return _path
|
||||
}
|
||||
} else {
|
||||
throw new Error('传入的文件类型不符合规则,只接受url、buffer、file://路径或者base64编码的图片')
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user