From 4e4c79ee7070f76198851055592678326f7f9f50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=83=E5=A5=88=E5=8D=83=E7=A5=81?= <12279051+qiannqq@user.noreply.gitee.com> Date: Mon, 31 Jul 2023 12:00:56 +0000 Subject: [PATCH 01/12] =?UTF-8?q?=E9=A6=96=E6=AC=A1=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E6=88=96=E4=BF=AE=E6=94=B9=E8=B4=A6=E5=8F=B7=E6=97=B6=E5=8F=AF?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E7=AD=BE=E5=90=8DAPI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 千奈千祁 <12279051+qiannqq@user.noreply.gitee.com> --- lib/config/qq.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/config/qq.js b/lib/config/qq.js index 2a30c70..86b8761 100644 --- a/lib/config/qq.js +++ b/lib/config/qq.js @@ -61,6 +61,11 @@ export default async function createQQ () { name: 'masterQQ' }) } + propmtList.push({ + type: 'input', + message: '请输入签名API地址(可留空):', + name: 'signAPI' + }) const ret = await inquirer.prompt(propmtList) let file = './config/config/' @@ -82,6 +87,10 @@ export default async function createQQ () { fs.writeFileSync(`${file}other.yaml`, other, 'utf8') } + if (ret.signAPI) { + bot = bot.replace(/sign_api_addr:\s*/, `sign_api_addr: ${ret.signAPI}`); + } + fs.writeFileSync(`${file}bot.yaml`, bot, 'utf8') console.log(`\nQQ配置完成,正在登录\n后续修改账号可以运行命令: ${chalk.green('node app login')}\n`) From 815613bbbe2994ff4f722a17706c142b1e7fb6a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B8=AE=E5=B8=AE?= <3102509561@qq.com> Date: Sat, 5 Aug 2023 11:38:26 +0000 Subject: [PATCH 02/12] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=E5=85=AC=E5=91=8A?= =?UTF-8?q?=E6=8E=A8=E9=80=81=E6=A0=87=E9=A2=98=E9=87=8D=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 帮帮 <3102509561@qq.com> --- plugins/genshin/apps/mysNews.js | 2 ++ plugins/genshin/model/mysNews.js | 7 +++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/plugins/genshin/apps/mysNews.js b/plugins/genshin/apps/mysNews.js index 7c5eb19..850fc17 100644 --- a/plugins/genshin/apps/mysNews.js +++ b/plugins/genshin/apps/mysNews.js @@ -126,6 +126,8 @@ export class mysNews extends plugin { model = '关闭' msg += `${model}` cfg[type][this.e.self_id] = lodash.difference(cfg[type][this.e.self_id], [this.e.group_id]) + if (lodash.isEmpty(cfg[type][this.e.self_id])) + delete cfg[type][this.e.self_id] } let yaml = YAML.stringify(cfg) diff --git a/plugins/genshin/model/mysNews.js b/plugins/genshin/model/mysNews.js index 96132c6..be5f601 100644 --- a/plugins/genshin/model/mysNews.js +++ b/plugins/genshin/model/mysNews.js @@ -257,14 +257,13 @@ export default class MysNews extends base { return this.replyMsg(img, `${param.data.post.subject}`) } - replyMsg(img, title = '') { + replyMsg(img, title) { if (!img || img.length <= 0) return false if (img.length == 1) { - if (title) img.unshift(title) + if (title) return [title, ...img] return img - } else { - return common.makeForwardMsg(this.e, img, title) } + return common.makeForwardMsg(this.e, img, title) } async mysNewsTask() { From 48bc682e5742dd28b80ff058de1815abc3fc2e58 Mon Sep 17 00:00:00 2001 From: touchscale <11134128+touchscale_admin@user.noreply.gitee.com> Date: Sat, 5 Aug 2023 16:49:33 +0000 Subject: [PATCH 03/12] =?UTF-8?q?icqq=E6=9B=B4=E6=96=B0=E8=87=B30.4.13?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: touchscale <11134128+touchscale_admin@user.noreply.gitee.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4faa8dc..2e32221 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "chalk": "^5.2.0", "chokidar": "^3.5.3", "https-proxy-agent": "5.0.1", - "icqq": "^0.4.12", + "icqq": "^0.4.13", "image-size": "^1.0.2", "inquirer": "^8.2.5", "lodash": "^4.17.21", From 9b9ec42ffabd596422effda3776d91d535d1c2ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=97=B6=E9=9B=A8=E2=97=8E=E6=98=9F=E7=A9=BA?= Date: Sun, 6 Aug 2023 15:01:56 +0800 Subject: [PATCH 04/12] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=E7=B1=B3=E6=B8=B8?= =?UTF-8?q?=E7=A4=BE=E5=85=AC=E5=91=8A=20=E9=87=8D=E5=A4=8D=E6=A0=87?= =?UTF-8?q?=E9=A2=98=20(#219)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 修复 米游社公告 重复标题 * 优化 日志 --- plugins/other/sendLog.js | 77 +++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 41 deletions(-) diff --git a/plugins/other/sendLog.js b/plugins/other/sendLog.js index 6fbd113..9b7d83b 100644 --- a/plugins/other/sendLog.js +++ b/plugins/other/sendLog.js @@ -1,29 +1,29 @@ -import plugin from '../../lib/plugins/plugin.js' -import common from '../../lib/common/common.js' -import fs from 'node:fs' -import lodash from 'lodash' -import moment from 'moment' +import plugin from "../../lib/plugins/plugin.js" +import common from "../../lib/common/common.js" +import fs from "node:fs" +import lodash from "lodash" +import moment from "moment" export class sendLog extends plugin { constructor() { super({ - name: '发送日志', - dsc: '发送最近100条运行日志', - event: 'message', + name: "发送日志", + dsc: "发送最近100条运行日志", + event: "message", rule: [ { - reg: '^#(运行|错误)*日志[0-9]*(.*)', - fnc: 'sendLog', - permission: 'master' + reg: "^#(运行|错误)*日志[0-9]*(.*)", + fnc: "sendLog", + permission: "master" } ] }) - this.lineNum = 50 - this.maxNum = 800 + this.lineNum = 100 + this.maxNum = 1000 - this.logFile = `./logs/command.${moment().format('YYYY-MM-DD')}.log` - this.errFile = './logs/error.log' + this.logFile = `logs/command.${moment().format("YYYY-MM-DD")}.log` + this.errFile = "logs/error.log" } async sendLog() { @@ -31,53 +31,48 @@ export class sendLog extends plugin { if (lineNum) { this.lineNum = lineNum[0] } else { - this.keyWord = this.e.msg.replace(/#|运行|错误|日志|\d/g, '') + this.keyWord = this.e.msg.replace(/#|运行|错误|日志|\d/g, "") } let logFile = this.logFile - let type = '运行' - if (this.e.msg.includes('错误')) { + let type = "运行" + if (this.e.msg.includes("错误")) { logFile = this.errFile - type = '错误' + type = "错误" } if (this.keyWord) type = this.keyWord - let log = this.getLog(logFile) + const log = this.getLog(logFile) - if (lodash.isEmpty(log)) { - this.reply(`暂无相关日志:${type}`) - return - } - let title = `最近${log.length}条${type}日志` + if (lodash.isEmpty(log)) + return this.reply(`暂无相关日志:${type}`) - let forwardMsg = await common.makeForwardMsg(this.e, [title, log.join("")], title) - - await this.reply(forwardMsg) + return this.reply(await common.makeForwardMsg(this.e, [log.join("\n")], `最近${log.length}条${type}日志`)) } getLog(logFile) { - let log = fs.readFileSync(logFile, { encoding: 'utf-8' }) - log = log.split('\n') + let log = fs.readFileSync(logFile, { encoding: "utf-8" }) + log = log.split("\n") if (this.keyWord) { - for (let i in log) { - if (!log[i].includes(this.keyWord)) delete log[i] - } + for (const i in log) + if (!log[i].includes(this.keyWord)) + delete log[i] } else { log = lodash.slice(log, (Number(this.lineNum) + 1) * -1) } log = log.reverse() - let tmp = [] - log.forEach(v => { - if (!v) return + + const tmp = [] + for (let i of log) { + if (!i) continue if (this.keyWord && tmp.length >= this.maxNum) return /* eslint-disable no-control-regex */ - v = v.replace(/\x1b[[0-9;]*m/g, '') - v = v.replace(/\r|\n/, '') + '\n\n' - tmp.push(v) - }) - + i = i.replace(/\x1b[[0-9;]*m/g, "") + i = i.replace(/\r|\n/, "") + tmp.push(i) + } return tmp } } From 30e1b1be9a52c4cc91c7687cce2fa72c60077a16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=80=E6=9C=89=E4=BA=8C=E5=88=BA=E8=9E=88=E9=83=BD?= =?UTF-8?q?=E5=BE=97=E6=AD=BB?= <321107534@qq.com> Date: Mon, 7 Aug 2023 02:53:43 +0000 Subject: [PATCH 05/12] =?UTF-8?q?=E4=BF=AE=E5=A4=8Darm64=E4=B8=80=E7=9B=B4?= =?UTF-8?q?=E8=B7=B3=E8=BF=87=E4=B8=8B=E8=BD=BDchromium=20=E5=8E=9F?= =?UTF-8?q?=E6=9C=AC=E7=9A=84=E4=BB=A3=E7=A0=81=E4=B8=BA=E5=8F=AA=E8=A6=81?= =?UTF-8?q?=E8=AE=BE=E5=A4=87=E4=B8=BAarm64=E5=B0=B1=E4=BC=9A=E4=B8=80?= =?UTF-8?q?=E7=9B=B4=E8=B7=B3=E8=BF=87=E4=B8=8B=E8=BD=BD=EF=BC=8C=E6=97=A0?= =?UTF-8?q?=E8=AE=BA=E6=98=AF=E4=BD=BF=E7=94=A8pnpm=20i=20puppeteer=20-w?= =?UTF-8?q?=E8=BF=98=E6=98=AFnode=20node=5Fmodules/puppeteer/install.js?= =?UTF-8?q?=EF=BC=8C=E9=83=BD=E6=97=A0=E6=B3=95=E5=AE=89=E8=A3=85=E6=B5=8F?= =?UTF-8?q?=E8=A7=88=E5=99=A8=EF=BC=8C=E5=8F=AA=E8=83=BD=E6=89=8B=E5=8A=A8?= =?UTF-8?q?=E5=8F=A6=E5=A4=96=E5=AE=89=E8=A3=85=E5=AE=8C=E6=95=B4chrome=20?= =?UTF-8?q?=E7=8E=B0=E5=9C=A8=E4=BF=AE=E6=94=B9=E4=B8=BAarm64=E6=A3=80?= =?UTF-8?q?=E6=B5=8B=E5=88=B0=E5=AE=89=E8=A3=85=E8=BF=87chromium=E6=89=8D?= =?UTF-8?q?=E4=BC=9A=E8=B7=B3=E8=BF=87=E4=B8=8B=E8=BD=BD=EF=BC=8C=E6=96=B9?= =?UTF-8?q?=E4=BE=BF=E5=AE=89=E8=A3=85puppeteer=E5=B8=A6=E7=9A=84chromium?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 所有二刺螈都得死 <321107534@qq.com> --- .puppeteerrc.cjs | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/.puppeteerrc.cjs b/.puppeteerrc.cjs index 253d90c..c3875f5 100644 --- a/.puppeteerrc.cjs +++ b/.puppeteerrc.cjs @@ -3,22 +3,20 @@ const { existsSync } = require("fs"); const arch = os.arch(); let skipDownload = false; let executablePath; -//win32 存在 Edge 优先选择 + +// win32 存在 Edge 优先选择 if (process.platform == "win32") { - if ( - existsSync("C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe") - ) { + if (existsSync("C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe")) { skipDownload = true; - executablePath = - "C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe"; + executablePath = "C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe"; } } else if (process.platform == "linux") { - //如果arm64架构跳过下载 - if (arch == "arm64" || arch == "aarch64") { + // 如果 arm64 架构且存在 Chromium,跳过下载 + if ((arch == "arm64" || arch == "aarch64") && existsSync("/usr/bin/chromium")) { skipDownload = true; - } - //不管什么架构,如果存在配置则跳过下载,且配置路径 - if (existsSync("/usr/bin/chromium")) { + executablePath = "/usr/bin/chromium"; + } else if (existsSync("/usr/bin/chromium")) { + // 不论什么架构,如果存在 Chromium,跳过下载且配置路径 skipDownload = true; executablePath = "/usr/bin/chromium"; } @@ -30,4 +28,4 @@ if (process.platform == "win32") { module.exports = { skipDownload, executablePath, -}; \ No newline at end of file +}; From 993d42db8f4589d787c03c99c6d7bfa2529afe28 Mon Sep 17 00:00:00 2001 From: woxigousade Date: Thu, 10 Aug 2023 15:33:33 +0800 Subject: [PATCH 06/12] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E7=95=99?= =?UTF-8?q?=E5=BD=B1=E5=8F=99=E4=BD=B3=E6=9C=9F=E8=8E=B7=E5=8F=96=E7=94=9F?= =?UTF-8?q?=E6=97=A5=E8=A7=92=E8=89=B2=E7=9B=B8=E7=89=87=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/genshin/apps/takeBirthdayPhoto.js | 142 ++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 plugins/genshin/apps/takeBirthdayPhoto.js diff --git a/plugins/genshin/apps/takeBirthdayPhoto.js b/plugins/genshin/apps/takeBirthdayPhoto.js new file mode 100644 index 0000000..dea56c0 --- /dev/null +++ b/plugins/genshin/apps/takeBirthdayPhoto.js @@ -0,0 +1,142 @@ +import plugin from '../../../lib/plugins/plugin.js' +import gsCfg from '../model/gsCfg.js' +import axios from 'axios' + +export class takeBirthdayPhoto extends plugin { + constructor() { + super({ + name: '留影叙佳期', + dsc: '留影叙佳期', + /** https://oicqjs.github.io/oicq/#events */ + event: 'message', + priority: 5000, + rule: [ + { + /** 命令正则匹配 */ + reg: '#?留影叙佳期$', + /** 执行方法 */ + fnc: 'birthdaystar', + } + ] + }) + } + async birthdaystar(e) { + const { user_id } = e; + + const userInfo = await this.getCookie(user_id) + if (!userInfo) { + e.reply('请先绑定ck再使用本功能哦~', true); + return true; + } + + const e_hk4e_token = await this.getEHK4EToken(userInfo.ck, userInfo.uid) + if (!e_hk4e_token) { + e.reply('获取e-hk4e_token失败,请刷新ck后再试~', true); + return true; + } + + const birthday_star_list = await this.getBirthdayStar(userInfo.uid, e_hk4e_token, userInfo.ck); + if (!birthday_star_list) { + e.reply('获取生日角色失败,请稍后再试~', true); + return true; + } + + if (birthday_star_list.length === 0) { + e.reply('今天没有生日角色哦~', true); + return true; + } + + for (let 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) + if (message != 'success') { + await e.reply(message) + return true + } else { + await e.reply(`获取${role.name}的图片成功~`, true); + } + } + + return true + } + + async getCookie(user_id) { + const userInfo = ((await gsCfg.getBingCk()).ckQQ)[user_id] + return userInfo + } + + async getEHK4EToken(ck, uid) { + const isCN = uid.toString().match(/^[125]/) ? true : false; + 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 = { + 'Cookie': ck, + 'Content-Type': 'application/json;charset=UTF-8', + 'Referer': 'https://webstatic.mihoyo.com/', + 'Origin': 'https://webstatic.mihoyo.com' + } + const body = JSON.stringify({ + uid: Number(uid), + game_biz: game_biz, + lang: 'zh-cn', + region: region, + }) + 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 + } + + async getServer(uid) { + switch (String(uid)[0]) { + case '1': + case '2': + return 'cn_gf01' + case '5': + return 'cn_qd01' + case '6': + return 'os_usa' + case '7': + return 'os_euro' + case '8': + return 'os_asia' + case '9': + return 'os_cht' + } + return 'cn_gf01' + } + + 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 res = await axios.get(url, { headers: header }) + return res.data.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 res = await axios.post(url, { role_id: Number(role_id) }, { headers: header }) + if (res.data.retcode != 0) { + return res.data.message + } else { + return 'success' + } + } +} \ No newline at end of file From 6453edde0942470b1468cc93776a64a66a95de3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zyy=2E=E5=B0=8F=E9=92=B0?= <1072411694@qq.com> Date: Sat, 12 Aug 2023 11:19:27 +0000 Subject: [PATCH 07/12] =?UTF-8?q?=E9=80=82=E9=85=8D=E4=B8=8B=E9=A2=91?= =?UTF-8?q?=E9=81=93=E6=8F=92=E4=BB=B6=E8=BD=AC=E5=8F=91...=20[QQGuild-plu?= =?UTF-8?q?gin](https://gitee.com/Zyy955/QQGuild-plugin)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Zyy.小钰 <1072411694@qq.com> --- lib/common/common.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/common/common.js b/lib/common/common.js index 6de7879..9775360 100644 --- a/lib/common/common.js +++ b/lib/common/common.js @@ -67,6 +67,9 @@ function mkdirs(dirname) { * @param msgsscr 转发信息是否伪装 */ async function makeForwardMsg(e, msg = [], dec = '', msgsscr = false) { + /** 是频道插件直接返回 */ + if (e.QQGuild) return msg + if (!Array.isArray(msg)) msg = [msg] let name = msgsscr ? e.sender.card || e.user_id : Bot.nickname From 9df10b9bb4470dfc1d87cedb56be8baebf72b3b1 Mon Sep 17 00:00:00 2001 From: sameu Date: Mon, 14 Aug 2023 02:40:12 +0800 Subject: [PATCH 08/12] =?UTF-8?q?fix:=20=E8=A1=A8=E6=83=85=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=94=B9=E4=B8=BA=E6=AD=A3=E5=BA=8F=E8=BE=93=E5=87=BA?= =?UTF-8?q?=EF=BC=8C=E6=AF=8F=E4=B8=AA=E8=A1=A8=E6=83=85=E5=8D=95=E7=8B=AC?= =?UTF-8?q?=E4=B8=80=E6=9D=A1=E6=B6=88=E6=81=AF=20(#222)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/system/add.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/plugins/system/add.js b/plugins/system/add.js index 9568688..368bd51 100644 --- a/plugins/system/add.js +++ b/plugins/system/add.js @@ -712,16 +712,17 @@ export class add extends plugin { let keyWord = await this.keyWordTran(arr[i].key) if (!keyWord) continue - + let result = [] if (Array.isArray(keyWord)) { - keyWord.unshift(`${arr[i].num}、`) + keyWord.unshift(`${num + 1}、`) keyWord.push('\n') - keyWord.forEach(v => msg.push(v)) + result.push(...keyWord) } else if (keyWord.type) { - msg.push(`\n${arr[i].num}、`, keyWord, '\n\n') + result.push(`\n${num + 1}、`, keyWord, '\n\n') } else { - msg.push(`${arr[i].num}、${keyWord}\n`) + result.push(`${num + 1}、${keyWord}\n`) } + msg.push(result) num++ } @@ -734,7 +735,7 @@ export class add extends plugin { title = `表情${search},${count}条` } - let forwardMsg = await common.makeForwardMsg(this.e, [title, msg], title) + let forwardMsg = await common.makeForwardMsg(this.e, [title, ...msg], title) this.e.reply(forwardMsg) } @@ -778,4 +779,4 @@ export class add extends plugin { return msg } -} \ No newline at end of file +} From 418572110cb3ba8c04d2d68478f6deb785ae0198 Mon Sep 17 00:00:00 2001 From: Lawrence_XS Date: Mon, 14 Aug 2023 02:40:35 +0800 Subject: [PATCH 09/12] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=9C=A8=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E5=85=B3=E9=94=AE=E8=AF=8D=E4=B8=AD=E6=8C=87=E5=AE=9A?= =?UTF-8?q?=E6=95=B0=E5=AD=97=E5=A4=A7=E4=BA=8E9=E6=97=B6=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E6=AD=A3=E7=A1=AE=E8=AF=BB=E5=8F=96=E5=AF=B9=E5=BA=94?= =?UTF-8?q?=E6=98=A0=E5=B0=84=E5=85=B3=E7=B3=BB=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=20(#223)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/system/add.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/system/add.js b/plugins/system/add.js index 368bd51..a0cc7e7 100644 --- a/plugins/system/add.js +++ b/plugins/system/add.js @@ -395,7 +395,7 @@ export class add extends plugin { let num = 0 if (isNaN(keyWord)) { - num = keyWord.charAt(keyWord.length - 1) + num = keyWord.trim().match(/[0-9]+/g)[0] if (!isNaN(num) && !textArr[this.group_id].has(keyWord) && !textArr[this.e.bot.uin].has(keyWord)) { keyWord = lodash.trimEnd(keyWord, num).trim() From 070d54cd712e3e5d76f3bb2d8e6228b96ea7d290 Mon Sep 17 00:00:00 2001 From: Kokomi <102026640+yoimiya-kokomi@users.noreply.github.com> Date: Mon, 14 Aug 2023 04:15:44 +0800 Subject: [PATCH 10/12] =?UTF-8?q?=E5=AF=B9=E6=9C=AA=E5=AE=89=E8=A3=85axios?= =?UTF-8?q?=E4=BE=9D=E8=B5=96=E7=9A=84=E6=83=85=E5=86=B5=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=85=BC=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 + plugins/genshin/apps/takeBirthdayPhoto.js | 80 +++++++++++++++-------- 2 files changed, 54 insertions(+), 27 deletions(-) diff --git a/package.json b/package.json index 2e32221..6b1217e 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ }, "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 dea56c0..68d8c34 100644 --- a/plugins/genshin/apps/takeBirthdayPhoto.js +++ b/plugins/genshin/apps/takeBirthdayPhoto.js @@ -1,9 +1,22 @@ import plugin from '../../../lib/plugins/plugin.js' import gsCfg from '../model/gsCfg.js' -import axios from 'axios' +// 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 +} export class takeBirthdayPhoto extends plugin { - constructor() { + constructor () { super({ name: '留影叙佳期', dsc: '留影叙佳期', @@ -15,59 +28,60 @@ export class takeBirthdayPhoto extends plugin { /** 命令正则匹配 */ reg: '#?留影叙佳期$', /** 执行方法 */ - fnc: 'birthdaystar', + fnc: 'birthdaystar' } ] }) } - async birthdaystar(e) { - const { user_id } = e; + + async birthdaystar (e) { + const { user_id } = e const userInfo = await this.getCookie(user_id) if (!userInfo) { - e.reply('请先绑定ck再使用本功能哦~', true); - return true; + e.reply('请先绑定ck再使用本功能哦~', true) + return true } const e_hk4e_token = await this.getEHK4EToken(userInfo.ck, userInfo.uid) if (!e_hk4e_token) { - e.reply('获取e-hk4e_token失败,请刷新ck后再试~', true); - return true; + e.reply('获取e-hk4e_token失败,请刷新ck后再试~', true) + return true } - const birthday_star_list = await this.getBirthdayStar(userInfo.uid, e_hk4e_token, userInfo.ck); + const birthday_star_list = await this.getBirthdayStar(userInfo.uid, e_hk4e_token, userInfo.ck) if (!birthday_star_list) { - e.reply('获取生日角色失败,请稍后再试~', true); - return true; + e.reply('获取生日角色失败,请稍后再试~', true) + return true } if (birthday_star_list.length === 0) { - e.reply('今天没有生日角色哦~', true); - return true; + e.reply('今天没有生日角色哦~', true) + return true } for (let role of birthday_star_list) { - await e.reply(`正在获取${role.name}的图片,请稍等~`, true); + 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) if (message != 'success') { await e.reply(message) return true } else { - await e.reply(`获取${role.name}的图片成功~`, true); + await e.reply(`获取${role.name}的图片成功~`, true) } } return true } - async getCookie(user_id) { + async getCookie (user_id) { const userInfo = ((await gsCfg.getBingCk()).ckQQ)[user_id] return userInfo } - async getEHK4EToken(ck, uid) { - const isCN = uid.toString().match(/^[125]/) ? true : false; + async getEHK4EToken (ck, uid) { + const isCN = uid.toString().match(/^[125]/) ? true : false 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) @@ -81,8 +95,12 @@ export class takeBirthdayPhoto extends plugin { uid: Number(uid), game_biz: game_biz, lang: 'zh-cn', - region: region, + region: region }) + let axios = await getAxios() + if (!axios) { + return false + } let res = await axios.post(url, body, { headers: header }) if (res.data.retcode != 0) { return false @@ -91,7 +109,7 @@ export class takeBirthdayPhoto extends plugin { return e_hk4e_token } - async getServer(uid) { + async getServer (uid) { switch (String(uid)[0]) { case '1': case '2': @@ -110,28 +128,36 @@ export class takeBirthdayPhoto extends plugin { return 'cn_gf01' } - async getBirthdayStar(uid, e_hk4e_token, ck) { + 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 isCN = uid.toString().match(/^[125]/) ? true : false let game_biz = isCN ? 'hk4e_cn' : 'hk4e_global' let header = { - 'Cookie': cookie, + '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 } - async getBirthdayStarImg(uid, e_hk4e_token, ck, role_id) { + 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 isCN = uid.toString().match(/^[125]/) ? true : false let game_biz = isCN ? 'hk4e_cn' : 'hk4e_global' let header = { - 'Cookie': cookie, + '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 From cd818ed212becc94aea2f5c95f34f867c4b559be Mon Sep 17 00:00:00 2001 From: Kokomi <592981798@qq.com> Date: Mon, 14 Aug 2023 12:32:28 +0800 Subject: [PATCH 11/12] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E8=A1=A8=E6=83=85?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=94=99=E8=AF=AF=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/system/add.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/system/add.js b/plugins/system/add.js index a0cc7e7..dc750b7 100644 --- a/plugins/system/add.js +++ b/plugins/system/add.js @@ -395,7 +395,7 @@ export class add extends plugin { let num = 0 if (isNaN(keyWord)) { - num = keyWord.trim().match(/[0-9]+/g)[0] + num = keyWord.trim().match(/[0-9]+$/)?.[0] if (!isNaN(num) && !textArr[this.group_id].has(keyWord) && !textArr[this.e.bot.uin].has(keyWord)) { keyWord = lodash.trimEnd(keyWord, num).trim() From 233d027b9535c117aeddff2a20244b96f631ec6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=97=B6=E9=9B=A8=E2=97=8E=E6=98=9F=E7=A9=BA?= Date: Mon, 14 Aug 2023 13:09:35 +0800 Subject: [PATCH 12/12] =?UTF-8?q?=E7=BB=9F=E4=B8=80=E4=BD=BF=E7=94=A8=20no?= =?UTF-8?q?de-fetch=EF=BC=8C=E5=88=A0=E9=99=A4=20axios=20(#224)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .puppeteerrc.cjs | 62 ++++++++--------- package.json | 1 - plugins/genshin/apps/takeBirthdayPhoto.js | 81 ++++++++--------------- 3 files changed, 59 insertions(+), 85 deletions(-) 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' }