mirror of
https://github.com/Jerryplusy/rc-plugin.git
synced 2025-10-14 16:19:18 +00:00
🐞 fix: #R插件更新修复
This commit is contained in:
parent
7575b24ef3
commit
ecd59f1e75
@ -17,16 +17,16 @@ import config from "../model/index.js";
|
|||||||
|
|
||||||
const transMap = { 中: "zh", 日: "jp", 文: "wyw", 英: "en" };
|
const transMap = { 中: "zh", 日: "jp", 文: "wyw", 英: "en" };
|
||||||
const douyinTypeMap = {
|
const douyinTypeMap = {
|
||||||
2: 'image',
|
2: "image",
|
||||||
4: 'video',
|
4: "video",
|
||||||
68: 'image',
|
68: "image",
|
||||||
0: 'video',
|
0: "video",
|
||||||
51: 'video',
|
51: "video",
|
||||||
55: 'video',
|
55: "video",
|
||||||
58: 'video',
|
58: "video",
|
||||||
61: 'video',
|
61: "video",
|
||||||
150: 'image'
|
150: "image",
|
||||||
}
|
};
|
||||||
|
|
||||||
export class tools extends plugin {
|
export class tools extends plugin {
|
||||||
constructor() {
|
constructor() {
|
||||||
@ -128,8 +128,8 @@ export class tools extends plugin {
|
|||||||
const json = await resp.json();
|
const json = await resp.json();
|
||||||
const item = json.aweme_detail;
|
const item = json.aweme_detail;
|
||||||
e.reply(`识别:抖音, ${item.desc}`);
|
e.reply(`识别:抖音, ${item.desc}`);
|
||||||
const url_type_code = item.aweme_type
|
const url_type_code = item.aweme_type;
|
||||||
const url_type = douyinTypeMap[url_type_code]
|
const url_type = douyinTypeMap[url_type_code];
|
||||||
if (url_type === "video") {
|
if (url_type === "video") {
|
||||||
const url_2 = item.video.play_addr.url_list[0];
|
const url_2 = item.video.play_addr.url_list[0];
|
||||||
this.downloadVideo(url_2).then(video => {
|
this.downloadVideo(url_2).then(video => {
|
||||||
@ -149,7 +149,7 @@ export class tools extends plugin {
|
|||||||
// no_watermark_image_list.push(i.url_list[0])
|
// no_watermark_image_list.push(i.url_list[0])
|
||||||
// 有水印图片列表
|
// 有水印图片列表
|
||||||
// watermark_image_list.push(i.download_url_list[0])
|
// watermark_image_list.push(i.download_url_list[0])
|
||||||
e.reply(segment.image(i.url_list[0]))
|
e.reply(segment.image(i.url_list[0]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -226,16 +226,16 @@ export class tools extends plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 动态
|
// 动态
|
||||||
if (url.includes('t.bilibili.com')) {
|
if (url.includes("t.bilibili.com")) {
|
||||||
// 去除多余参数
|
// 去除多余参数
|
||||||
if (url.includes('?')) {
|
if (url.includes("?")) {
|
||||||
url = url.substring(0, url.indexOf("?"));
|
url = url.substring(0, url.indexOf("?"));
|
||||||
}
|
}
|
||||||
const dynamicId = /[^/]+(?!.*\/)/.exec(url)[0]
|
const dynamicId = /[^/]+(?!.*\/)/.exec(url)[0];
|
||||||
// console.log(dynamicId)
|
// console.log(dynamicId)
|
||||||
getDynamic(dynamicId).then((resp) => {
|
getDynamic(dynamicId).then(resp => {
|
||||||
if (resp.dynamicSrc.length > 0) {
|
if (resp.dynamicSrc.length > 0) {
|
||||||
e.reply(`识别:哔哩哔哩动态, ${resp.dynamicDesc}`)
|
e.reply(`识别:哔哩哔哩动态, ${resp.dynamicDesc}`);
|
||||||
// let dynamicSrcMsg = []
|
// let dynamicSrcMsg = []
|
||||||
// resp.dynamicSrc.forEach(item => {
|
// resp.dynamicSrc.forEach(item => {
|
||||||
// dynamicSrcMsg.push({
|
// dynamicSrcMsg.push({
|
||||||
@ -245,13 +245,13 @@ export class tools extends plugin {
|
|||||||
// })
|
// })
|
||||||
// })
|
// })
|
||||||
resp.dynamicSrc.forEach(item => {
|
resp.dynamicSrc.forEach(item => {
|
||||||
e.reply(segment.image(item))
|
e.reply(segment.image(item));
|
||||||
})
|
});
|
||||||
} else {
|
} else {
|
||||||
e.reply(`识别:哔哩哔哩动态, 但是失败!`)
|
e.reply(`识别:哔哩哔哩动态, 但是失败!`);
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
return true
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const path = `${this.defaultPath}${this.e.group_id || this.e.user_id}/`;
|
const path = `${this.defaultPath}${this.e.group_id || this.e.user_id}/`;
|
||||||
|
@ -2,10 +2,9 @@
|
|||||||
import Version from "../model/version.js";
|
import Version from "../model/version.js";
|
||||||
import config from "../model/index.js";
|
import config from "../model/index.js";
|
||||||
import puppeteer from "../../../lib/puppeteer/puppeteer.js";
|
import puppeteer from "../../../lib/puppeteer/puppeteer.js";
|
||||||
import lodash from 'lodash'
|
import lodash from "lodash";
|
||||||
|
|
||||||
import {exec, execSync} from "node:child_process";
|
|
||||||
|
|
||||||
|
import { exec, execSync } from "node:child_process";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理插件更新
|
* 处理插件更新
|
||||||
@ -53,76 +52,82 @@ export class update extends plugin {
|
|||||||
await this.e.reply("您无权操作");
|
await this.e.reply("您无权操作");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
const pluginName = 'rconsole-plugin'
|
const pluginName = "rconsole-plugin";
|
||||||
|
|
||||||
let command = `git -C ./plugins/${pluginName}/ pull --no-rebase`;
|
let command = `git -C ./plugins/${pluginName}/ pull --no-rebase`;
|
||||||
this.oldCommitId = await this.getcommitId(pluginName)
|
this.oldCommitId = await this.getcommitId(pluginName);
|
||||||
await e.reply("正在执行更新操作,请稍等");
|
await e.reply("正在执行更新操作,请稍等");
|
||||||
|
|
||||||
let ret = await this.execSync(command)
|
let ret = await this.execSync(command);
|
||||||
if (ret.error) {
|
if (ret.error) {
|
||||||
e.reply(`更新失败!重试一下!`)
|
e.reply(`更新失败!重试一下!`);
|
||||||
await this.gitErr(ret.error, ret.stdout)
|
await this.gitErr(ret.error, ret.stdout);
|
||||||
return false
|
return false;
|
||||||
}
|
}
|
||||||
const time = await this.getTime(pluginName)
|
const time = await this.getTime(pluginName);
|
||||||
if (/Already up|已经是最新/g.test(ret.stdout)) {
|
if (/Already up|已经是最新/g.test(ret.stdout)) {
|
||||||
e.reply(`R插件已经是最新: ${this.versionData[0].version}`)
|
e.reply(`R插件已经是最新: ${this.versionData[0].version}`);
|
||||||
} else {
|
} else {
|
||||||
this.isUp = true
|
this.isUp = true;
|
||||||
e.reply(`R插件更新成功,最后更新时间:${time}`)
|
e.reply(`R插件更新成功,最后更新时间:${time}`);
|
||||||
e.reply(await this.getLog(pluginName))
|
e.reply(await this.getLog(pluginName));
|
||||||
}
|
}
|
||||||
return true
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getcommitId(pluginName) {
|
async getcommitId(pluginName) {
|
||||||
// let cm = 'git rev-parse --short HEAD'
|
// let cm = 'git rev-parse --short HEAD'
|
||||||
const command = `git -C ./plugins/${pluginName}/ rev-parse --short HEAD`
|
const command = `git -C ./plugins/${pluginName}/ rev-parse --short HEAD`;
|
||||||
let commitId = execSync(command, {encoding: 'utf-8'})
|
let commitId = execSync(command, { encoding: "utf-8" });
|
||||||
commitId = lodash.trim(commitId)
|
commitId = lodash.trim(commitId);
|
||||||
return commitId
|
return commitId;
|
||||||
}
|
}
|
||||||
|
|
||||||
async execSync(cmd) {
|
async execSync(cmd) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
exec(cmd, {windowsHide: true}, (error, stdout, stderr) => {
|
exec(cmd, { windowsHide: true }, (error, stdout, stderr) => {
|
||||||
resolve({error, stdout, stderr})
|
resolve({ error, stdout, stderr });
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async getTime(pluginName) {
|
async getTime(pluginName) {
|
||||||
const cm = `cd ./plugins/${pluginName}/ && git log -1 --oneline --pretty=format:"%cd" --date=format:"%m-%d %H:%M"`
|
const cm = `cd ./plugins/${pluginName}/ && git log -1 --oneline --pretty=format:"%cd" --date=format:"%m-%d %H:%M"`;
|
||||||
let time = ''
|
let time = "";
|
||||||
try {
|
try {
|
||||||
time = execSync(cm, {encoding: 'utf-8'})
|
time = execSync(cm, { encoding: "utf-8" });
|
||||||
time = lodash.trim(time)
|
time = lodash.trim(time);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
time = '获取时间失败'
|
time = "获取时间失败";
|
||||||
}
|
}
|
||||||
return time
|
return time;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getLog (pluginName) {
|
async getLog(pluginName) {
|
||||||
let cm = 'git log -20 --oneline --pretty=format:"%h||[%cd] %s" --date=format:"%m-%d %H:%M"'
|
let cm =
|
||||||
if (pluginName) { cm = `cd ./plugins/${pluginName}/ && ${cm}` }
|
'git log -20 --oneline --pretty=format:"%h||[%cd] %s" --date=format:"%m-%d %H:%M"';
|
||||||
let logAll
|
if (pluginName) {
|
||||||
try { logAll = execSync(cm, { encoding: 'utf-8' }) } catch (error) { this.reply(error.toString(), true) }
|
cm = `cd ./plugins/${pluginName}/ && ${cm}`;
|
||||||
if (!logAll) return false
|
}
|
||||||
logAll = logAll.split('\n')
|
let logAll;
|
||||||
let log = []
|
try {
|
||||||
|
logAll = execSync(cm, { encoding: "utf-8" });
|
||||||
|
} catch (error) {
|
||||||
|
this.reply(error.toString(), true);
|
||||||
|
}
|
||||||
|
if (!logAll) return false;
|
||||||
|
logAll = logAll.split("\n");
|
||||||
|
let log = [];
|
||||||
for (let str of logAll) {
|
for (let str of logAll) {
|
||||||
str = str.split('||')
|
str = str.split("||");
|
||||||
if (str[0] === this.oldCommitId) break
|
if (str[0] === this.oldCommitId) break;
|
||||||
if (str[1].includes('Merge branch')) continue
|
if (str[1].includes("Merge branch")) continue;
|
||||||
log.push(str[1])
|
log.push(str[1]);
|
||||||
}
|
}
|
||||||
let line = log.length
|
let line = log.length;
|
||||||
log = log.join('\n')
|
log = log.join("\n");
|
||||||
if (log.length <= 0) return ''
|
if (log.length <= 0) return "";
|
||||||
logger.info(`${pluginName || 'Yunzai-Bot'}更新日志,共${line}条\n${log}`)
|
logger.info(`${pluginName || "Yunzai-Bot"}更新日志,共${line}条\n${log}`);
|
||||||
return log
|
return log;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user