🌈 style: 代码格式化

This commit is contained in:
zhiyu1998 2022-11-25 20:12:18 +08:00
parent 20be1a51ab
commit f48dcc82da
7 changed files with 78 additions and 77 deletions

View File

@ -23,7 +23,7 @@ export class cat extends plugin {
async cat (e) { async cat (e) {
const numb = this.catConfig.count const numb = this.catConfig.count
let images = [] let images = []
let reqRes = [...await fetch(`https://shibe.online/api/cats?count=${numb}`).then(data => data.json()), ...await fetch(`https://api.thecatapi.com/v1/images/search?limit=${numb}`).then(data => data.json()).then(json => json.map(item => item.url))] let reqRes = [ ...await fetch(`https://shibe.online/api/cats?count=${ numb }`).then(data => data.json()), ...await fetch(`https://api.thecatapi.com/v1/images/search?limit=${ numb }`).then(data => data.json()).then(json => json.map(item => item.url)) ]
e.reply('涩图也不看了,就看猫是吧, 探索中...') e.reply('涩图也不看了,就看猫是吧, 探索中...')
reqRes.forEach(item => { reqRes.forEach(item => {
images.push({ images.push({

View File

@ -22,7 +22,7 @@ export class doctor extends plugin {
async doctor (e) { async doctor (e) {
let keyword = e.msg.split(' ')[1] let keyword = e.msg.split(' ')[1]
const url = `https://api2.dayi.org.cn/api/search2?keyword=${keyword}&pageNo=1&pageSize=10` const url = `https://api2.dayi.org.cn/api/search2?keyword=${ keyword }&pageNo=1&pageSize=10`
let res = await fetch(url) let res = await fetch(url)
.then((resp) => resp.json()) .then((resp) => resp.json())
.then((resp) => resp.list) .then((resp) => resp.list)
@ -30,15 +30,15 @@ export class doctor extends plugin {
for (const element of res) { for (const element of res) {
const title = this.removeTag(element.title) const title = this.removeTag(element.title)
const template = ` const template = `
${title}\n ${ title }\n
标签${element.secondTitle}\n 标签${ element.secondTitle }\n
介绍${element.introduction} 介绍${ element.introduction }
` `
// 如果完全匹配,直接响应页面 // 如果完全匹配,直接响应页面
if (title === keyword) { if (title === keyword) {
const browser = await puppeteer.browserInit() const browser = await puppeteer.browserInit()
const page = await browser.newPage() const page = await browser.newPage()
await page.goto(`https://www.dayi.org.cn/drug/${element.id}`) await page.goto(`https://www.dayi.org.cn/drug/${ element.id }`)
let buff = await page.screenshot({ let buff = await page.screenshot({
fullPage: true, type: 'jpeg', omitBackground: false, quality: 90 fullPage: true, type: 'jpeg', omitBackground: false, quality: 90
}) })
@ -46,7 +46,7 @@ export class doctor extends plugin {
await e.reply(segment.image(buff)) await e.reply(segment.image(buff))
} }
msg.push({ msg.push({
message: { type: 'text', text: `${template}` }, nickname: Bot.nickname, user_id: Bot.uin message: { type: 'text', text: `${ template }` }, nickname: Bot.nickname, user_id: Bot.uin
}) })
} }
/** 最后回复消息 */ /** 最后回复消息 */

View File

@ -68,13 +68,13 @@ export class hotSearch extends plugin {
.catch((err) => logger.error(err)) .catch((err) => logger.error(err))
res.forEach((element) => { res.forEach((element) => {
const template = ` const template = `
标题${element.title}\n 标题${ element.title }\n
简介${_.isNull(element.desc) ? '' : element.desc}\n 简介${ _.isNull(element.desc) ? '' : element.desc }\n
热度${element.hot}\n 热度${ element.hot }\n
访问详情${element.url}\n 访问详情${ element.url }\n
` `
msg.push({ msg.push({
message: { type: 'text', text: `${template}` }, nickname: Bot.nickname, user_id: Bot.uin message: { type: 'text', text: `${ template }` }, nickname: Bot.nickname, user_id: Bot.uin
}) })
}) })
return !!this.reply(await Bot.makeForwardMsg(msg)) return !!this.reply(await Bot.makeForwardMsg(msg))

View File

@ -23,6 +23,7 @@ function initMongo () {
}) })
}) })
} }
const mongo = initMongo() const mongo = initMongo()
// 60s后撤回 // 60s后撤回
const recallTime = 109 const recallTime = 109
@ -61,7 +62,7 @@ export class mystery extends plugin {
this.e.reply = async function (msgs, quote, data) { this.e.reply = async function (msgs, quote, data) {
if (!msgs) return false if (!msgs) return false
if (!Array.isArray(msgs)) msgs = [msgs] if (!Array.isArray(msgs)) msgs = [ msgs ]
let result = await oldReply(msgs, quote, data) let result = await oldReply(msgs, quote, data)
if (!result || !result.message_id) { if (!result || !result.message_id) {
@ -77,9 +78,9 @@ export class mystery extends plugin {
if (isxml) { if (isxml) {
result = await oldReply(msgs, quote, data) result = await oldReply(msgs, quote, data)
} else { } else {
let MsgList = [{ let MsgList = [ {
message: msgs, nickname: Bot.nickname, user_id: Bot.uin message: msgs, nickname: Bot.nickname, user_id: Bot.uin
}] } ]
let forwardMsg = await Bot.makeForwardMsg(MsgList) let forwardMsg = await Bot.makeForwardMsg(MsgList)
@ -114,7 +115,7 @@ export class mystery extends plugin {
// 请求 // 请求
let images = [] let images = []
let imgData = [] let imgData = []
let url = `https://www.cos6.net/wp-json/wp/v2/posts?page=${page}` let url = `https://www.cos6.net/wp-json/wp/v2/posts?page=${ page }`
await fetch(url) await fetch(url)
.then((resp) => { .then((resp) => {
return resp.json() return resp.json()
@ -151,7 +152,7 @@ export class mystery extends plugin {
} }
async cospro (e) { async cospro (e) {
let req = [...await fetch('https://imgapi.cn/cos2.php?return=jsonpro').then((resp) => resp.json()).then((json) => json.imgurls), ...await fetch('https://imgapi.cn/cos.php?return=jsonpro').then((resp) => resp.json()).then((json) => json.imgurls)] let req = [ ...await fetch('https://imgapi.cn/cos2.php?return=jsonpro').then((resp) => resp.json()).then((json) => json.imgurls), ...await fetch('https://imgapi.cn/cos.php?return=jsonpro').then((resp) => resp.json()).then((json) => json.imgurls) ]
e.reply('哪天克火掉一定是在这个群里面...') e.reply('哪天克火掉一定是在这个群里面...')
let images = [] let images = []
req.forEach(item => { req.forEach(item => {
@ -179,7 +180,7 @@ export class mystery extends plugin {
// 请求 // 请求
let images = [] let images = []
let imgData = [] let imgData = []
let url = `https://yingtall.com/wp-json/wp/v2/posts?page=${page}` let url = `https://yingtall.com/wp-json/wp/v2/posts?page=${ page }`
await fetch(url) await fetch(url)
.then((resp) => { .then((resp) => {
return resp.json() return resp.json()
@ -219,7 +220,7 @@ export class mystery extends plugin {
async setu (e) { async setu (e) {
const numb = this.mysteryConfig.setu.count const numb = this.mysteryConfig.setu.count
// 图源 // 图源
const urlList = ['https://iw233.cn/api.php?sort=random', 'https://iw233.cn/API/Random.php'] const urlList = [ 'https://iw233.cn/api.php?sort=random', 'https://iw233.cn/API/Random.php' ]
e.reply('探索中...') e.reply('探索中...')
let images = [] let images = []
for (let i = numb; i > 0; i--) { for (let i = numb; i > 0; i--) {
@ -241,7 +242,7 @@ export class mystery extends plugin {
nickname: this.e.sender.card || this.e.user_id, user_id: this.e.user_id nickname: this.e.sender.card || this.e.user_id, user_id: this.e.user_id
} }
await mongo.then(conn => { await mongo.then(conn => {
return conn.aggregate([{ $sample: { size: MAX_SIZE } }]).toArray() return conn.aggregate([ { $sample: { size: MAX_SIZE } } ]).toArray()
}).then((result) => { }).then((result) => {
result.forEach((item) => { result.forEach((item) => {
images.push({ images.push({

View File

@ -30,9 +30,9 @@ export class recommend extends plugin {
res = await res.json() res = await res.json()
let msg = [] let msg = []
res.data.list.forEach((element) => { res.data.list.forEach((element) => {
const template = `推荐软件:${element.title}\n地址:${element.url}\n` const template = `推荐软件:${ element.title }\n地址:${ element.url }\n`
msg.push({ msg.push({
message: { type: 'text', text: `${template}` }, nickname: Bot.nickname, user_id: Bot.uin message: { type: 'text', text: `${ template }` }, nickname: Bot.nickname, user_id: Bot.uin
}) })
}) })
/** 最后回复消息 */ /** 最后回复消息 */
@ -45,9 +45,9 @@ export class recommend extends plugin {
res = await res.json() res = await res.json()
let msg = [] let msg = []
res.data.list.forEach((element) => { res.data.list.forEach((element) => {
const template = `推荐软件:${element.title}\n地址:${element.url}\n` const template = `推荐软件:${ element.title }\n地址:${ element.url }\n`
msg.push({ msg.push({
message: { type: 'text', text: `${template}` }, nickname: Bot.nickname, user_id: Bot.uin message: { type: 'text', text: `${ template }` }, nickname: Bot.nickname, user_id: Bot.uin
}) })
}) })
return !!this.reply(await Bot.makeForwardMsg(msg)) return !!this.reply(await Bot.makeForwardMsg(msg))

View File

@ -1,14 +1,14 @@
// 主库 // 主库
import fetch from "node-fetch"; import fetch from "node-fetch";
import fs from "node:fs"; import fs from "node:fs";
import {segment} from "oicq"; import { segment } from "oicq";
// 其他库 // 其他库
import md5 from "md5"; import md5 from "md5";
import axios from "axios"; import axios from "axios";
import path from 'path' import path from 'path'
export class tools extends plugin { export class tools extends plugin {
constructor() { constructor () {
super({ super({
name: "工具和学习类", name: "工具和学习类",
dsc: "工具相关指令", dsc: "工具相关指令",
@ -33,25 +33,25 @@ export class tools extends plugin {
} }
// 翻译插件 // 翻译插件
async trans(e) { async trans (e) {
let place = e.msg.replace(/#|翻译/g, "").trim(); let place = e.msg.replace(/#|翻译/g, "").trim();
let url = /[\u4E00-\u9FFF]+/g.test(place) let url = /[\u4E00-\u9FFF]+/g.test(place)
? `http://api.fanyi.baidu.com/api/trans/vip/translate?from=zh&to=en&appid=20210422000794040&salt=542716863&sign=${md5( ? `http://api.fanyi.baidu.com/api/trans/vip/translate?from=zh&to=en&appid=20210422000794040&salt=542716863&sign=${ md5(
"20210422000794040" + place + "542716863" + "HooD_ndgwcGH6SAnxGrM" "20210422000794040" + place + "542716863" + "HooD_ndgwcGH6SAnxGrM"
)}&q=${place}` ) }&q=${ place }`
: `http://api.fanyi.baidu.com/api/trans/vip/translate?from=en&to=zh&appid=20210422000794040&salt=542716863&sign=${md5( : `http://api.fanyi.baidu.com/api/trans/vip/translate?from=en&to=zh&appid=20210422000794040&salt=542716863&sign=${ md5(
"20210422000794040" + place + "542716863" + "HooD_ndgwcGH6SAnxGrM" "20210422000794040" + place + "542716863" + "HooD_ndgwcGH6SAnxGrM"
)}&q=${place}`; ) }&q=${ place }`;
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];
e.reply("识别:抖音, 解析中..."); e.reply("识别:抖音, 解析中...");
@ -59,14 +59,14 @@ export class tools extends plugin {
await this.douyinRequest(douUrl).then((res) => { await this.douyinRequest(douUrl).then((res) => {
const douRex = /.*video\/(\d+)\/(.*?)/g; const douRex = /.*video\/(\d+)\/(.*?)/g;
const douId = douRex.exec(res)[1]; const douId = douRex.exec(res)[1];
const url = `https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids=${douId}`; const url = `https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids=${ douId }`;
return fetch(url) return fetch(url)
.then((resp) => resp.json()) .then((resp) => resp.json())
.then((json) => json.item_list[0]) .then((json) => json.item_list[0])
.then((item) => item.video.play_addr.url_list[0]) .then((item) => item.video.play_addr.url_list[0])
.then((url) => { .then((url) => {
this.downloadVideo(url).then(video => { this.downloadVideo(url).then(video => {
e.reply(segment.video(`${this.defaultPath}${this.e.group_id || this.e.user_id}/temp.mp4`)); e.reply(segment.video(`${ this.defaultPath }${ this.e.group_id || this.e.user_id }/temp.mp4`));
}) })
}); });
}); });
@ -74,24 +74,24 @@ export class tools extends plugin {
} }
// 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 url = urlRex.exec(e.msg.trim())[0] const url = urlRex.exec(e.msg.trim())[0]
const tiktokApi = `https://api.douyin.wtf/api?url=${url}&minimal=true` const tiktokApi = `https://api.douyin.wtf/api?url=${ url }&minimal=true`
e.reply("识别tiktok, 解析中..."); e.reply("识别tiktok, 解析中...");
fetch(tiktokApi) fetch(tiktokApi)
.then(resp => resp.json()) .then(resp => resp.json())
.then(json => { .then(json => {
this.downloadVideo(json.wm_video_url.replace("https", "http")).then(video => { this.downloadVideo(json.wm_video_url.replace("https", "http")).then(video => {
e.reply(segment.video(`${this.defaultPath}${this.e.group_id || this.e.user_id}/temp.mp4`)) e.reply(segment.video(`${ this.defaultPath }${ this.e.group_id || this.e.user_id }/temp.mp4`))
}) })
}) })
return true return true
} }
// 请求参数 // 请求参数
async douyinRequest(url) { async douyinRequest (url) {
const params = { const params = {
headers: { headers: {
"User-Agent": "User-Agent":
@ -113,11 +113,11 @@ export class tools extends plugin {
} }
// 根URL据下载视频 / 音频 // 根URL据下载视频 / 音频
async downloadVideo(url) { async downloadVideo (url) {
if (!fs.existsSync(this.defaultPath)) { if (!fs.existsSync(this.defaultPath)) {
this.mkdirsSync(this.defaultPath); this.mkdirsSync(this.defaultPath);
} }
const target = this.defaultPath + `${this.e.group_id || this.e.user_id}/temp.mp4` const target = this.defaultPath + `${ this.e.group_id || this.e.user_id }/temp.mp4`
// 待优化 // 待优化
if (fs.existsSync(target)) { if (fs.existsSync(target)) {
console.log(`视频已存在`); console.log(`视频已存在`);
@ -130,7 +130,7 @@ export class tools extends plugin {
}, },
responseType: "stream", responseType: "stream",
}); });
console.log(`开始下载: ${url}`); console.log(`开始下载: ${ url }`);
const writer = fs.createWriteStream(target); const writer = fs.createWriteStream(target);
res.data.pipe(writer); res.data.pipe(writer);
@ -141,7 +141,7 @@ export class tools extends plugin {
} }
// 同步递归创建文件夹 // 同步递归创建文件夹
mkdirsSync(dirname) { mkdirsSync (dirname) {
if (fs.existsSync(dirname)) { if (fs.existsSync(dirname)) {
return true; return true;
} else { } else {
@ -153,7 +153,7 @@ export class tools extends plugin {
} }
// 递归创建目录 异步方法 // 递归创建目录 异步方法
mkdirs(dirname, callback) { mkdirs (dirname, callback) {
fs.exists(dirname, function (exists) { fs.exists(dirname, function (exists) {
if (exists) { if (exists) {
callback(); callback();