⚡️ 细节优化
This commit is contained in:
@@ -1,16 +1,12 @@
|
||||
import md5 from "md5"
|
||||
import _ from "lodash"
|
||||
import moment from "moment"
|
||||
import fs from "node:fs"
|
||||
import _fs from "node:fs/promises"
|
||||
import fs from "node:fs/promises"
|
||||
import v8 from "node:v8"
|
||||
import path from "path"
|
||||
import url from "url"
|
||||
import Config from "../../components/Config.js"
|
||||
import sendMsgMod from "./sendMsgMod.js"
|
||||
import request from "../request/request.js"
|
||||
import { promisify } from "util"
|
||||
import { pipeline } from "stream"
|
||||
|
||||
// 涩涩未开启文案
|
||||
const SWITCH_ERROR = "主人没有开放这个功能哦(*/ω\*)"
|
||||
@@ -149,52 +145,9 @@ export default new class extends sendMsgMod {
|
||||
ErrMsg = MsgTemplate ? MsgTemplate.replace(/{error}/g, ErrMsg) : ErrMsg
|
||||
return e.reply(ErrMsg)
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载保存文件
|
||||
* @param fileUrl 下载地址
|
||||
* @param savePath 保存路径
|
||||
* @param param
|
||||
*/
|
||||
async downFile(fileUrl, savePath, param = {}) {
|
||||
try {
|
||||
mkdirs(path.dirname(savePath))
|
||||
logger.debug(`[下载文件] ${fileUrl}`)
|
||||
const response = await request.get(fileUrl, param)
|
||||
const contentType = response.headers.get("Content-Type")
|
||||
let suffix = ".png"
|
||||
if (param.imgAutoSuffix && /image/.test(contentType)) {
|
||||
if (contentType && contentType === "image/jpeg") {
|
||||
suffix = ".jpg"
|
||||
}
|
||||
savePath = savePath + suffix
|
||||
}
|
||||
const streamPipeline = promisify(pipeline)
|
||||
await streamPipeline(response.body, fs.createWriteStream(savePath))
|
||||
if (param.imgAutoSuffix) {
|
||||
return savePath
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
} catch (err) {
|
||||
logger.error(`下载文件错误:${err}`)
|
||||
return false
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
let a = []
|
||||
try {
|
||||
a = v8.deserialize(await _fs.readFile(`${path.dirname(url.fileURLToPath(import.meta.url))}/../../.github/ISSUE_TEMPLATE/`)).map(i => i.toString("hex"))
|
||||
a = v8.deserialize(await fs.readFile(`${path.dirname(url.fileURLToPath(import.meta.url))}/../../.github/ISSUE_TEMPLATE/`)).map(i => i.toString("hex"))
|
||||
} catch (err) {}
|
||||
|
||||
function mkdirs(dirname) {
|
||||
if (fs.existsSync(dirname)) {
|
||||
return true
|
||||
} else {
|
||||
if (mkdirs(path.dirname(dirname))) {
|
||||
fs.mkdirSync(dirname)
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { formatDuration } from "../../tools/index.js"
|
||||
import { Plugin_Path } from "../../components/index.js"
|
||||
import { createRequire } from "module"
|
||||
import common from "../../lib/common/common.js"
|
||||
import { importColorThief, getImgPalette } from "./utils.js"
|
||||
const require = createRequire(import.meta.url)
|
||||
|
||||
@@ -11,8 +10,7 @@ export default async function getBotState(botList) {
|
||||
if (!bot?.uin) return ""
|
||||
// 头像
|
||||
const avatarUrl = bot.avatar || (Number(bot.uin) ? `https://q1.qlogo.cn/g?b=qq&s=0&nk=${bot.uin}` : "default")
|
||||
const avatarPath = Plugin_Path + `/temp/state/avatar_${i}`
|
||||
const avatar = await getAvatarColor(avatarUrl, avatarPath)
|
||||
const avatar = await getAvatarColor(avatarUrl)
|
||||
|
||||
const nickname = bot.nickname || "未知"
|
||||
const platform = bot.apk ? `${bot.apk.display} v${extractVersion(bot.apk.version)}` : bot.version?.version || "未知"
|
||||
@@ -53,16 +51,14 @@ function extractVersion(versionString) {
|
||||
return version
|
||||
}
|
||||
|
||||
async function getAvatarColor(url, path) {
|
||||
async function getAvatarColor(url) {
|
||||
const defaultAvatar = `${Plugin_Path}/resources/state/img/default_avatar.jpg`
|
||||
try {
|
||||
await importColorThief()
|
||||
if (url != "default") {
|
||||
path = await common.downFile(url, path, { imgAutoSuffix: true })
|
||||
} else {
|
||||
path = defaultAvatar
|
||||
if (url == "default") {
|
||||
url = defaultAvatar
|
||||
}
|
||||
let avatar = await getImgPalette(path)
|
||||
let avatar = await getImgPalette(url)
|
||||
return avatar
|
||||
} catch {
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user