koishi-plugin-adapter-onebot-multi 0.0.17 → 0.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -894,6 +894,13 @@ var WsClient = class extends import_koishi5.Adapter.WsClient {
894
894
  static {
895
895
  __name(this, "WsClient");
896
896
  }
897
+ constructor(ctx, bot) {
898
+ super(ctx, bot);
899
+ ctx.on("http/websocket-init", (url, options) => {
900
+ ;
901
+ options.maxPayload = 500 * 1024 * 1024;
902
+ });
903
+ }
897
904
  accept(socket) {
898
905
  accept(socket, this.bot);
899
906
  }
@@ -975,9 +982,18 @@ function accept(socket, bot) {
975
982
  delete listeners[parsed.echo];
976
983
  }
977
984
  });
978
- socket.addEventListener("close", () => {
985
+ socket.addEventListener("error", (event) => {
986
+ bot.logger.warn(`WebSocket 错误: ${event.message || "未知错误"}`);
987
+ });
988
+ socket.addEventListener("close", (event) => {
979
989
  delete bot.internal._request;
980
- bot.offline();
990
+ const closeInfo = `code: ${event.code}, reason: ${event.reason || "无"}`;
991
+ if (event.code === 1009) {
992
+ bot.logger.error(`WebSocket 因消息过大断开 (${closeInfo}),协议端可能发送了超大消息`);
993
+ } else if (event.code !== 1e3 && event.code !== 1001) {
994
+ bot.logger.warn(`WebSocket 连接关闭 (${closeInfo})`);
995
+ }
996
+ ;
981
997
  bot.ctx.emit("onebot-multi/bot-offline", bot);
982
998
  });
983
999
  bot.internal._request = (action, params) => {
@@ -1051,7 +1067,7 @@ var HeartbeatMonitor = class {
1051
1067
  }
1052
1068
  } else {
1053
1069
  if (this.bot.status === import_koishi6.Universal.Status.ONLINE) {
1054
- this.bot.offline();
1070
+ this.logger.warn(`Bot ${this.bot.selfId} 协议端报告离线,等待恢复...`);
1055
1071
  this.ctx.emit("onebot-multi/bot-offline", this.bot);
1056
1072
  }
1057
1073
  }
@@ -1064,10 +1080,7 @@ var HeartbeatMonitor = class {
1064
1080
  }
1065
1081
  if (this.lastOnlineState !== false) {
1066
1082
  this.lastOnlineState = false;
1067
- if (this.bot.status === import_koishi6.Universal.Status.ONLINE) {
1068
- this.bot.offline(error);
1069
- this.ctx.emit("onebot-multi/bot-offline", this.bot);
1070
- }
1083
+ this.ctx.emit("onebot-multi/bot-offline", this.bot);
1071
1084
  }
1072
1085
  }
1073
1086
  }
package/lib/ws.d.ts CHANGED
@@ -6,6 +6,7 @@ export interface SharedConfig<T = 'ws' | 'ws-reverse'> {
6
6
  responseTimeout?: number;
7
7
  }
8
8
  export declare class WsClient<C extends Context = Context> extends Adapter.WsClient<C, OneBotBot<C, any>> {
9
+ constructor(ctx: C, bot: OneBotBot<C>);
9
10
  accept(socket: Universal.WebSocket): void;
10
11
  prepare(): any;
11
12
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-adapter-onebot-multi",
3
3
  "description": "奶龙bot定制版onebot适配器,支持自动负载均衡,适配器级黑名单/白名单,提供webui,可指定端口",
4
- "version": "0.0.17",
4
+ "version": "0.0.18",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [