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 douyinTypeMap = {
|
||||
2: 'image',
|
||||
4: 'video',
|
||||
68: 'image',
|
||||
0: 'video',
|
||||
51: 'video',
|
||||
55: 'video',
|
||||
58: 'video',
|
||||
61: 'video',
|
||||
150: 'image'
|
||||
}
|
||||
2: "image",
|
||||
4: "video",
|
||||
68: "image",
|
||||
0: "video",
|
||||
51: "video",
|
||||
55: "video",
|
||||
58: "video",
|
||||
61: "video",
|
||||
150: "image",
|
||||
};
|
||||
|
||||
export class tools extends plugin {
|
||||
constructor() {
|
||||
@ -128,8 +128,8 @@ export class tools extends plugin {
|
||||
const json = await resp.json();
|
||||
const item = json.aweme_detail;
|
||||
e.reply(`识别:抖音, ${item.desc}`);
|
||||
const url_type_code = item.aweme_type
|
||||
const url_type = douyinTypeMap[url_type_code]
|
||||
const url_type_code = item.aweme_type;
|
||||
const url_type = douyinTypeMap[url_type_code];
|
||||
if (url_type === "video") {
|
||||
const url_2 = item.video.play_addr.url_list[0];
|
||||
this.downloadVideo(url_2).then(video => {
|
||||
@ -149,7 +149,7 @@ export class tools extends plugin {
|
||||
// no_watermark_image_list.push(i.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("?"));
|
||||
}
|
||||
const dynamicId = /[^/]+(?!.*\/)/.exec(url)[0]
|
||||
const dynamicId = /[^/]+(?!.*\/)/.exec(url)[0];
|
||||
// console.log(dynamicId)
|
||||
getDynamic(dynamicId).then((resp) => {
|
||||
getDynamic(dynamicId).then(resp => {
|
||||
if (resp.dynamicSrc.length > 0) {
|
||||
e.reply(`识别:哔哩哔哩动态, ${resp.dynamicDesc}`)
|
||||
e.reply(`识别:哔哩哔哩动态, ${resp.dynamicDesc}`);
|
||||
// let dynamicSrcMsg = []
|
||||
// resp.dynamicSrc.forEach(item => {
|
||||
// dynamicSrcMsg.push({
|
||||
@ -245,13 +245,13 @@ export class tools extends plugin {
|
||||
// })
|
||||
// })
|
||||
resp.dynamicSrc.forEach(item => {
|
||||
e.reply(segment.image(item))
|
||||
})
|
||||
e.reply(segment.image(item));
|
||||
});
|
||||
} else {
|
||||
e.reply(`识别:哔哩哔哩动态, 但是失败!`)
|
||||
e.reply(`识别:哔哩哔哩动态, 但是失败!`);
|
||||
}
|
||||
})
|
||||
return true
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
const path = `${this.defaultPath}${this.e.group_id || this.e.user_id}/`;
|
||||
|
@ -2,11 +2,10 @@
|
||||
import Version from "../model/version.js";
|
||||
import config from "../model/index.js";
|
||||
import puppeteer from "../../../lib/puppeteer/puppeteer.js";
|
||||
import lodash from 'lodash'
|
||||
import lodash from "lodash";
|
||||
|
||||
import { exec, execSync } from "node:child_process";
|
||||
|
||||
|
||||
/**
|
||||
* 处理插件更新
|
||||
*/
|
||||
@ -53,76 +52,82 @@ export class update extends plugin {
|
||||
await this.e.reply("您无权操作");
|
||||
return true;
|
||||
}
|
||||
const pluginName = 'rconsole-plugin'
|
||||
const pluginName = "rconsole-plugin";
|
||||
|
||||
let command = `git -C ./plugins/${pluginName}/ pull --no-rebase`;
|
||||
this.oldCommitId = await this.getcommitId(pluginName)
|
||||
this.oldCommitId = await this.getcommitId(pluginName);
|
||||
await e.reply("正在执行更新操作,请稍等");
|
||||
|
||||
let ret = await this.execSync(command)
|
||||
let ret = await this.execSync(command);
|
||||
if (ret.error) {
|
||||
e.reply(`更新失败!重试一下!`)
|
||||
await this.gitErr(ret.error, ret.stdout)
|
||||
return false
|
||||
e.reply(`更新失败!重试一下!`);
|
||||
await this.gitErr(ret.error, ret.stdout);
|
||||
return false;
|
||||
}
|
||||
const time = await this.getTime(pluginName)
|
||||
const time = await this.getTime(pluginName);
|
||||
if (/Already up|已经是最新/g.test(ret.stdout)) {
|
||||
e.reply(`R插件已经是最新: ${this.versionData[0].version}`)
|
||||
e.reply(`R插件已经是最新: ${this.versionData[0].version}`);
|
||||
} else {
|
||||
this.isUp = true
|
||||
e.reply(`R插件更新成功,最后更新时间:${time}`)
|
||||
e.reply(await this.getLog(pluginName))
|
||||
this.isUp = true;
|
||||
e.reply(`R插件更新成功,最后更新时间:${time}`);
|
||||
e.reply(await this.getLog(pluginName));
|
||||
}
|
||||
return true
|
||||
return true;
|
||||
}
|
||||
|
||||
async getcommitId(pluginName) {
|
||||
// let cm = 'git rev-parse --short HEAD'
|
||||
const command = `git -C ./plugins/${pluginName}/ rev-parse --short HEAD`
|
||||
let commitId = execSync(command, {encoding: 'utf-8'})
|
||||
commitId = lodash.trim(commitId)
|
||||
return commitId
|
||||
const command = `git -C ./plugins/${pluginName}/ rev-parse --short HEAD`;
|
||||
let commitId = execSync(command, { encoding: "utf-8" });
|
||||
commitId = lodash.trim(commitId);
|
||||
return commitId;
|
||||
}
|
||||
|
||||
async execSync(cmd) {
|
||||
return new Promise((resolve, reject) => {
|
||||
exec(cmd, { windowsHide: true }, (error, stdout, stderr) => {
|
||||
resolve({error, stdout, stderr})
|
||||
})
|
||||
})
|
||||
resolve({ error, stdout, stderr });
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async getTime(pluginName) {
|
||||
const cm = `cd ./plugins/${pluginName}/ && git log -1 --oneline --pretty=format:"%cd" --date=format:"%m-%d %H:%M"`
|
||||
let time = ''
|
||||
const cm = `cd ./plugins/${pluginName}/ && git log -1 --oneline --pretty=format:"%cd" --date=format:"%m-%d %H:%M"`;
|
||||
let time = "";
|
||||
try {
|
||||
time = execSync(cm, {encoding: 'utf-8'})
|
||||
time = lodash.trim(time)
|
||||
time = execSync(cm, { encoding: "utf-8" });
|
||||
time = lodash.trim(time);
|
||||
} catch (error) {
|
||||
time = '获取时间失败'
|
||||
time = "获取时间失败";
|
||||
}
|
||||
return time
|
||||
return time;
|
||||
}
|
||||
|
||||
async getLog(pluginName) {
|
||||
let cm = 'git log -20 --oneline --pretty=format:"%h||[%cd] %s" --date=format:"%m-%d %H:%M"'
|
||||
if (pluginName) { cm = `cd ./plugins/${pluginName}/ && ${cm}` }
|
||||
let logAll
|
||||
try { logAll = execSync(cm, { encoding: 'utf-8' }) } catch (error) { this.reply(error.toString(), true) }
|
||||
if (!logAll) return false
|
||||
logAll = logAll.split('\n')
|
||||
let log = []
|
||||
let cm =
|
||||
'git log -20 --oneline --pretty=format:"%h||[%cd] %s" --date=format:"%m-%d %H:%M"';
|
||||
if (pluginName) {
|
||||
cm = `cd ./plugins/${pluginName}/ && ${cm}`;
|
||||
}
|
||||
let logAll;
|
||||
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) {
|
||||
str = str.split('||')
|
||||
if (str[0] === this.oldCommitId) break
|
||||
if (str[1].includes('Merge branch')) continue
|
||||
log.push(str[1])
|
||||
str = str.split("||");
|
||||
if (str[0] === this.oldCommitId) break;
|
||||
if (str[1].includes("Merge branch")) continue;
|
||||
log.push(str[1]);
|
||||
}
|
||||
let line = log.length
|
||||
log = log.join('\n')
|
||||
if (log.length <= 0) return ''
|
||||
logger.info(`${pluginName || 'Yunzai-Bot'}更新日志,共${line}条\n${log}`)
|
||||
return log
|
||||
let line = log.length;
|
||||
log = log.join("\n");
|
||||
if (log.length <= 0) return "";
|
||||
logger.info(`${pluginName || "Yunzai-Bot"}更新日志,共${line}条\n${log}`);
|
||||
return log;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user