Git Product home page Git Product logo

node-cq-websocket's Introduction

momocow's github stats

MomoCow's LeetCode Progress

node-cq-websocket's People

Contributors

dependabot[bot] avatar inazuma-bot avatar momocow avatar renovate-bot avatar satouriko avatar spacemeowx2 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

node-cq-websocket's Issues

Inconsistent parameters among message events

For example,

Events emitted in series when the bot is @-ed.
[email protected] (event, context)
message.group.@ (event, context)
message.group (event, context)
message (event, context)

In another hand, if a group message is received without any @ tags including the bot.
message.group.@ (event, context, atTags)
message.group (event, context, atTags)
message (event, context, atTags)

And normal messages without any @ tag.
message.group (event, context)
message (event, context)

Positional parameters for CQWebSocket constructor.

Extract baseUrl, host and port from CQWebSocketOption, change the declaration of CQWebSocketFactory to the one as below.

type CQWebSocketFactory<T = any> = {
  // use default protocol, host and port
  new (opt?: Partial<CQWebSocketOption>): CQWebSocket

  // provide your own <host [port]> or <base_url>
  new (baseUrlOrHost: string, opt?: Partial<CQWebSocketOption>): CQWebSocket
  new (host: string, port: number, opt?: Partial<CQWebSocketOption>): CQWebSocket
}

If baseUrlOrHost starts with a valid protocol name (http://, https://, ws://, wss://), the param is used as the baseUrl; otherwise, it is treated as host and will automatically be prefixed with ws://.

如何发送群组消息?

我查阅了文档,可以在message.group事件中回复群组消息。
有没有什么方法能在别的地方发送群组消息呢?

Use base URL instead of host and port options

用 base URL 讓SDK用戶自訂位址, 以更進一步支援例如反向代理的網路環境。

原先 URL 組成

ws://{host}:{port}/<event|api>[?access_token={token}]

變更為

ws://{baseUrl}/<event|api>[?access_token={token}]

Development flows

Scripts

Clean

Clean all files that match src/**/*.d.ts and src/**/*.js and the .dist folder (which contains local builds).

npm run clean

Commit

Following semantic commit message via commitizen.

npm run commit

Lint

  • Coding style: StandardJS
  • Linter: tslint + tslint-config-standard
npm run lint

Build

Compile all .ts files in place.

Since the main field in package.json is configured to be src/index, either typescript or javascript projects can find their corresponding entry files.

  • Compiler: tsc
npm run build

Webpack

Generate the cq-websocket.min.js and cq-websocket.kaomojified.js as the legacy work did. The output directory is dist on CI servers and .dist at local.

  • Compiler: webpack
npm run webpack

Release

Run semantic-release.

This will do actual release if it is master branch and there is any commit that causes version changed.

npm run release

Test

Run tests with AVA with ts-node/register enabled.

For nyc to correctly report the coverage, in tsconfig.json inlineSourceMap is set to true and source-map-support is installed.

npm test

Coverage

Coverage will be reported to coveralls.

npm run coverage

Docs

API references are generated using Typedoc with typedoc-plugin-external-module-name under /docs/api folder.

npm run docs

Update CQHTTP version in comment blocks

Parse all tsdoc comment blocks under src folder and update CQHTTP version in the CQHTTP document URL according to the minimal version specified by engines.cqhttp field in package.json.

gulp docs:update-cqhttp-version

怎么使用

Your environment has been set up for using Node.js 10.15.1 (ia32) and npm.

C:\Users\zaoqi>cd bot

C:\Users\zaoqi\bot>node bot.js
[/event] 建立連線中, 請稍後...
[/api] 建立連線中, 請稍後...
/event { SocketError: Failed to establish the websocket connection.
at W3CWebSocket._sock.addEventListener (C:\Users\zaoqi\node_modules\cq-websocket\src\index.js:479:70)
at W3CWebSocket._dispatchEvent [as dispatchEvent] (C:\Users\zaoqi\node_modules\yaeti\lib\EventTarget.js:115:12)
at W3CWebSocket.onConnectFailed (C:\Users\zaoqi\node_modules\websocket\lib\W3CWebSocket.js:217:14)
at WebSocketClient. (C:\Users\zaoqi\node_modules\websocket\lib\W3CWebSocket.js:59:25)
at WebSocketClient.emit (events.js:189:13)
at ClientRequest.handleRequestError (C:\Users\zaoqi\node_modules\websocket\lib\WebSocketClient.js:227:14)
at ClientRequest.emit (events.js:189:13)
at Socket.socketErrorListener (_http_client.js:392:9)
at Socket.emit (events.js:189:13)
at emitErrorNT (internal/streams/destroy.js:82:8) name: 'SocketError' }
[/event] 連線失敗 。・゚・(つд゚)・゚・ [丑1] 對噗起 [/event] 連線關閉(1006: connection failed) /api { SocketError: Failed to establish the websocket connection. at W3CWebSocket._sock.addEventListener (C:\Users\zaoqi\node_modules\cq-websocket\src\index.js:479:70) at W3CWebSocket._dispatchEvent [as dispatchEvent] (C:\Users\zaoqi\node_modules\yaeti\lib\EventTarget.js:115:12) at W3CWebSocket.onConnectFailed (C:\Users\zaoqi\node_modules\websocket\lib\W3CWebSocket.js:217:14) at WebSocketClient.<anonymous> (C:\Users\zaoqi\node_modules\websocket\lib\W3CWebSocket.js:59:25) at WebSocketClient.emit (events.js:189:13) at ClientRequest.handleRequestError (C:\Users\zaoqi\node_modules\websocket\lib\WebSocketClient.js:227:14) at ClientRequest.emit (events.js:189:13) at Socket.socketErrorListener (_http_client.js:392:9) at Socket.emit (events.js:189:13) at emitErrorNT (internal/streams/destroy.js:82:8) name: 'SocketError' } [/api] 連線失敗 。・゚・(つд゚)・゚・ [丑1] 對噗起
[/api] 連線關閉(1006: connection failed)
[/event] 建立連線中, 請稍後...
[/api] 建立連線中, 請稍後...
/event { SocketError: Failed to establish the websocket connection.
at W3CWebSocket._sock.addEventListener (C:\Users\zaoqi\node_modules\cq-websocket\src\index.js:479:70)
at W3CWebSocket._dispatchEvent [as dispatchEvent] (C:\Users\zaoqi\node_modules\yaeti\lib\EventTarget.js:115:12)
at W3CWebSocket.onConnectFailed (C:\Users\zaoqi\node_modules\websocket\lib\W3CWebSocket.js:217:14)
at WebSocketClient. (C:\Users\zaoqi\node_modules\websocket\lib\W3CWebSocket.js:59:25)
at WebSocketClient.emit (events.js:189:13)
at ClientRequest.handleRequestError (C:\Users\zaoqi\node_modules\websocket\lib\WebSocketClient.js:227:14)
at ClientRequest.emit (events.js:189:13)
at Socket.socketErrorListener (_http_client.js:392:9)
at Socket.emit (events.js:189:13)
at emitErrorNT (internal/streams/destroy.js:82:8) name: 'SocketError' }
[/event] 連線失敗 。・゚・(つд゚)・゚・ [丑2] 對噗起 [/event] 連線關閉(1006: connection failed) /api { SocketError: Failed to establish the websocket connection. at W3CWebSocket._sock.addEventListener (C:\Users\zaoqi\node_modules\cq-websocket\src\index.js:479:70) at W3CWebSocket._dispatchEvent [as dispatchEvent] (C:\Users\zaoqi\node_modules\yaeti\lib\EventTarget.js:115:12) at W3CWebSocket.onConnectFailed (C:\Users\zaoqi\node_modules\websocket\lib\W3CWebSocket.js:217:14) at WebSocketClient.<anonymous> (C:\Users\zaoqi\node_modules\websocket\lib\W3CWebSocket.js:59:25) at WebSocketClient.emit (events.js:189:13) at ClientRequest.handleRequestError (C:\Users\zaoqi\node_modules\websocket\lib\WebSocketClient.js:227:14) at ClientRequest.emit (events.js:189:13) at Socket.socketErrorListener (_http_client.js:392:9) at Socket.emit (events.js:189:13) at emitErrorNT (internal/streams/destroy.js:82:8) name: 'SocketError' } [/api] 連線失敗 。・゚・(つд゚)・゚・ [丑2] 對噗起
[/api] 連線關閉(1006: connection failed)
[/event] 建立連線中, 請稍後...
[/api] 建立連線中, 請稍後...
/event { SocketError: Failed to establish the websocket connection.
at W3CWebSocket._sock.addEventListener (C:\Users\zaoqi\node_modules\cq-websocket\src\index.js:479:70)
at W3CWebSocket._dispatchEvent [as dispatchEvent] (C:\Users\zaoqi\node_modules\yaeti\lib\EventTarget.js:115:12)
at W3CWebSocket.onConnectFailed (C:\Users\zaoqi\node_modules\websocket\lib\W3CWebSocket.js:217:14)
at WebSocketClient. (C:\Users\zaoqi\node_modules\websocket\lib\W3CWebSocket.js:59:25)
at WebSocketClient.emit (events.js:189:13)
at ClientRequest.handleRequestError (C:\Users\zaoqi\node_modules\websocket\lib\WebSocketClient.js:227:14)
at ClientRequest.emit (events.js:189:13)
at Socket.socketErrorListener (_http_client.js:392:9)
at Socket.emit (events.js:189:13)
at emitErrorNT (internal/streams/destroy.js:82:8) name: 'SocketError' }
[/event] 連線失敗 。・゚・(つд゚)・゚・ [丑3] 對噗起 [/event] 連線關閉(1006: connection failed) /api { SocketError: Failed to establish the websocket connection. at W3CWebSocket._sock.addEventListener (C:\Users\zaoqi\node_modules\cq-websocket\src\index.js:479:70) at W3CWebSocket._dispatchEvent [as dispatchEvent] (C:\Users\zaoqi\node_modules\yaeti\lib\EventTarget.js:115:12) at W3CWebSocket.onConnectFailed (C:\Users\zaoqi\node_modules\websocket\lib\W3CWebSocket.js:217:14) at WebSocketClient.<anonymous> (C:\Users\zaoqi\node_modules\websocket\lib\W3CWebSocket.js:59:25) at WebSocketClient.emit (events.js:189:13) at ClientRequest.handleRequestError (C:\Users\zaoqi\node_modules\websocket\lib\WebSocketClient.js:227:14) at ClientRequest.emit (events.js:189:13) at Socket.socketErrorListener (_http_client.js:392:9) at Socket.emit (events.js:189:13) at emitErrorNT (internal/streams/destroy.js:82:8) name: 'SocketError' } [/api] 連線失敗 。・゚・(つд゚)・゚・ [丑3] 對噗起
[/api] 連線關閉(1006: connection failed)
^C
C:\Users\zaoqi\bot>

d.ts文件声明中少了元事件的类型

我在使用typescript写事件监听时,希望监听一下元事件的心跳连接,但在编辑器中提示 类型“"meta_event.heartbeat"”的参数不能赋给类型“"socket.connecting" | "socket.failed" | "socket.reconnecting" | "socket.reconnect" | "socket.reconnect_failed" | "socket.max_reconnect"”的参数
查阅源码后发现并未对元事件进行d.ts类型声明
虽然编译成js之后依旧可以执行,但是会对使用ts编写的用户有所困扰,希望修复一下

Memory leak in EventBus

For test snippets, see performance/leakage/once.test.js.

Within the test for CQWebSocket#once(), memory grows about 342KB after 180 iterations.

[node-cq-websocket] # npm run perf

> [email protected] perf /workspace
> tape performance/**/*.test.js

TAP version 13
# EventEmitter#once()
ok 1 should be equivalent
# CQWebSocket#once()

/workspace/node_modules/leakage/lib/index.js:66
    throw heapError
    ^
MemoryLeakError: Heap grew on 6 subsequent garbage collections (180 of 180 iterations) by 342 kB.

  Iterations between GCs: 30

  Final GC details:
  [   25.7 kB] [+ 181x] [-   1x] Array
  [   7.68 kB] [+ 120x] [-   0x] system / Context
  [   6.48 kB] [+  90x] [-   0x] Closure
  [   5.28 kB] [+  60x] [-   0x] Promise
  ... (5 more)

    at testConstantHeapSize (/workspace/node_modules/leakage/lib/testConstantHeapSize.js:24:12)
    at iterate (/workspace/node_modules/leakage/lib/index.js:64:21)
    at Test.<anonymous> (/workspace/performance/leak.test.js:23:3)
    at Test.bound [as _cb] (/workspace/node_modules/tape/lib/test.js:77:32)
    at Test.run (/workspace/node_modules/tape/lib/test.js:96:10)
    at Test.bound [as run] (/workspace/node_modules/tape/lib/test.js:77:32)
    at Immediate.next [as _onImmediate] (/workspace/node_modules/tape/lib/results.js:75:19)
    at runCallback (timers.js:810:20)
    at tryOnImmediate (timers.js:768:5)
    at processImmediate [as _immediateCallback] (timers.js:745:5)

連續呼叫 connect, disconnect, reconnect 會發生無法掌控的問題

需 debouncing 機制, 並且維護一個內部的狀態值

內部狀態總共 6 個值, 分別對應以下事件

  • disabled (對應事件: 無)
  • init (對應事件: 無)
  • connecting (對應事件: socket.connecting)
  • connected (對應事件: socket.connect)
  • closing (對應事件: socket.closing)
  • closed (對應事件: socket.close)

TODO

  • 只有處於 initclosed 狀態可以呼叫 connect
  • 只有處於 connected 可以呼叫 disconnect
  • 只有處於 init, connectedclosed 可以呼叫 reconnect
  • 處於 disabled 呼叫任何連線方法均沒有效果

WS connect problem

Here is my situation:
Host: 192.168.102.24,
Docker: 192.168.102.24:8888,
cqHttp:

    "host": "192.168.102.24",
    "port": 5700,
    "use_http": true,
    "ws_host": "192.168.102.24",
    "ws_port": 6700,
    "use_ws": true,

node-cq-webscoket

  port: 6700,
  host: '127.0.0.1',//0.0.0.0 || 192.168.102.24

still cannot establish connect to cqHttp server,is there something wrong?
please tell me more details if you are convience.
Thanks!

demo code not work

steps to reproduce:

nodejs: v11.15.0, v12.11.1

  1. start cqhttp container
docker run -ti --rm --name cqhttp-test \
             -v $(pwd)/data:/home/user/coolq \
             -p 9000:9000 \
             -p 9001:9001 \
             -p 5700:5700 \
             -e COOLQ_ACCOUNT=<my_qq_id> \
             -e CQHTTP_SERVE_DATA_FILES=yes \
             -e VNC_PASSWD=12345678 \
             richardchien/cqhttp:latest
  1. login in noVNC

  2. update echobot.js L:23

const CQWebsocket = require('../')
-->
const CQWebsocket = require('../').default
  1. run node echobot.js --port 9001

console output:

[/event] 建立連線中, 請稍後...
[/api] 建立連線中, 請稍後...
[/event] 連線成功 ヽ(✿゚▽゚)ノ 蛆蛆1個嘗試
[/api] 連線成功 ヽ(✿゚▽゚)ノ 蛆蛆1個嘗試
今天又是複讀複讀的一天 。:.゚ヽ(*´∀`)ノ゚.:。
[/api] 連線關閉(1003: Unsupported: Unknown opcode 0x01)
[/api] 建立連線中, 請稍後...
[/api] 連線成功 ヽ(✿゚▽゚)ノ 蛆蛆1個嘗試
今天又是複讀複讀的一天 。:.゚ヽ(*´∀`)ノ゚.:。
[/api] 連線關閉(1003: Unsupported: Unknown opcode 0x01)
[/api] 建立連線中, 請稍後...
[/api] 連線成功 ヽ(✿゚▽゚)ノ 蛆蛆1個嘗試
今天又是複讀複讀的一天 。:.゚ヽ(*´∀`)ノ゚.:。
[/api] 連線關閉(1003: Unsupported: Unknown opcode 0x01)
[/api] 建立連線中, 請稍後...

container output:

172.17.0.1 - - [07/Oct/2019 20:06:00] 172.17.0.1: Plain non-SSL (ws://) WebSocket connection
172.17.0.1 - - [07/Oct/2019 20:06:00] 172.17.0.1: Path: '/event'
172.17.0.1 - - [07/Oct/2019 20:06:00] connecting to: 127.0.0.1:5911
172.17.0.1 - - [07/Oct/2019 20:06:00] 172.17.0.1: Plain non-SSL (ws://) WebSocket connection
172.17.0.1 - - [07/Oct/2019 20:06:00] 172.17.0.1: Path: '/api'
172.17.0.1 - - [07/Oct/2019 20:06:00] connecting to: 127.0.0.1:5911
172.17.0.1 - - [07/Oct/2019 20:06:06] 172.17.0.1: Plain non-SSL (ws://) WebSocket connection
172.17.0.1 - - [07/Oct/2019 20:06:06] 172.17.0.1: Path: '/event'
172.17.0.1 - - [07/Oct/2019 20:06:06] connecting to: 127.0.0.1:5911
172.17.0.1 - - [07/Oct/2019 20:06:06] 172.17.0.1: Plain non-SSL (ws://) WebSocket connection
172.17.0.1 - - [07/Oct/2019 20:06:06] 172.17.0.1: Path: '/api'
172.17.0.1 - - [07/Oct/2019 20:06:06] connecting to: 127.0.0.1:5911
172.17.0.1 - - [07/Oct/2019 20:06:07] 172.17.0.1: Plain non-SSL (ws://) WebSocket connection
172.17.0.1 - - [07/Oct/2019 20:06:07] 172.17.0.1: Path: '/api'
172.17.0.1 - - [07/Oct/2019 20:06:07] connecting to: 127.0.0.1:5911

遇到 $WebsocketClient is not a constructor的错误

错误提示为:

Uncaught TypeError: $WebsocketClient is not a constructor

定位在: https://github.com/momocow/node-cq-websocket/blob/master/src/index.js#L31
这可能是我试图直接在js中使用这个nodejs包导致的

HelpWanted

想在网页中使用通知,需要https连接,此时无法使用websocket协议
能否改用wss://进行传输?

在特定情况下消息含有at但没有被 [email protected] 捕获

我实际使用时发现,当在消息中at机器人之前含有图片,则该消息将会被message.x捕获,跳过了[email protected]

例如:

# 以下消息可以被 [email protected] 捕获(先at再图片,或是at前只有文字没有图片)
[CQ:at,qq=123] [CQ:image,file=123,url=123]
123123[CQ:at,qq=123]

# 以下消息会跳过 [email protected] (先图片再at,并且与之间或者之前是否有文字无关)
[CQ:image,file=123,url=123][CQ:at,qq=123]
[CQ:image,file=123,url=123] [CQ:at,qq=123]
[CQ:image,file=123,url=123] aaa [CQ:at,qq=123]
aaa[CQ:image,file=123,url=123][CQ:at,qq=123]

想问问如何付费?

感谢作者做这个nice的库,
想问下如何付费?
没有看到怎么收费,还有收费标准、付费服务内容啥的?

Support default export.

No need for "allowSyntheticDefaultImports": true in the tsconfig.json anymore after this implementation.

websocket can't be reconnected sometimes

I'm running multiple(more than 5) CQWebsocket instances in my program.

Sometimes one or two instances were not reconnected after reconnect() method called, while other instances did reconnect as expected.

Since there is no internal trace, I've no idea what happened and can only restart my program to restore the connections.

Could you add an "internal trace" feature in the current or next version?
Thanks.

Once listeners cannot be removed

因為註冊單次監聽器時, 使用一個 wrapper 包裝該監聽器後才呼叫 on() 進行註冊。
但若需要呼叫 off() 移除該監聽器, 因為沒有 wrapper 的參照, 故無法移除。

自動重連時的 UnhandledPromiseRejectionWarning

找出哪個環節有 Promise 沒有處理好, 看起來會是 websocket 的東西。

const CQWebsocket = require('../..')

const bot = new CQWebsocket()

bot.on('socket.connecting', function (wsType, attempts) {
  console.log('[%s] 嘗試第 %d 次連線 _(:з」∠)_', wsType, attempts)
}).on('socket.connect', function (wsType, sock, attempts) {
  console.log('[%s] 第 %d 次連線嘗試成功 ヽ(✿゚▽゚)ノ', wsType, attempts)
}).on('socket.failed', function (wsType, attempts) {
  console.log('[%s] 第 %d 次連線嘗試失敗 。・゚・(つд`゚)・゚・', wsType, attempts)
})

bot.connect()
[/event] 第 1 次連線嘗試失敗 。・゚・(つд`゚)・゚・

(node:10652) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:6700
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1162:14)
(node:10652) 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(). (rejection id: 1)

(node:10652) [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.

[/api] 第 1 次連線嘗試失敗 。・゚・(つд`゚)・゚・

(node:10652) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:6700
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1162:14)

(node:10652) 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(). (rejection id: 2)

[/event] 第 2 次連線嘗試失敗 。・゚・(つд`゚)・゚・

(node:10652) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:6700
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1162:14)

(node:10652) 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(). (rejection id: 3)

[/api] 第 2 次連線嘗試失敗 。・゚・(つд`゚)・゚・

(node:10652) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:6700
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1162:14)

(node:10652) 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(). (rejection id: 4)

[/event] 第 3 次連線嘗試失敗 。・゚・(つд`゚)・゚・

(node:10652) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:6700
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1162:14)

(node:10652) 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(). (rejection id: 5)

[/api] 第 3 次連線嘗試失敗 。・゚・(つд`゚)・゚・

(node:10652) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:6700
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1162:14)

(node:10652) 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(). (rejection id: 6)

[/event] 第 4 次連線嘗試失敗 。・゚・(つд`゚)・゚・

(node:10652) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:6700
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1162:14)

(node:10652) 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(). (rejection id: 7)

[/api] 第 4 次連線嘗試失敗 。・゚・(つд`゚)・゚・

(node:10652) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:6700
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1162:14)

(node:10652) 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(). (rejection id: 8)

[/event] 第 5 次連線嘗試失敗 。・゚・(つд`゚)・゚・

(node:10652) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:6700
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1162:14)

(node:10652) 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(). (rejection id: 9)

[/api] 第 5 次連線嘗試失敗 。・゚・(つд`゚)・゚・

(node:10652) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:6700
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1162:14)

(node:10652) 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(). (rejection id: 10)

[/event] 第 6 次連線嘗試失敗 。・゚・(つд`゚)・゚・

(node:10652) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:6700
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1162:14)

(node:10652) 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(). (rejection id: 11)

[/api] 第 6 次連線嘗試失敗 。・゚・(つд`゚)・゚・

(node:10652) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:6700
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1162:14)

(node:10652) 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(). (rejection id: 12)

[/event] 第 7 次連線嘗試失敗 。・゚・(つд`゚)・゚・

(node:10652) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:6700
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1162:14)

(node:10652) 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(). (rejection id: 13)

[/api] 第 7 次連線嘗試失敗 。・゚・(つд`゚)・゚・

(node:10652) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:6700
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1162:14)

(node:10652) 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(). (rejection id: 14)

Use WeakMap for mappings of once listeners and their wrappers

在現在的做法中
一次性的監聽器實際上是先經過一層封裝 (為了自動移除)
而後才註冊到 event map 中

因此透過一個 Map 對象負責配對原先的監聽器到封裝後的方法
用以輔助 #off(event, listener) 找到正確的封裝方法
並將其移除。

若用戶未主動呼叫#off()方法, 或者並未有呼叫#off()方法的需求,
內存中仍有這個 Map 對象配對, 增加 memory leak 風險。

因此改用 WeakMap 可提升這部分的性能,
在現有的慣例中,
所有需要呼叫#off()方法的用戶自然會握有監聽器的參照,
沒握有參照的就是不需要呼叫#off()方法。

API 事件運作不正常

注意到現在使用的是

this._eventBus.emit('socket.response', WebsocketType.API, JSON.parse(msg.utf8Data))

從而api.response事件不能正確執行

message.*.@ 事件

現在已經有 message.*.@me 事件, 當機器人被@時會發布。

新事件 message.*.@, 任何夾帶 @ 的信息
若對象非此機器人, 則觸發該事件
由此事件可監聽特定用戶是否被 @。

ES6 import failed

import { CQWebSocket } from 'cq-websocket';
         ^^^^^^^^^^^
SyntaxError: The requested module 'cq-websocket' does not provide an export named 'CQWebSocket'

暂时用沙雕方式替代
const CQWebSocket = (await import('cq-websocket')).default.default;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.