🌈 style: 代码美化,不做任何修改

This commit is contained in:
zhiyu1998 2023-03-07 13:27:00 +08:00
parent d774c811a1
commit 6abbc6154a
4 changed files with 174 additions and 160 deletions

View File

@ -1,6 +1,6 @@
import fetch from "node-fetch"; import fetch from "node-fetch";
import { Group, segment } from "oicq"; import { Group, segment } from "oicq";
import { autoTask } from "../utils/common.js" import { autoTask } from "../utils/common.js";
// 指定定时发送的群号 // 指定定时发送的群号
const groupList = ["169721415"]; const groupList = ["169721415"];
@ -60,7 +60,7 @@ export class daily extends plugin {
async function pushDailyWorld(e) { async function pushDailyWorld(e) {
// 每天60秒读懂世界接口地址 // 每天60秒读懂世界接口地址
const url = await fetch("https://api.vvhan.com/api/60s?type=json").catch(err => const url = await fetch("https://api.vvhan.com/api/60s?type=json").catch(err =>
console.error(err) console.error(err),
); );
const imgUrl = await url.json(); const imgUrl = await url.json();
const res = await imgUrl.imgUrl; const res = await imgUrl.imgUrl;
@ -80,7 +80,7 @@ async function pushDailyWorld(e) {
async function pushTouchFish(e) { async function pushTouchFish(e) {
const url = await fetch("https://api.vvhan.com/api/moyu?type=json").catch(err => const url = await fetch("https://api.vvhan.com/api/moyu?type=json").catch(err =>
console.error(err) console.error(err),
); );
const imgUrl = await url.json(); const imgUrl = await url.json();
const res = await imgUrl.url; const res = await imgUrl.url;

View File

@ -139,7 +139,7 @@ export class query extends plugin {
return true; return true;
} }
e.reply( e.reply(
`识别:${resp.data[0].name}\n烂番茄评分:${resp.imdbRating}\n豆瓣评分:${resp.doubanRating}\n评分:${resp.imdbRating}` `识别:${resp.data[0].name}\n烂番茄评分:${resp.imdbRating}\n豆瓣评分:${resp.doubanRating}\n评分:${resp.imdbRating}`,
); );
}); });
}); });
@ -151,7 +151,7 @@ export class query extends plugin {
let images = []; let images = [];
let reqRes = [ let reqRes = [
...(await fetch(`https://shibe.online/api/cats?count=${numb}`).then(data => ...(await fetch(`https://shibe.online/api/cats?count=${numb}`).then(data =>
data.json() data.json(),
)), )),
...(await fetch(`https://api.thecatapi.com/v1/images/search?limit=${numb}`) ...(await fetch(`https://api.thecatapi.com/v1/images/search?limit=${numb}`)
.then(data => data.json()) .then(data => data.json())
@ -323,7 +323,7 @@ export class query extends plugin {
"User-Agent": "User-Agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36 Edg/95.0.1020.53", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36 Edg/95.0.1020.53",
}, },
} },
) )
.then(resp => { .then(resp => {
// console.log(resp.data); // console.log(resp.data);
@ -482,7 +482,7 @@ export class query extends plugin {
}); });
await e.reply(await Bot.makeForwardMsg(bookMsg)); await e.reply(await Bot.makeForwardMsg(bookMsg));
await e.reply( await e.reply(
"请选择一个你想要的ID、来源例如11918807 zlibrary只回复11918807默认zlibrary" "请选择一个你想要的ID、来源例如11918807 zlibrary只回复11918807默认zlibrary",
); );
thisBookMethod.setContext("searchBookContext"); thisBookMethod.setContext("searchBookContext");

View File

@ -17,7 +17,7 @@ import { retry } from "../utils/common.js";
import config from "../model/index.js"; import config from "../model/index.js";
export class tools extends plugin { export class tools extends plugin {
constructor () { constructor() {
super({ super({
name: "工具和学习类", name: "工具和学习类",
dsc: "工具相关指令", dsc: "工具相关指令",
@ -75,7 +75,7 @@ export class tools extends plugin {
// TODO 填写服务器的内网ID和clash的端口 // TODO 填写服务器的内网ID和clash的端口
this.proxyAddr = this.toolsConfig.proxyAddr; this.proxyAddr = this.toolsConfig.proxyAddr;
this.proxyPort = this.toolsConfig.proxyPort; this.proxyPort = this.toolsConfig.proxyPort;
this.myProxy = `http://${ this.proxyAddr }:${ this.proxyPort }`; this.myProxy = `http://${this.proxyAddr}:${this.proxyPort}`;
// console.log(this.myProxy) // console.log(this.myProxy)
// 加载百度翻译配置 // 加载百度翻译配置
this.translateAppId = this.toolsConfig.translateAppId; this.translateAppId = this.toolsConfig.translateAppId;
@ -85,13 +85,13 @@ export class tools extends plugin {
} }
// 翻译插件 // 翻译插件
async trans (e) { async trans(e) {
const languageReg = /翻(.)/g; const languageReg = /翻(.)/g;
const msg = e.msg.trim(); const msg = e.msg.trim();
const language = languageReg.exec(msg); const language = languageReg.exec(msg);
if (!transMap.hasOwnProperty(language[1])) { if (!transMap.hasOwnProperty(language[1])) {
e.reply( e.reply(
"输入格式有误!例子:翻中 China's policy has been consistent, but Japan chooses a path of mistrust, decoupling and military expansion" "输入格式有误!例子:翻中 China's policy has been consistent, but Japan chooses a path of mistrust, decoupling and military expansion",
); );
return; return;
} }
@ -100,20 +100,20 @@ export class tools extends plugin {
// let url = `http://api.fanyi.baidu.com/api/trans/vip/translate?from=auto&to=${ transMap[language[1]] }&appid=APP ID&salt=自定义&sign=${ md5("APP ID" + place + "自定义" + "密钥") }&q=${ place }`; // let url = `http://api.fanyi.baidu.com/api/trans/vip/translate?from=auto&to=${ transMap[language[1]] }&appid=APP ID&salt=自定义&sign=${ md5("APP ID" + place + "自定义" + "密钥") }&q=${ place }`;
let url = `http://api.fanyi.baidu.com/api/trans/vip/translate?from=auto&to=${ let url = `http://api.fanyi.baidu.com/api/trans/vip/translate?from=auto&to=${
transMap[language[1]] transMap[language[1]]
}&appid=${ this.translateAppId }&salt=rconsole&sign=${ md5( }&appid=${this.translateAppId}&salt=rconsole&sign=${md5(
this.translateAppId + place + "rconsole" + this.translateSecret this.translateAppId + place + "rconsole" + this.translateSecret,
) }&q=${ place }`; )}&q=${place}`;
// console.log(url) // console.log(url)
await fetch(url) await fetch(url)
.then(resp => resp.json()) .then(resp => resp.json())
.then(text => text.trans_result) .then(text => text.trans_result)
.then(res => this.reply(`${ res[0].dst }`, true)) .then(res => this.reply(`${res[0].dst}`, true))
.catch(err => logger.error(err)); .catch(err => logger.error(err));
return true; return true;
} }
// 抖音解析 // 抖音解析
async douyin (e) { async douyin(e) {
const urlRex = /(http:|https:)\/\/v.douyin.com\/[A-Za-z\d._?%&+\-=\/#]*/g; const urlRex = /(http:|https:)\/\/v.douyin.com\/[A-Za-z\d._?%&+\-=\/#]*/g;
const douUrl = urlRex.exec(e.msg.trim())[0]; const douUrl = urlRex.exec(e.msg.trim())[0];
@ -125,85 +125,96 @@ 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`; // 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`;
fetch("https://ttwid.bytedance.com/ttwid/union/register/", { fetch("https://ttwid.bytedance.com/ttwid/union/register/", {
"method": "POST", method: "POST",
"mode": "cors", mode: "cors",
"credentials": 'include', credentials: "include",
body: JSON.stringify({ body: JSON.stringify({
"region": "cn", region: "cn",
"aid": 1768, aid: 1768,
"needFid": false, needFid: false,
"service": "www.ixigua.com", service: "www.ixigua.com",
"migrate_info": { migrate_info: {
"ticket": "", ticket: "",
"source": "node" source: "node",
}, },
"cbUrlProtocol": "https", cbUrlProtocol: "https",
"union": true union: true,
}) }),
}).then(resp => { }).then(resp => {
const ttwid = resp.headers.get('set-cookie'); const ttwid = resp.headers.get("set-cookie");
const odin_tt = 'a09d8eb0d95b7b9adb4b6fc6591918bfb996096967a7aa4305bd81b5150a8199d2e29ed21883cdd7709c5beaa2be3baa'; const odin_tt =
"a09d8eb0d95b7b9adb4b6fc6591918bfb996096967a7aa4305bd81b5150a8199d2e29ed21883cdd7709c5beaa2be3baa";
const headers = { const headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36', "user-agent":
'referer':'https://www.douyin.com/', "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36",
'Cookie': `ttwid=${ttwid};${odin_tt}` referer: "https://www.douyin.com/",
} Cookie: `ttwid=${ttwid};${odin_tt}`,
const dyApi = 'https://www.douyin.com/aweme/v1/web/aweme/detail/?' };
const params = `aweme_id=${ douId }&aid=1128&version_name=23.5.0&device_platform=android&os_version=2333` const dyApi = "https://www.douyin.com/aweme/v1/web/aweme/detail/?";
const params = `aweme_id=${douId}&aid=1128&version_name=23.5.0&device_platform=android&os_version=2333`;
// xg参数 // xg参数
axios.post(`http://47.115.200.238/xg/path?url=${params.replaceAll('&','%26')}`, { axios
headers: { .post(`http://47.115.200.238/xg/path?url=${params.replaceAll("&", "%26")}`, {
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36", headers: {
"referer": "https://www.douyin.com/", "user-agent":
"cookie": "" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36",
}, referer: "https://www.douyin.com/",
}).then(resp => { cookie: "",
const param = resp.data.result[0].paramsencode },
const resDyApi = `${dyApi}${param}`
axios.get(resDyApi, {
headers
}).then(async resp => {
const item = resp.data.aweme_detail;
e.reply(`识别:抖音, ${ item.desc }`);
const urlTypeCode = item.aweme_type;
const urlType = douyinTypeMap[urlTypeCode];
if (urlType === "video") {
const url_2 = item.video.play_addr.url_list[2];
this.downloadVideo(url_2, false, headers).then(video => {
e.reply(
segment.video(
`${ this.defaultPath }${ this.e.group_id || this.e.user_id }/temp.mp4`
)
);
});
} else if (urlType === "image") {
// 无水印图片列表
let no_watermark_image_list = [];
// 有水印图片列表
// let watermark_image_list = [];
for (let i of item.images) {
// 无水印图片列表
no_watermark_image_list.push({
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));
}
}) })
}) .then(resp => {
}) const param = resp.data.result[0].paramsencode;
const resDyApi = `${dyApi}${param}`;
axios
.get(resDyApi, {
headers,
})
.then(async resp => {
const item = resp.data.aweme_detail;
e.reply(`识别:抖音, ${item.desc}`);
const urlTypeCode = item.aweme_type;
const urlType = douyinTypeMap[urlTypeCode];
if (urlType === "video") {
const url_2 = item.video.play_addr.url_list[2];
this.downloadVideo(url_2, false, headers).then(video => {
e.reply(
segment.video(
`${this.defaultPath}${
this.e.group_id || this.e.user_id
}/temp.mp4`,
),
);
});
} else if (urlType === "image") {
// 无水印图片列表
let no_watermark_image_list = [];
// 有水印图片列表
// let watermark_image_list = [];
for (let i of item.images) {
// 无水印图片列表
no_watermark_image_list.push({
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),
);
}
});
});
});
}); });
return true; return true;
} }
// tiktok解析 // tiktok解析
async tiktok (e) { async tiktok(e) {
const urlRex = /(http:|https:)\/\/www.tiktok.com\/[A-Za-z\d._?%&+\-=\/#@]*/g; const urlRex = /(http:|https:)\/\/www.tiktok.com\/[A-Za-z\d._?%&+\-=\/#@]*/g;
const urlShortRex = /(http:|https:)\/\/vt.tiktok.com\/[A-Za-z\d._?%&+\-=\/#]*/g; const urlShortRex = /(http:|https:)\/\/vt.tiktok.com\/[A-Za-z\d._?%&+\-=\/#]*/g;
const urlShortRex2 = /(http:|https:)\/\/vm.tiktok.com\/[A-Za-z\d._?%&+\-=\/#]*/g; const urlShortRex2 = /(http:|https:)\/\/vm.tiktok.com\/[A-Za-z\d._?%&+\-=\/#]*/g;
@ -235,7 +246,7 @@ export class tools extends plugin {
} }
const idVideo = await this.getIdVideo(url); const idVideo = await this.getIdVideo(url);
// API链接 // API链接
const API_URL = `https://api16-normal-c-useast1a.tiktokv.com/aweme/v1/feed/?aweme_id=${ idVideo }&version_code=262&app_name=musical_ly&channel=App&device_id=null&os_version=14.4.2&device_platform=iphone&device_type=iPhone9`; const API_URL = `https://api16-normal-c-useast1a.tiktokv.com/aweme/v1/feed/?aweme_id=${idVideo}&version_code=262&app_name=musical_ly&channel=App&device_id=null&os_version=14.4.2&device_platform=iphone&device_type=iPhone9`;
await axios await axios
.get(API_URL, { .get(API_URL, {
@ -256,12 +267,12 @@ export class tools extends plugin {
}) })
.then(resp => { .then(resp => {
const data = resp.data.aweme_list[0]; const data = resp.data.aweme_list[0];
e.reply(`识别tiktok, ${ data.desc }`); e.reply(`识别tiktok, ${data.desc}`);
this.downloadVideo(data.video.play_addr.url_list[0], true).then(video => { this.downloadVideo(data.video.play_addr.url_list[0], true).then(video => {
e.reply( e.reply(
segment.video( segment.video(
`${ this.defaultPath }${ this.e.group_id || this.e.user_id }/temp.mp4` `${this.defaultPath}${this.e.group_id || this.e.user_id}/temp.mp4`,
) ),
); );
}); });
}); });
@ -269,7 +280,7 @@ export class tools extends plugin {
} }
// bilibi解析 // bilibi解析
async bili (e) { async bili(e) {
const urlRex = /(http:|https:)\/\/www.bilibili.com\/[A-Za-z\d._?%&+\-=\/#]*/g; const urlRex = /(http:|https:)\/\/www.bilibili.com\/[A-Za-z\d._?%&+\-=\/#]*/g;
const bShortRex = /(http:|https:)\/\/b23.tv\/[A-Za-z\d._?%&+\-=\/#]*/g; const bShortRex = /(http:|https:)\/\/b23.tv\/[A-Za-z\d._?%&+\-=\/#]*/g;
let url = e.msg.trim(); let url = e.msg.trim();
@ -293,15 +304,15 @@ export class tools extends plugin {
// console.log(dynamicId) // console.log(dynamicId)
getDynamic(dynamicId).then(async resp => { getDynamic(dynamicId).then(async 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({
message: segment.image(item), message: segment.image(item),
nickname: e.sender.card || e.user_id, nickname: e.sender.card || e.user_id,
user_id: e.user_id, user_id: e.user_id,
}) });
}) });
await this.reply(await Bot.makeForwardMsg(dynamicSrcMsg)); await this.reply(await Bot.makeForwardMsg(dynamicSrcMsg));
// resp.dynamicSrc.forEach(item => { // resp.dynamicSrc.forEach(item => {
// e.reply(segment.image(item)); // e.reply(segment.image(item));
@ -313,7 +324,7 @@ export class tools extends plugin {
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}/`;
if (!fs.existsSync(path)) { if (!fs.existsSync(path)) {
mkdirsSync(path); mkdirsSync(path);
} }
@ -325,12 +336,12 @@ export class tools extends plugin {
// 获取视频信息,然后发送 // 获取视频信息,然后发送
fetch( fetch(
videoId.startsWith("BV") videoId.startsWith("BV")
? `${ baseVideoInfo }?bvid=${ videoId }` ? `${baseVideoInfo}?bvid=${videoId}`
: `${ baseVideoInfo }?aid=${ videoId }` : `${baseVideoInfo}?aid=${videoId}`,
) )
.then(resp => resp.json()) .then(resp => resp.json())
.then(resp => { .then(resp => {
e.reply(`识别:哔哩哔哩, ${ resp.data.title }`).catch(err => { e.reply(`识别:哔哩哔哩, ${resp.data.title}`).catch(err => {
e.reply("解析失败,重试一下"); e.reply("解析失败,重试一下");
console.log(err); console.log(err);
}); });
@ -339,9 +350,9 @@ export class tools extends plugin {
await getDownloadUrl(url) await getDownloadUrl(url)
.then(data => { .then(data => {
this.downBili(`${ path }temp`, data.videoUrl, data.audioUrl) this.downBili(`${path}temp`, data.videoUrl, data.audioUrl)
.then(data => { .then(data => {
e.reply(segment.video(`${ path }temp.mp4`)); e.reply(segment.video(`${path}temp.mp4`));
}) })
.catch(err => { .catch(err => {
console.log(err); console.log(err);
@ -356,9 +367,9 @@ export class tools extends plugin {
} }
// 百科 // 百科
async wiki (e) { async wiki(e) {
const key = e.msg.replace(/#|百科|wiki/g, "").trim(); const key = e.msg.replace(/#|百科|wiki/g, "").trim();
const url = `https://xiaoapi.cn/API/bk.php?m=json&type=sg&msg=${ encodeURI(key) }`; const url = `https://xiaoapi.cn/API/bk.php?m=json&type=sg&msg=${encodeURI(key)}`;
// const url2 = 'https://api.jikipedia.com/go/auto_complete' // const url2 = 'https://api.jikipedia.com/go/auto_complete'
Promise.all([ Promise.all([
// axios.post(url2, { // axios.post(url2, {
@ -392,8 +403,8 @@ export class tools extends plugin {
const data = res[0]; const data = res[0];
// const data2 = res[0] // const data2 = res[0]
const template = ` const template = `
解释${ _.get(data, "msg") }\n 解释${_.get(data, "msg")}\n
详情${ _.get(data, "more") }\n 详情${_.get(data, "more")}\n
`; `;
// 小鸡解释:${ _.get(data2, 'content') } // 小鸡解释:${ _.get(data2, 'content') }
e.reply(template); e.reply(template);
@ -403,7 +414,7 @@ export class tools extends plugin {
// 小蓝鸟解析 // 小蓝鸟解析
// 例子https://twitter.com/chonkyanimalx/status/1595834168000204800 // 例子https://twitter.com/chonkyanimalx/status/1595834168000204800
async twitter (e) { async twitter(e) {
// 配置参数及解析 // 配置参数及解析
const reg = /https?:\/\/twitter.com\/[0-9-a-zA-Z_]{1,20}\/status\/([0-9]*)/; const reg = /https?:\/\/twitter.com\/[0-9-a-zA-Z_]{1,20}\/status\/([0-9]*)/;
const twitterUrl = reg.exec(e.msg); const twitterUrl = reg.exec(e.msg);
@ -418,54 +429,56 @@ export class tools extends plugin {
.singleTweet(id, { .singleTweet(id, {
"media.fields": "media.fields":
"duration_ms,height,media_key,preview_image_url,public_metrics,type,url,width,alt_text,variants", "duration_ms,height,media_key,preview_image_url,public_metrics,type,url,width,alt_text,variants",
expansions: [ "entities.mentions.username", "attachments.media_keys" ], expansions: ["entities.mentions.username", "attachments.media_keys"],
}) })
.then(async resp => { .then(async resp => {
e.reply(`识别:小蓝鸟学习版,${ resp.data.text }`); e.reply(`识别:小蓝鸟学习版,${resp.data.text}`);
const downloadPath = `${ this.defaultPath }${ this.e.group_id || this.e.user_id }`; const downloadPath = `${this.defaultPath}${this.e.group_id || this.e.user_id}`;
// 创建文件夹(如果没有过这个群) // 创建文件夹(如果没有过这个群)
if (!fs.existsSync(downloadPath)) { if (!fs.existsSync(downloadPath)) {
mkdirsSync(downloadPath); mkdirsSync(downloadPath);
} }
// 逐个遍历判断 // 逐个遍历判断
let task = [] let task = [];
for (let item of resp.includes.media) { for (let item of resp.includes.media) {
if (item.type === "photo") { if (item.type === "photo") {
// 图片 // 图片
task.push(this.downloadImg(item.url, downloadPath)) task.push(this.downloadImg(item.url, downloadPath));
} else if (item.type === "video") { } else if (item.type === "video") {
// 视频 // 视频
await this.downloadVideo(resp.includes.media[0].variants[0].url, true).then(_ => { await this.downloadVideo(resp.includes.media[0].variants[0].url, true).then(
e.reply(segment.video(`${ downloadPath }/temp.mp4`)); _ => {
}); e.reply(segment.video(`${downloadPath}/temp.mp4`));
},
);
} }
} }
let images = [] let images = [];
let path = [] let path = [];
// 获取所有图片的promise // 获取所有图片的promise
await Promise.all(task).then(resp => { await Promise.all(task).then(resp => {
// console.log(resp) // console.log(resp)
resp.forEach(item => { resp.forEach(item => {
path.push(item) path.push(item);
images.push({ images.push({
message: segment.image(fs.readFileSync(item)), message: segment.image(fs.readFileSync(item)),
nickname: this.e.sender.card || this.e.user_id, nickname: this.e.sender.card || this.e.user_id,
user_id: this.e.user_id, user_id: this.e.user_id,
}); });
}) });
}) });
await e.reply(await Bot.makeForwardMsg(images)) await e.reply(await Bot.makeForwardMsg(images));
// 清理文件 // 清理文件
path.forEach(item => { path.forEach(item => {
fs.unlinkSync(item); fs.unlinkSync(item);
}) });
}); });
return true; return true;
} }
// acfun解析 // acfun解析
async acfun (e) { async acfun(e) {
const path = `${ this.defaultPath }${ this.e.group_id || this.e.user_id }/temp/`; const path = `${this.defaultPath}${this.e.group_id || this.e.user_id}/temp/`;
if (!fs.existsSync(path)) { if (!fs.existsSync(path)) {
mkdirsSync(path); mkdirsSync(path);
} }
@ -473,15 +486,15 @@ export class tools extends plugin {
let inputMsg = e.msg; let inputMsg = e.msg;
// 适配手机分享https://m.acfun.cn/v/?ac=32838812&sid=d2b0991bd6ad9c09 // 适配手机分享https://m.acfun.cn/v/?ac=32838812&sid=d2b0991bd6ad9c09
if (inputMsg.includes("m.acfun.cn")) { if (inputMsg.includes("m.acfun.cn")) {
inputMsg = `https://www.acfun.cn/v/ac${ /ac=([^&?]*)/.exec(inputMsg)[1] }`; inputMsg = `https://www.acfun.cn/v/ac${/ac=([^&?]*)/.exec(inputMsg)[1]}`;
} }
parseUrl(inputMsg).then(res => { parseUrl(inputMsg).then(res => {
e.reply(`识别:猴山,${ res.videoName }`); e.reply(`识别:猴山,${res.videoName}`);
parseM3u8(res.urlM3u8s[res.urlM3u8s.length - 1]).then(res2 => { parseM3u8(res.urlM3u8s[res.urlM3u8s.length - 1]).then(res2 => {
downloadM3u8Videos(res2.m3u8FullUrls, path).then(_ => { downloadM3u8Videos(res2.m3u8FullUrls, path).then(_ => {
mergeAcFileToMp4(res2.tsNames, path, `${ path }out.mp4`).then(_ => { mergeAcFileToMp4(res2.tsNames, path, `${path}out.mp4`).then(_ => {
e.reply(segment.video(`${ path }out.mp4`)); e.reply(segment.video(`${path}out.mp4`));
}); });
}); });
}); });
@ -490,11 +503,11 @@ export class tools extends plugin {
} }
// 小红书解析 // 小红书解析
async redbook (e) { async redbook(e) {
const msgUrl = /(http:|https:)\/\/(xhslink|xiaohongshu).com\/[A-Za-z\d._?%&+\-=\/#@]*/.exec( const msgUrl = /(http:|https:)\/\/(xhslink|xiaohongshu).com\/[A-Za-z\d._?%&+\-=\/#@]*/.exec(
e.msg e.msg,
)[0]; )[0];
const url = `https://dlpanda.com/zh-CN/xhs?url=${ msgUrl }`; const url = `https://dlpanda.com/zh-CN/xhs?url=${msgUrl}`;
await axios await axios
.get(url, { .get(url, {
@ -510,21 +523,22 @@ export class tools extends plugin {
.then(async resp => { .then(async resp => {
const reg = /<img(.*)src="\/\/ci\.xiaohongshu\.com(.*?)"/g; const reg = /<img(.*)src="\/\/ci\.xiaohongshu\.com(.*?)"/g;
const downloadPath = `${ this.defaultPath }${ this.e.group_id || this.e.user_id }`; const downloadPath = `${this.defaultPath}${this.e.group_id || this.e.user_id}`;
// 创建文件夹(如果没有过这个群) // 创建文件夹(如果没有过这个群)
if (!fs.existsSync(downloadPath)) { if (!fs.existsSync(downloadPath)) {
mkdirsSync(downloadPath); mkdirsSync(downloadPath);
} }
const res = resp.data.match(reg) const res = resp.data.match(reg);
const imagesPath = res.map(item => { const imagesPath = res.map(item => {
const addr = `https:${item.split('"')[3]}`; const addr = `https:${item.split('"')[3]}`;
return axios.get(addr, { return axios
headers: { .get(addr, {
"User-Agent": headers: {
"Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Mobile Safari/537.36", "User-Agent":
}, "Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Mobile Safari/537.36",
responseType: "stream", },
}) responseType: "stream",
})
.then(resp => { .then(resp => {
const filepath = `${downloadPath}/${/com\/(.*)\?/.exec(addr)[1]}.jpg`; const filepath = `${downloadPath}/${/com\/(.*)\?/.exec(addr)[1]}.jpg`;
const writer = fs.createWriteStream(filepath); const writer = fs.createWriteStream(filepath);
@ -533,31 +547,31 @@ export class tools extends plugin {
writer.on("finish", () => resolve(filepath)); writer.on("finish", () => resolve(filepath));
writer.on("error", reject); writer.on("error", reject);
}); });
}) });
}) });
let path = [] let path = [];
const images = await Promise.all(imagesPath).then(paths => { const images = await Promise.all(imagesPath).then(paths => {
return paths.map(item => { return paths.map(item => {
path.push(item) path.push(item);
return { return {
message: segment.image(fs.readFileSync(item)), message: segment.image(fs.readFileSync(item)),
nickname: e.sender.card || e.user_id, nickname: e.sender.card || e.user_id,
user_id: e.user_id, user_id: e.user_id,
} };
}) });
}) });
await this.reply(await Bot.makeForwardMsg(images)); await this.reply(await Bot.makeForwardMsg(images));
// 清理文件 // 清理文件
path.forEach(item => { path.forEach(item => {
fs.unlinkSync(item); fs.unlinkSync(item);
}) });
}); });
return true; return true;
} }
// 文献解析 // 文献解析
async literature (e) { 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 url = litReg.exec(e.msg.trim())[0];
const waitList = [ const waitList = [
@ -578,7 +592,7 @@ export class tools extends plugin {
}); });
} }
async downBili (title, videoUrl, audioUrl) { async downBili(title, videoUrl, audioUrl) {
return Promise.all([ return Promise.all([
downloadBFile( downloadBFile(
videoUrl, videoUrl,
@ -589,8 +603,8 @@ export class tools extends plugin {
type: "video", type: "video",
data: value, data: value,
}), }),
1000 1000,
) ),
), ),
downloadBFile( downloadBFile(
audioUrl, audioUrl,
@ -601,8 +615,8 @@ export class tools extends plugin {
type: "audio", type: "audio",
data: value, data: value,
}), }),
1000 1000,
) ),
), ),
]).then(data => { ]).then(data => {
return mergeFileToMp4(data[0].fullFileName, data[1].fullFileName, title + ".mp4"); return mergeFileToMp4(data[0].fullFileName, data[1].fullFileName, title + ".mp4");
@ -610,9 +624,9 @@ export class tools extends plugin {
} }
// 工具:下载一张网络图片 // 工具:下载一张网络图片
async downloadImg (img, dir) { async downloadImg(img, dir) {
const filename = img.split("/").pop(); const filename = img.split("/").pop();
const filepath = `${ dir }/${ filename }`; const filepath = `${dir}/${filename}`;
const writer = fs.createWriteStream(filepath); const writer = fs.createWriteStream(filepath);
return axios return axios
.get(img, { .get(img, {
@ -646,7 +660,7 @@ export class tools extends plugin {
} }
// 请求参数 // 请求参数
async douyinRequest (url) { async douyinRequest(url) {
const params = { const params = {
headers: { headers: {
"User-Agent": "User-Agent":
@ -668,12 +682,12 @@ export class tools extends plugin {
} }
// 工具根URL据下载视频 / 音频 // 工具根URL据下载视频 / 音频
async downloadVideo (url, isProxy = false, headers = null) { async downloadVideo(url, isProxy = false, headers = null) {
const groupPath = `${ this.defaultPath }${ this.e.group_id || this.e.user_id }`; const groupPath = `${this.defaultPath}${this.e.group_id || this.e.user_id}`;
if (!fs.existsSync(groupPath)) { if (!fs.existsSync(groupPath)) {
mkdirsSync(groupPath); mkdirsSync(groupPath);
} }
const target = `${ groupPath }/temp.mp4`; const target = `${groupPath}/temp.mp4`;
// 待优化 // 待优化
if (fs.existsSync(target)) { if (fs.existsSync(target)) {
console.log(`视频已存在`); console.log(`视频已存在`);
@ -703,7 +717,7 @@ export class tools extends plugin {
}), }),
}); });
} }
console.log(`开始下载: ${ url }`); console.log(`开始下载: ${url}`);
const writer = fs.createWriteStream(target); const writer = fs.createWriteStream(target);
res.data.pipe(writer); res.data.pipe(writer);
@ -714,7 +728,7 @@ export class tools extends plugin {
} }
// 工具找到tiktok的视频id // 工具找到tiktok的视频id
async getIdVideo (url) { async getIdVideo(url) {
const matching = url.includes("/video/"); const matching = url.includes("/video/");
if (!matching) { if (!matching) {
this.e.reply("没找到,正在获取随机视频!"); this.e.reply("没找到,正在获取随机视频!");

View File

@ -151,7 +151,7 @@ export class update extends plugin {
await this.reply( await this.reply(
msg + msg +
`存在冲突:\n${errMsg}\n` + `存在冲突:\n${errMsg}\n` +
"请解决冲突后再更新,或者执行#强制更新,放弃本地修改" "请解决冲突后再更新,或者执行#强制更新,放弃本地修改",
); );
} else if (stdout.includes("CONFLICT")) { } else if (stdout.includes("CONFLICT")) {
await this.reply([ await this.reply([