diff --git a/.puppeteerrc.cjs b/.puppeteerrc.cjs index c3875f5..25a6268 100644 --- a/.puppeteerrc.cjs +++ b/.puppeteerrc.cjs @@ -1,31 +1,31 @@ -const os = require("os"); -const { existsSync } = require("fs"); -const arch = os.arch(); -let skipDownload = false; -let executablePath; - -// win32 存在 Edge 优先选择 -if (process.platform == "win32") { - if (existsSync("C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe")) { - skipDownload = true; - executablePath = "C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe"; - } -} else if (process.platform == "linux") { - // 如果 arm64 架构且存在 Chromium,跳过下载 - if ((arch == "arm64" || arch == "aarch64") && existsSync("/usr/bin/chromium")) { - skipDownload = true; - executablePath = "/usr/bin/chromium"; - } else if (existsSync("/usr/bin/chromium")) { - // 不论什么架构,如果存在 Chromium,跳过下载且配置路径 - skipDownload = true; - executablePath = "/usr/bin/chromium"; - } -} - -/** - * @type {import("puppeteer").Configuration} - */ -module.exports = { - skipDownload, - executablePath, -}; +const os = require("os"); +const { existsSync } = require("fs"); +const arch = os.arch(); +let skipDownload = false; +let executablePath; + +// win32 存在 Edge 优先选择 +if (process.platform == "win32") { + if (existsSync("C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe")) { + skipDownload = true; + executablePath = "C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe"; + } +} else if (process.platform == "linux") { + // 如果 arm64 架构且存在 Chromium,跳过下载 + if ((arch == "arm64" || arch == "aarch64") && existsSync("/usr/bin/chromium")) { + skipDownload = true; + executablePath = "/usr/bin/chromium"; + } else if (existsSync("/usr/bin/chromium")) { + // 不论什么架构,如果存在 Chromium,跳过下载且配置路径 + skipDownload = true; + executablePath = "/usr/bin/chromium"; + } +} + +/** + * @type {import("puppeteer").Configuration} + */ +module.exports = { + skipDownload, + executablePath, +}; \ No newline at end of file diff --git a/package.json b/package.json index 6b1217e..2e32221 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,6 @@ }, "dependencies": { "art-template": "^4.13.2", - "axios": "^1.4.0", "chalk": "^5.2.0", "chokidar": "^3.5.3", "https-proxy-agent": "5.0.1", diff --git a/plugins/genshin/apps/takeBirthdayPhoto.js b/plugins/genshin/apps/takeBirthdayPhoto.js index 68d8c34..e99c9cb 100644 --- a/plugins/genshin/apps/takeBirthdayPhoto.js +++ b/plugins/genshin/apps/takeBirthdayPhoto.js @@ -1,19 +1,6 @@ import plugin from '../../../lib/plugins/plugin.js' import gsCfg from '../model/gsCfg.js' -// import axios from 'axios' -let axios = null -let getAxios = async function () { - if (axios) { - return axios - } - try { - axios = (await import('axios')).default - } catch (e) { - console.log('未安装依赖axios...') - return false - } - return axios -} +import fetch from 'node-fetch' export class takeBirthdayPhoto extends plugin { constructor () { @@ -60,10 +47,10 @@ export class takeBirthdayPhoto extends plugin { return true } - for (let role of birthday_star_list) { + for (const role of birthday_star_list) { await e.reply(`正在获取${role.name}的图片,请稍等~`, true) await e.reply(segment.image(role.take_picture)) - let message = await this.getBirthdayStarImg(userInfo.uid, e_hk4e_token, userInfo.ck, role.role_id) + const message = await this.getBirthdayStarImg(userInfo.uid, e_hk4e_token, userInfo.ck, role.role_id) if (message != 'success') { await e.reply(message) return true @@ -85,7 +72,7 @@ export class takeBirthdayPhoto extends plugin { const url = isCN ? 'https://api-takumi.mihoyo.com/common/badge/v1/login/account' : 'https://api-os-takumi.mihoyo.com/common/badge/v1/login/account' const game_biz = isCN ? 'hk4e_cn' : 'hk4e_global' const region = await this.getServer(uid) - const header = { + const headers = { 'Cookie': ck, 'Content-Type': 'application/json;charset=UTF-8', 'Referer': 'https://webstatic.mihoyo.com/', @@ -97,15 +84,12 @@ export class takeBirthdayPhoto extends plugin { lang: 'zh-cn', region: region }) - let axios = await getAxios() - if (!axios) { + let res = await fetch(url, { method: "POST", body, headers }) + const e_hk4e_token = res.headers.get('set-cookie').match(/e_hk4e_token=(.*?);/)[1] + res = await res.json() + if (res.retcode != 0) { return false } - let res = await axios.post(url, body, { headers: header }) - if (res.data.retcode != 0) { - return false - } - let e_hk4e_token = res.headers['set-cookie'].toString().match(/e_hk4e_token=(.*?);/)[1] return e_hk4e_token } @@ -129,38 +113,29 @@ export class takeBirthdayPhoto extends plugin { } async getBirthdayStar (uid, e_hk4e_token, ck) { - let cookie = `e_hk4e_token=${e_hk4e_token};${ck}` - let badge_region = await this.getServer(uid) - let isCN = uid.toString().match(/^[125]/) ? true : false - let game_biz = isCN ? 'hk4e_cn' : 'hk4e_global' - let header = { - 'Cookie': cookie - } - let url = `https://hk4e-api.mihoyo.com/event/birthdaystar/account/index?lang=zh-cn&badge_uid=${uid}&badge_region=${badge_region}&game_biz=${game_biz}&activity_id=20220301153521` - let axios = await getAxios() - if (!axios) { - return false - } - let res = await axios.get(url, { headers: header }) - return res.data.data.role + const cookie = `e_hk4e_token=${e_hk4e_token};${ck}` + const badge_region = await this.getServer(uid) + const isCN = uid.toString().match(/^[125]/) ? true : false + const game_biz = isCN ? 'hk4e_cn' : 'hk4e_global' + const headers = { 'Cookie': cookie } + const url = `https://hk4e-api.mihoyo.com/event/birthdaystar/account/index?lang=zh-cn&badge_uid=${uid}&badge_region=${badge_region}&game_biz=${game_biz}&activity_id=20220301153521` + let res = await fetch(url, { headers }) + res = await res.json() + return res.data.role } async getBirthdayStarImg (uid, e_hk4e_token, ck, role_id) { - let cookie = `e_hk4e_token=${e_hk4e_token};${ck}` - let badge_region = await this.getServer(uid) - let isCN = uid.toString().match(/^[125]/) ? true : false - let game_biz = isCN ? 'hk4e_cn' : 'hk4e_global' - let header = { - 'Cookie': cookie - } - let url = `https://hk4e-api.mihoyo.com/event/birthdaystar/account/post_my_draw?lang=zh-cn&badge_uid=${uid}&badge_region=${badge_region}&game_biz=${game_biz}&activity_id=20220301153521` - let axios = await getAxios() - if (!axios) { - return false - } - let res = await axios.post(url, { role_id: Number(role_id) }, { headers: header }) - if (res.data.retcode != 0) { - return res.data.message + const cookie = `e_hk4e_token=${e_hk4e_token};${ck}` + const badge_region = await this.getServer(uid) + const isCN = uid.toString().match(/^[125]/) ? true : false + const game_biz = isCN ? 'hk4e_cn' : 'hk4e_global' + const headers = { 'Cookie': cookie } + const url = `https://hk4e-api.mihoyo.com/event/birthdaystar/account/post_my_draw?lang=zh-cn&badge_uid=${uid}&badge_region=${badge_region}&game_biz=${game_biz}&activity_id=20220301153521` + const body = JSON.stringify({ role_id: Number(role_id) }) + let res = await fetch(url, { method: "POST", body, headers }) + res = await res.json() + if (res.retcode != 0) { + return res.message } else { return 'success' }