Drincann / Mirai-js

运行在 Node.js、浏览器下,基于 mirai-api-http 的 QQ 机器人开发框架。
https://mirai-js-drincann.vercel.app
GNU Affero General Public License v3.0
252 stars 31 forks source link

指定操作不支持 #231

Closed zhaoluuu closed 1 year ago

zhaoluuu commented 1 year ago

你好!可以帮我看看问题所在嘛?或者告诉我解决调式方法。 当我尝试open一个链接后,报如下

[root@VM-0-10-centos qqBot]# node index.js 
mirai-js: error core.verify
(node:22591) UnhandledPromiseRejectionWarning: Error: 指定操作不支持
    at module.exports (/home/qqNew/qqBot/node_modules/mirai-js/dist/node/util/errorHandler.js:25:11)
    at module.exports (/home/qqNew/qqBot/node_modules/mirai-js/dist/node/core/verify.js:68:5)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async Bot.open (/home/qqNew/qqBot/node_modules/mirai-js/dist/node/Bot.js:205:21)
    at async login (file:///home/qqNew/qqBot/index.js:19:9)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:22591) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:22591) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

然后如下是我mcl的启动信息

[root@VM-0-10-centos mcl-2.1.2]# ./mcl
  15:17:18 [INFO] iTX Technologies Mirai Console Loader version 2.1.2-61c8bd8
  15:17:18 [INFO] Runtime: OpenJDK 64-Bit Server VM 11.0.18 (arch: 64)
  15:17:18 [INFO] https://github.com/iTXTech/mirai-console-loader
  15:17:18 [INFO] This program is licensed under GNU AGPL v3
  15:17:19 [INFO] Mirai Console Loader Announcement:
Mirai Console Loader 公告栏

如果在图片上传的时候遇到问题请与我们联系 (需要提供图片文件源本)
`- 如 Unsupported image type for ExternalResource *
`  considering use gif/png/bmp/jpg format.
`- Tracker: https://github.com/mamoe/mirai/issues/new/choose

常用资源整合
`- https://mirai.mamoe.net/topic/653

MCL 已推出 2.1.0,更好的支持 Mirai 2.11 的插件系统,建议更新。

  15:17:19 [INFO] Verifying "net.mamoe:mirai-console" v2.14.0
  15:17:20 [INFO] Verifying "net.mamoe:mirai-console-terminal" v2.14.0
  15:17:20 [INFO] Verifying "net.mamoe:mirai-core-all" v2.14.0
  15:17:21 [INFO] Verifying "org.itxtech:mcl-addon" v2.1.1
  15:17:21 [INFO] Verifying "org.bouncycastle:bcprov-jdk15on" v1.64
  15:17:21 [INFO] Verifying "net.mamoe:mirai-api-http" v2.8.0
2023-02-21 15:17:22 I/main: Starting mirai-console...
2023-02-21 15:17:22 I/main: 

==================================[ Mirai consosle 2.14.0 ]===================================
 __       __ __                   __  ______                                      __
|  \     /  \  \                 |  \/      \                                    |  \
| ▓▓\   /  ▓▓\▓▓ ______   ______  \▓▓  ▓▓▓▓▓▓\ ______  _______   _______  ______ | ▓▓ ______
| ▓▓▓\ /  ▓▓▓  \/      \ |      \|  \ ▓▓   \▓▓/      \|       \ /       \/      \| ▓▓/      \
| ▓▓▓▓\  ▓▓▓▓ ▓▓  ▓▓▓▓▓▓\ \▓▓▓▓▓▓\ ▓▓ ▓▓     |  ▓▓▓▓▓▓\ ▓▓▓▓▓▓▓\  ▓▓▓▓▓▓▓  ▓▓▓▓▓▓\ ▓▓  ▓▓▓▓▓▓\
| ▓▓\▓▓ ▓▓ ▓▓ ▓▓ ▓▓   \▓▓/      ▓▓ ▓▓ ▓▓   __| ▓▓  | ▓▓ ▓▓  | ▓▓\▓▓    \| ▓▓  | ▓▓ ▓▓ ▓▓    ▓▓
| ▓▓ \▓▓▓| ▓▓ ▓▓ ▓▓     |  ▓▓▓▓▓▓▓ ▓▓ ▓▓__/  \ ▓▓__/ ▓▓ ▓▓  | ▓▓_\▓▓▓▓▓▓\ ▓▓__/ ▓▓ ▓▓ ▓▓▓▓▓▓▓▓
| ▓▓  \▓ | ▓▓ ▓▓ ▓▓      \▓▓    ▓▓ ▓▓\▓▓    ▓▓\▓▓    ▓▓ ▓▓  | ▓▓       ▓▓\▓▓    ▓▓ ▓▓\▓▓     \
 \▓▓      \▓▓\▓▓\▓▓       \▓▓▓▓▓▓▓\▓▓ \▓▓▓▓▓▓  \▓▓▓▓▓▓ \▓▓   \▓▓\▓▓▓▓▓▓▓  \▓▓▓▓▓▓ \▓▓ \▓▓▓▓▓▓▓

2023-02-21 15:17:22 I/main: Backend: version 2.14.0, built on 2023-02-06 14:25:21.
2023-02-21 15:17:22 I/main: Frontend Terminal: version 2.14.0, provided by Mamoe Technologies
2023-02-21 15:17:22 I/main: Welcome to visit https://mirai.mamoe.net/
2023-02-21 15:17:24 I/plugin: Successfully loaded plugin mirai-api-http v2.8.0
2023-02-21 15:17:24 I/plugin: Successfully loaded plugin MCL Addon v2.1.1
2023-02-21 15:17:25 I/main: Prepared built-in commands: autoLogin, help, login, logout, permission, status, stop
2023-02-21 15:17:25 W/mirai-api-http: USING INITIAL KEY, please edit the key
2023-02-21 15:17:25 I/Mirai HTTP API: ********************************************************
2023-02-21 15:17:25 I/MahKtorAdapter[http,ws]: Autoreload is disabled because the development mode is off.
2023-02-21 15:17:25 I/MahKtorAdapter[http,ws]: Application started in 0.324 seconds.
2023-02-21 15:17:25 I/MahKtorAdapter[http,ws]: Responding at http://0.0.0.0:2080
2023-02-21 15:17:25 I/http adapter: >>> [http adapter] is listening at http://0.0.0.0:2080
2023-02-21 15:17:25 I/ws adapter: >>> [ws adapter] is listening at ws://0.0.0.0:2080
2023-02-21 15:17:25 I/Mirai HTTP API: Http api server is running with verifyKey: INITKEYpff86IGV
2023-02-21 15:17:25 I/Mirai HTTP API: adaptors: [http,ws]
2023-02-21 15:17:25 I/Mirai HTTP API: ********************************************************
2023-02-21 15:17:25 I/MCL Addon: iTXTech MCL Version: 2.1.2-61c8bd8
2023-02-21 15:17:25 W/MCL Addon: iTXTech Soyuz 未安装,Soyuz MCL Handler 特性已禁用
2023-02-21 15:17:26 I/main: 2 plugin(s) enabled.
2023-02-21 15:17:26 I/main: mirai-console started successfully.
/login qq pwd ANDROID_PAD
2023-02-21 15:18:25 I/Bot.3330360291: Bot login successful.

最后是我的node代码

import pkg from 'mirai-js';
const { Bot, Message,Middleware } = pkg;
const bot = new Bot();

// 连接到一个 mirai-api-http 服务
await bot.open({
    baseUrl: 'http://host:2080',
    verifyKey: 'INITKEYpff86IGV',
    // 要绑定的 qq,须确保该用户已在 mirai-console 登录
    qq: qq,
});

盼复!谢谢🙏

zhaoluuu commented 1 year ago
leeda@leedadeMacBook-Pro qqBot % node test.js
mirai-js: error core.verify
/Users/leeda/qqBot/node_modules/mirai-js/dist/node/util/errorHandler.js:25
    throw new Error([message, miraiMessage, resMessage, response === null || response === void 0 ? void 0 : response.data].filter(msg => typeof msg == 'string').join('\n'));
          ^

Error: 指定操作不支持
    at module.exports (/Users/leeda/qqBot/node_modules/mirai-js/dist/node/util/errorHandler.js:25:11)
    at module.exports (/Users/leeda/qqBot/node_modules/mirai-js/dist/node/core/verify.js:68:5)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Bot.open (/Users/leeda/qqBot/node_modules/mirai-js/dist/node/Bot.js:205:21)
    at async file:///Users/leeda/qqBot/test.js:6:1
leeda@leedadeMacBook-Pro qqBot % 
zhaoluuu commented 1 year ago

更多的使用情况 mirai-js": "^2.8.9" mirai-api-http v2.8.0 mirai-api-http 的配置文件

adapters: 
- http
- ws
debug: false
enableVerify: true
## 是否开启认证流程, 若为 true 则建立连接时需要验证 verifyKey
verifyKey: INITKEYpff86IGV
singleMode: true
cacheSize: 4096
adapterSettings: 
    http:
        ## http server 监听的本地地址
        ## 一般为 localhost 即可, 如果多网卡等情况,自定设置
        host: 0.0.0.0

        ## http server 监听的端口
        ## 与 websocket server 可以重复, 由于协议与路径不同, 不会产生冲突
        port: 2080

        ## 配置跨域, 默认允许来自所有域名
        cors: [*]
    ws:
        ## websocket server 监听的本地地址
        ## 一般为 localhost 即可, 如果多网卡等情况,自定设置
        host: 0.0.0.0

        ## websocket server 监听的端口
        ## 与 http server 可以重复, 由于协议与路径不同, 不会产生冲突
        port: 2080

        ## websocket 用于消息同步的字段为 syncId, 一般值为请求时的原值,用于同步一次请求与响应
        ## 对于由 websocket server 主动发出的通知, 固定使用一个 syncId, 默认为 ”-1“
        reservedSyncId: -1
zhaoluuu commented 1 year ago

使用postman测试bind

image
Drincann commented 1 year ago

@zhaoluuu 为什么 close 了,问题还在吗?

zhaoluuu commented 1 year ago

@zhaoluuu 为什么 close 了,问题还在吗?

问题已经解决了,我对setting.yml文件中的singleMode的值设置为false,再次启动就好了。 很高心收到你的关切,祝好😊

Drincann commented 1 year ago

@zhaoluuu 客气,open method 的参数中应该是包含该选项的。