From 9b43b98224e8066c41bc9a762c40dec36dcececc Mon Sep 17 00:00:00 2001 From: Qin Fandong Date: Mon, 6 Mar 2023 22:30:43 +0800 Subject: [PATCH] qq framework switched from oicq to icqq and fix #995 --- bot.js | 42 +++++++++++++++++------- config_defaults/setting.yml | 2 +- package-lock.json | 64 +++++++++++++++++-------------------- package.json | 5 ++- src/utils/oicq.js | 2 +- 5 files changed, 63 insertions(+), 52 deletions(-) diff --git a/bot.js b/bot.js index 4a4c26891..a9f7fbe90 100644 --- a/bot.js +++ b/bot.js @@ -1,5 +1,5 @@ +import { createClient } from "icqq"; import lodash from "lodash"; -import { createClient } from "oicq"; import { dispatch } from "#bot/dispatch"; import { init } from "#bot/init"; import { loadPlugins } from "#bot/plugin"; @@ -16,7 +16,9 @@ function create() { } for (const account of global.config.accounts) { - const bot = createClient(account.qq, { platform: account.platform, log_level: "debug", data_dir: global.oicqdir }); + // https://github.com/icqqjs/icqq#%E4%B8%8Eoicq2%E7%9A%84%E5%B7%AE%E5%BC%82 + //const bot = createClient(account.qq, { platform: account.platform, log_level: "debug", data_dir: global.oicqdir }); + const bot = createClient({ platform: account.platform, log_level: "debug", data_dir: global.oicqdir }); bot.account = account; bot.boardcast = boardcast.bind(null, bot); @@ -105,21 +107,14 @@ async function run() { bot.on(e, () => resolve()); } - bot.on("system.login.device", () => { - bot.logger.mark("输入密保手机收到的短信验证码后按下回车键继续。"); - bot.sendSmsCode(); - process.stdin.once("data", (input) => { - bot.submitSmsCode(input.toString()); - resolve(); - }); - }); bot.on("system.login.slider", () => { bot.logger.mark("输入滑动验证码请求中的 ticket 后按下回车键继续。"); process.stdin.once("data", (input) => { - bot.submitSlider(input.toString()); + bot.submitSlider(input.toString().trim()); resolve(); }); }); + bot.on("system.login.qrcode", () => { bot.logger.mark("手机扫码完成后按下回车键继续。"); process.stdin.once("data", () => { @@ -127,7 +122,30 @@ async function run() { resolve(); }); }); - bot.login(bot.account.password); + + bot.on("system.login.device", (e) => { + console.log("输入证方式(1:短信验证;2:扫码验证)。"); + process.stdin.once("data", (input) => { + if ("1" === input.toString().trim()) { + bot.logger.mark("输入密保手机收到的短信验证码后按下回车键继续。"); + bot.sendSmsCode(); + process.stdin.once("data", (input) => { + bot.submitSmsCode(input.toString().trim()); + resolve(); + }); + } else { + console.log("扫码完成后回车继续:" + e.url); + process.stdin.once("data", () => { + bot.login(); + resolve(); + }); + } + }); + }); + + // https://github.com/icqqjs/icqq#%E4%B8%8Eoicq2%E7%9A%84%E5%B7%AE%E5%BC%82 + //bot.login(bot.account.password); + bot.login(bot.account.qq, bot.account.password); }); } } diff --git a/config_defaults/setting.yml b/config_defaults/setting.yml index 9ab21a6b3..31a1d7025 100644 --- a/config_defaults/setting.yml +++ b/config_defaults/setting.yml @@ -17,7 +17,7 @@ accounts: - # QQ 号码 qq: 123456789 - # QQ 明文密码,为空( null )则使用扫码登录,推荐使用扫码登录 + # QQ 明文密码,为空( null )则使用扫码登录,推荐使用密码登录 #password: null password: zhimakaimen # 1:安卓手机、 2:aPad 、 3:安卓手表、 4:MacOS 、 5:iPad diff --git a/package-lock.json b/package-lock.json index c2e956852..1557c926f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,7 +7,6 @@ "": { "name": "adachi-bot", "version": "1.5.4", - "hasInstallScript": true, "license": "MIT", "dependencies": { "cross-env": "7.0.3", @@ -16,6 +15,7 @@ "figlet": "1.5.2", "fnv-plus": "1.3.1", "iconv-lite": "0.6.3", + "icqq": "0.0.28", "js-yaml": "4.1.0", "kind-of": "6.0.3", "lodash": "4.17.21", @@ -25,7 +25,6 @@ "moment-timezone": "0.5.41", "node-fetch": "3.3.0", "node-schedule": "2.1.1", - "oicq": "2.3.1", "p-limit": "4.0.0", "patch-package": "6.5.1", "pm2": "5.2.2", @@ -1246,12 +1245,13 @@ } }, "node_modules/axios": { - "version": "0.27.2", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.27.2.tgz", - "integrity": "sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==", + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.3.4.tgz", + "integrity": "sha512-toYm+Bsyl6VC5wSkfkbbNB6ROv7KY93PEBBL6xyDczaIHasAiv4wPqQ/c4RjoQzipxRD2W5g21cOqQulZ7rHwQ==", "dependencies": { - "follow-redirects": "^1.14.9", - "form-data": "^4.0.0" + "follow-redirects": "^1.15.0", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" } }, "node_modules/balanced-match": { @@ -3700,19 +3700,6 @@ "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==" }, - "node_modules/fsevents": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", - "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", - "hasInstallScript": true, - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": "^8.16.0 || ^10.6.0 || >=11.0.0" - } - }, "node_modules/ftp": { "version": "0.3.10", "resolved": "https://registry.npmjs.org/ftp/-/ftp-0.3.10.tgz", @@ -4300,6 +4287,23 @@ "node": ">=0.10.0" } }, + "node_modules/icqq": { + "version": "0.0.28", + "resolved": "https://registry.npmjs.org/icqq/-/icqq-0.0.28.tgz", + "integrity": "sha512-vsaNqiws1eYwTkQISmDe+e480578+7mT59bxdahX1REDgHd4NIIpSCfE9XMXN2kCH2gu1Pg8SL2lEh6KAr+3HQ==", + "dependencies": { + "axios": "^1.1.2", + "lodash": "^4.17.21", + "log4js": "^6.3.0", + "long": "^4.0.0", + "pngjs": "^6.0.0", + "probe-image-size": "^7.2.2", + "triptrap": "^0.0.13-1" + }, + "engines": { + "node": ">= v14" + } + }, "node_modules/ieee754": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", @@ -6228,21 +6232,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/oicq": { - "version": "2.3.1", - "resolved": "https://registry.npmjs.org/oicq/-/oicq-2.3.1.tgz", - "integrity": "sha512-mRw/GgdRKFMylnrlnnywzCIwvad6fF5E4WZfIlval070wEc3w9yMV49i9epFltWkU/JGNMDS4t5wWdZEYzW0EQ==", - "dependencies": { - "axios": "^0.27.2", - "log4js": "^6.3.0", - "long": "^4.0.0", - "pngjs": "^6.0.0", - "probe-image-size": "^7.2.2" - }, - "engines": { - "node": ">= v14" - } - }, "node_modules/on-finished": { "version": "2.4.1", "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz", @@ -8766,6 +8755,11 @@ "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" }, + "node_modules/triptrap": { + "version": "0.0.13-1", + "resolved": "https://registry.npmjs.org/triptrap/-/triptrap-0.0.13-1.tgz", + "integrity": "sha512-nNsIFFfOFoDjY8d0YM5mHdB4ZCdHQJkgNDDQG5w3rcZwt9m/uJuW00/xBpxd+eEW5OIqpG0UyiglzCu4NPN9/w==" + }, "node_modules/tsconfig-paths": { "version": "3.14.2", "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-3.14.2.tgz", diff --git a/package.json b/package.json index b057ba3d0..ebb2a7c89 100644 --- a/package.json +++ b/package.json @@ -48,8 +48,7 @@ "install-dev": "npm run install-prod && npx cross-env-shell npm_config_sharp_binary_host='https://npmmirror.com/mirrors/sharp' npm_config_sharp_libvips_binary_host='https://npmmirror.com/mirrors/sharp-libvips' npm install --include dev", "install-prod": "npm install --omit dev", "update": "git pull && npm run install-prod", - "update-modules": "npx ncu -u && npm update", - "postinstall": "npx patch-package --patch-dir ./.patches" + "update-modules": "npx ncu -u && npm update" }, "dependencies": { "cross-env": "7.0.3", @@ -58,6 +57,7 @@ "figlet": "1.5.2", "fnv-plus": "1.3.1", "iconv-lite": "0.6.3", + "icqq": "0.0.28", "js-yaml": "4.1.0", "kind-of": "6.0.3", "lodash": "4.17.21", @@ -67,7 +67,6 @@ "moment-timezone": "0.5.41", "node-fetch": "3.3.0", "node-schedule": "2.1.1", - "oicq": "2.3.1", "p-limit": "4.0.0", "patch-package": "6.5.1", "pm2": "5.2.2", diff --git a/src/utils/oicq.js b/src/utils/oicq.js index 80fcfd468..c0af1d639 100644 --- a/src/utils/oicq.js +++ b/src/utils/oicq.js @@ -4,7 +4,7 @@ * ========================================================================== */ import lodash from "lodash"; import querystring from "querystring"; -import { genDmMessageId } from "oicq/lib/message/message.js"; +import { genDmMessageId } from "icqq/lib/message/message.js"; import { matchBracket } from "#utils/tools"; ("use strict");