@alemonjs/onebot 2.1.0-alpha.11 → 2.1.0-alpha.12

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/config.d.ts CHANGED
@@ -1,3 +1,11 @@
1
- declare const platform = "onebot";
2
-
3
- export { platform };
1
+ export declare const platform = "onebot";
2
+ export type Options = {
3
+ url: string;
4
+ token?: string;
5
+ reverse_enable?: boolean;
6
+ reverse_port: number;
7
+ master_key?: string[];
8
+ master_id?: string[];
9
+ };
10
+ export declare const getOneBotConfig: () => Options;
11
+ export declare const getMaster: (UserId: string) => readonly [boolean, string];
package/lib/db.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ export declare const BotMe: {
2
+ id: string;
3
+ name: string;
4
+ avatar: string;
5
+ };
package/lib/db.js CHANGED
@@ -1,4 +1,7 @@
1
1
  const BotMe = {
2
- id: ''};
2
+ id: '',
3
+ name: '',
4
+ avatar: ''
5
+ };
3
6
 
4
7
  export { BotMe };
package/lib/hook.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { EventKeys, Events } from 'alemonjs';
2
- import { OneBotAPI } from './sdk/api.js';
3
- import { MESSAGES_TYPE, DIRECT_MESSAGE_TYPE } from './sdk/types.js';
4
-
2
+ import { OneBotAPI as API } from './sdk/api';
3
+ import { DIRECT_MESSAGE_TYPE, MESSAGES_TYPE } from './sdk/types';
5
4
  type MAP = {
6
5
  'message.create': MESSAGES_TYPE;
7
6
  'private.message.create': DIRECT_MESSAGE_TYPE;
@@ -11,8 +10,8 @@ type MAP = {
11
10
  'message.delete': undefined;
12
11
  'message.reaction.add': undefined;
13
12
  'message.reaction.remove': undefined;
14
- 'channal.create': undefined;
15
- 'channal.delete': undefined;
13
+ 'channel.create': undefined;
14
+ 'channel.delete': undefined;
16
15
  'guild.join': undefined;
17
16
  'guild.exit': undefined;
18
17
  'member.add': undefined;
@@ -22,17 +21,6 @@ type MAP = {
22
21
  'private.friend.add': undefined;
23
22
  'private.guild.add': undefined;
24
23
  };
25
- /**
26
- *
27
- * @param event
28
- * @returns
29
- */
30
- declare const useValue: <T extends EventKeys>(event: Events[T]) => readonly [MAP[T]];
31
- /**
32
- *
33
- * @param event
34
- * @returns
35
- */
36
- declare const useClient: <T extends EventKeys>(event: Events[T]) => readonly [OneBotAPI, MAP[T]];
37
-
38
- export { useClient, useValue };
24
+ export declare const useValue: <T extends EventKeys>(event: Events[T]) => readonly [MAP[T]];
25
+ export declare const useClient: <T extends EventKeys>(event: Events[T]) => readonly [API, MAP[T]];
26
+ export {};
package/lib/hook.js CHANGED
@@ -1,20 +1,10 @@
1
1
  import { createEventValue, useClient as useClient$1 } from 'alemonjs';
2
2
  import { OneBotAPI } from './sdk/api.js';
3
3
 
4
- /**
5
- *
6
- * @param event
7
- * @returns
8
- */
9
4
  const useValue = (event) => {
10
5
  const value = createEventValue(event);
11
6
  return [value];
12
7
  };
13
- /**
14
- *
15
- * @param event
16
- * @returns
17
- */
18
8
  const useClient = (event) => {
19
9
  const [client] = useClient$1(event, OneBotAPI);
20
10
  const value = createEventValue(event);
package/lib/index.d.ts CHANGED
@@ -1,7 +1,5 @@
1
- export { platform } from './config.js';
2
- export { OneBotAPI as API } from './sdk/api.js';
3
- export { useClient, useValue } from './hook.js';
4
-
1
+ export { platform } from './config';
2
+ export { OneBotAPI as API } from './sdk/api';
3
+ export * from './hook';
5
4
  declare const main: () => void;
6
-
7
- export { main as default };
5
+ export default main;
package/lib/index.js CHANGED
@@ -10,13 +10,9 @@ export { useClient, useValue } from './hook.js';
10
10
  const main = () => {
11
11
  const config = getOneBotConfig();
12
12
  const client = new OneBotClient({
13
- // url
14
13
  url: config?.url ?? '',
15
- // token
16
14
  access_token: config?.token ?? '',
17
- // 是否开启反向连接,正向连接失效
18
15
  reverse_enable: config?.reverse_enable ?? false,
19
- // 反向连接端口
20
16
  reverse_port: config?.reverse_port ?? 17158
21
17
  });
22
18
  void client.connect();
@@ -31,6 +27,7 @@ const main = () => {
31
27
  if (item.type === 'text') {
32
28
  msg += item.data.text;
33
29
  }
30
+ else if (item.type === 'at') ;
34
31
  }
35
32
  return msg.trim();
36
33
  };
@@ -45,7 +42,7 @@ const main = () => {
45
42
  const UserAvatar = createUserAvatar(UserId);
46
43
  const [isMaster, UserKey] = getMaster(UserId);
47
44
  const groupId = String(event.group_id);
48
- // 定义消
45
+ const readyId = event.message.find(item => item.type === 'reply')?.data?.id;
49
46
  const e = {
50
47
  name: 'message.create',
51
48
  Platform: platform,
@@ -61,6 +58,7 @@ const main = () => {
61
58
  MessageId: String(event.message_id),
62
59
  MessageText: msg.trim(),
63
60
  OpenId: UserId,
61
+ readyId,
64
62
  CreateAt: Date.now(),
65
63
  tag: 'message.create',
66
64
  value: event
@@ -72,7 +70,7 @@ const main = () => {
72
70
  const UserId = String(event.user_id);
73
71
  const UserAvatar = createUserAvatar(UserId);
74
72
  const [isMaster, UserKey] = getMaster(UserId);
75
- // 定义消
73
+ const readyId = event.message.find(item => item.type === 'reply')?.data?.id;
76
74
  const e = {
77
75
  name: 'private.message.create',
78
76
  Platform: platform,
@@ -86,17 +84,13 @@ const main = () => {
86
84
  MessageText: msg.trim(),
87
85
  OpenId: String(event.user_id),
88
86
  CreateAt: Date.now(),
87
+ readyId,
89
88
  tag: 'private.message.create',
90
89
  value: event
91
90
  };
92
91
  cbp.send(e);
93
92
  });
94
- /**
95
- * @param val
96
- * @returns
97
- */
98
93
  const DataToMessage = async (val = []) => {
99
- // 空元素
100
94
  const empty = {
101
95
  type: 'text',
102
96
  data: {
@@ -163,12 +157,6 @@ const main = () => {
163
157
  }));
164
158
  return message;
165
159
  };
166
- /**
167
- *
168
- * @param ChannelId
169
- * @param val
170
- * @returns
171
- */
172
160
  const sendGroup = async (ChannelId, val) => {
173
161
  if (val.length < 0) {
174
162
  return [];
@@ -185,12 +173,6 @@ const main = () => {
185
173
  return [createResult(ResultCode.Fail, 'client.groupOpenMessages', error)];
186
174
  }
187
175
  };
188
- /**
189
- *
190
- * @param UserId
191
- * @param val
192
- * @returns
193
- */
194
176
  const sendPrivate = async (UserId, val) => {
195
177
  if (val.length < 0) {
196
178
  return [];
@@ -279,6 +261,20 @@ const main = () => {
279
261
  };
280
262
  const onactions = async (data, consume) => {
281
263
  switch (data.action) {
264
+ case 'me.info': {
265
+ const res = await client.getLoginInfo();
266
+ const UserId = String(res?.user_id);
267
+ const [isMaster, UserKey] = getMaster(UserId);
268
+ const user = {
269
+ UserId: UserId,
270
+ UserName: res?.nickname,
271
+ IsBot: true,
272
+ IsMaster: isMaster,
273
+ UserAvatar: '',
274
+ UserKey: UserKey
275
+ };
276
+ return consume([createResult(ResultCode.Ok, '请求完成', user)]);
277
+ }
282
278
  case 'message.send': {
283
279
  const event = data.payload.event;
284
280
  const paramFormat = data.payload.params.format;
@@ -286,15 +282,15 @@ const main = () => {
286
282
  return consume(res);
287
283
  }
288
284
  case 'message.send.channel': {
289
- const channel_id = data.payload.ChannelId;
285
+ const ChannelId = data.payload.ChannelId;
290
286
  const val = data.payload.params.format;
291
- const res = await api.active.send.channel(channel_id, val);
287
+ const res = await api.active.send.channel(ChannelId, val);
292
288
  return consume(res);
293
289
  }
294
290
  case 'message.send.user': {
295
- const user_id = data.payload.UserId;
291
+ const UserId = data.payload.UserId;
296
292
  const val = data.payload.params.format;
297
- const res = await api.active.send.user(user_id, val);
293
+ const res = await api.active.send.user(UserId, val);
298
294
  return consume(res);
299
295
  }
300
296
  case 'mention.get': {
@@ -343,6 +339,9 @@ const main = () => {
343
339
  .catch(err => createResult(ResultCode.Fail, data.action, err));
344
340
  return consume([res]);
345
341
  }
342
+ default: {
343
+ return consume([createResult(ResultCode.Fail, '未知请求,请尝试升级版本', null)]);
344
+ }
346
345
  }
347
346
  };
348
347
  cbp.onactions((data, consume) => void onactions(data, consume));
@@ -353,21 +352,22 @@ const main = () => {
353
352
  const res = await client[key](...params);
354
353
  consume([createResult(ResultCode.Ok, '请求完成', res)]);
355
354
  }
355
+ else {
356
+ consume([createResult(ResultCode.Fail, '未知请求,请尝试升级版本', null)]);
357
+ }
356
358
  };
357
- // 处理 api 调用
358
359
  cbp.onapis((data, consume) => void onapis(data, consume));
359
360
  };
360
361
  const mainProcess = () => {
361
362
  ['SIGINT', 'SIGTERM', 'SIGQUIT', 'disconnect'].forEach(sig => {
362
363
  process?.on?.(sig, () => {
363
- logger?.info?.(`[@alemonjs/onebot][${sig}] 收到信号,正在关闭...`);
364
+ logger.info?.(`[@alemonjs/onebot][${sig}] 收到信号,正在关闭...`);
364
365
  setImmediate(() => process.exit(0));
365
366
  });
366
367
  });
367
368
  process?.on?.('exit', code => {
368
- logger?.info?.(`[@alemonjs/onebot][exit] 进程退出,code=${code}`);
369
+ logger.info?.(`[@alemonjs/onebot][exit] 进程退出,code=${code}`);
369
370
  });
370
- // 监听主进程消息
371
371
  process.on('message', msg => {
372
372
  try {
373
373
  const data = typeof msg === 'string' ? JSON.parse(msg) : msg;
@@ -380,7 +380,6 @@ const mainProcess = () => {
380
380
  }
381
381
  catch { }
382
382
  });
383
- // 主动发送 ready 消息
384
383
  if (process.send) {
385
384
  process.send(JSON.stringify({ type: 'ready' }));
386
385
  }
package/lib/sdk/api.d.ts CHANGED
@@ -1,91 +1,55 @@
1
1
  import WebSocket from 'ws';
2
-
3
- declare class OneBotAPI {
2
+ export declare const consume: (parsedMessage: any) => void;
3
+ export declare class OneBotAPI {
4
4
  ws: WebSocket | null;
5
- /**
6
- * 发送私聊消息
7
- * @param options
8
- * @returns
9
- */
10
5
  sendPrivateMessage(options: {
11
6
  user_id: number;
12
7
  message: any[];
13
8
  }): Promise<any>;
14
- /**
15
- * 发送群消息
16
- * @param options
17
- * @returns
18
- */
19
9
  sendGroupMessage(options: {
20
10
  group_id: number;
21
11
  message: any[];
22
12
  }): Promise<any>;
23
- /**
24
- * 发送消息
25
- * @param options
26
- * @returns
27
- */
28
13
  sendMessage(options: {
29
14
  message_type: 'private' | 'group';
30
15
  group_id?: number;
31
16
  user_id?: number;
32
17
  message: any[];
33
18
  }): Promise<any>;
34
- /**
35
- * 好友列表
36
- */
19
+ getLoginInfo(): Promise<any>;
20
+ getMsg(options: {
21
+ message_id: number;
22
+ }): Promise<any>;
37
23
  getFriendList(): Promise<any>;
38
- /**
39
- * 群列表
40
- */
41
24
  getGroupList(): Promise<any>;
42
- /**
43
- * 群成员列表
44
- * @param options
45
- * @returns
46
- */
47
25
  getGroupMemberList(options: {
48
26
  group_id: number;
49
27
  }): Promise<any>;
50
- /**
51
- * 处理好友请求
52
- * @param options
53
- * @returns
54
- */
55
28
  setFriendAddRequest(options: {
56
29
  flag: string;
57
30
  approve: boolean;
58
31
  remark?: string;
59
32
  }): Promise<any>;
60
- /**
61
- * 处理群请求
62
- * @param options
63
- * @returns
64
- */
65
33
  setGroupAddRequest(options: {
66
34
  flag: string;
67
35
  sub_type: string;
68
36
  approve: boolean;
69
37
  reason?: string;
70
38
  }): Promise<any>;
71
- /** 撤回消息 */
72
39
  deleteMsg(options: {
73
40
  message_id: number;
74
41
  }): Promise<any>;
75
- /** 上传私聊文件 */
76
42
  uploadPrivateFile(options: {
77
43
  user_id: number;
78
44
  file: string;
79
45
  name?: string;
80
46
  }): Promise<any>;
81
- /** 上传群文件 */
82
47
  uploadGroupFile(options: {
83
48
  group_id: number;
84
49
  file: string;
85
50
  name?: string;
86
51
  folder?: string;
87
52
  }): Promise<any>;
88
- /** 发送私聊转发 */
89
53
  sendPrivateForward(options: {
90
54
  user_id: number;
91
55
  messages: {
@@ -95,7 +59,6 @@ declare class OneBotAPI {
95
59
  nickname?: string;
96
60
  }[];
97
61
  }): Promise<any>;
98
- /** 发送群转发 */
99
62
  sendGroupForward(options: {
100
63
  group_id: number;
101
64
  messages: {
@@ -106,5 +69,3 @@ declare class OneBotAPI {
106
69
  }[];
107
70
  }): Promise<any>;
108
71
  }
109
-
110
- export { OneBotAPI };
package/lib/sdk/api.js CHANGED
@@ -1,42 +1,26 @@
1
1
  import { generateUniqueId, actionResolves, actionTimeouts, timeoutTime } from './config.js';
2
2
 
3
- /**
4
- *
5
- * @param ws
6
- * @param data
7
- * @returns
8
- */
9
3
  const send = (ws, data) => {
10
4
  const id = generateUniqueId();
11
- // 设置唯一标识符
12
5
  data.echo = id;
13
6
  return new Promise((resolve, reject) => {
14
7
  actionResolves.set(id, { resolve, reject });
15
- // 发送消息
16
8
  ws.send(JSON.stringify(data));
17
- // 30 秒后超时
18
9
  const timeout = setTimeout(() => {
19
- // 被清理了
20
10
  if (!actionResolves.has(id) || !actionTimeouts.has(id)) {
21
11
  return;
22
12
  }
23
- // 删除回调
24
13
  actionResolves.delete(id);
25
- // 删除超时器
26
14
  actionTimeouts.delete(id);
27
- // 不会当错误进行处理。而是传入错误码
28
15
  resolve(null);
29
16
  }, timeoutTime);
30
17
  actionTimeouts.set(id, timeout);
31
18
  });
32
19
  };
33
- // 消费
34
20
  const consume = (parsedMessage) => {
35
- // 读取 唯一标识
36
21
  const id = parsedMessage.echo;
37
22
  const { resolve, reject } = actionResolves.get(id) || {};
38
23
  actionResolves.delete(id);
39
- // 清除超时器
40
24
  const timeout = actionTimeouts.get(id);
41
25
  if (timeout) {
42
26
  actionTimeouts.delete(id);
@@ -53,11 +37,6 @@ const consume = (parsedMessage) => {
53
37
  };
54
38
  class OneBotAPI {
55
39
  ws = null;
56
- /**
57
- * 发送私聊消息
58
- * @param options
59
- * @returns
60
- */
61
40
  sendPrivateMessage(options) {
62
41
  if (!this.ws) {
63
42
  return;
@@ -67,11 +46,6 @@ class OneBotAPI {
67
46
  params: options
68
47
  });
69
48
  }
70
- /**
71
- * 发送群消息
72
- * @param options
73
- * @returns
74
- */
75
49
  sendGroupMessage(options) {
76
50
  if (!this.ws) {
77
51
  return;
@@ -81,11 +55,6 @@ class OneBotAPI {
81
55
  params: options
82
56
  });
83
57
  }
84
- /**
85
- * 发送消息
86
- * @param options
87
- * @returns
88
- */
89
58
  sendMessage(options) {
90
59
  if (!this.ws) {
91
60
  return;
@@ -95,9 +64,24 @@ class OneBotAPI {
95
64
  params: options
96
65
  });
97
66
  }
98
- /**
99
- * 好友列表
100
- */
67
+ getLoginInfo() {
68
+ if (!this.ws) {
69
+ return;
70
+ }
71
+ return send(this.ws, {
72
+ action: 'get_login_info',
73
+ params: {}
74
+ });
75
+ }
76
+ getMsg(options) {
77
+ if (!this.ws) {
78
+ return;
79
+ }
80
+ return send(this.ws, {
81
+ action: 'get_msg',
82
+ params: options
83
+ });
84
+ }
101
85
  getFriendList() {
102
86
  if (!this.ws) {
103
87
  return;
@@ -107,9 +91,6 @@ class OneBotAPI {
107
91
  params: {}
108
92
  });
109
93
  }
110
- /**
111
- * 群列表
112
- */
113
94
  getGroupList() {
114
95
  if (!this.ws) {
115
96
  return;
@@ -119,11 +100,6 @@ class OneBotAPI {
119
100
  params: {}
120
101
  });
121
102
  }
122
- /**
123
- * 群成员列表
124
- * @param options
125
- * @returns
126
- */
127
103
  getGroupMemberList(options) {
128
104
  if (!this.ws) {
129
105
  return;
@@ -133,11 +109,6 @@ class OneBotAPI {
133
109
  params: options
134
110
  });
135
111
  }
136
- /**
137
- * 处理好友请求
138
- * @param options
139
- * @returns
140
- */
141
112
  setFriendAddRequest(options) {
142
113
  if (!this.ws) {
143
114
  return;
@@ -147,11 +118,6 @@ class OneBotAPI {
147
118
  params: options
148
119
  });
149
120
  }
150
- /**
151
- * 处理群请求
152
- * @param options
153
- * @returns
154
- */
155
121
  setGroupAddRequest(options) {
156
122
  if (!this.ws) {
157
123
  return;
@@ -161,7 +127,6 @@ class OneBotAPI {
161
127
  params: options
162
128
  });
163
129
  }
164
- /** 撤回消息 */
165
130
  deleteMsg(options) {
166
131
  if (!this.ws) {
167
132
  return;
@@ -171,7 +136,6 @@ class OneBotAPI {
171
136
  params: options
172
137
  });
173
138
  }
174
- /** 上传私聊文件 */
175
139
  uploadPrivateFile(options) {
176
140
  if (!this.ws) {
177
141
  return;
@@ -181,7 +145,6 @@ class OneBotAPI {
181
145
  params: options
182
146
  });
183
147
  }
184
- /** 上传群文件 */
185
148
  uploadGroupFile(options) {
186
149
  if (!this.ws) {
187
150
  return;
@@ -191,7 +154,6 @@ class OneBotAPI {
191
154
  params: options
192
155
  });
193
156
  }
194
- /** 发送私聊转发 */
195
157
  sendPrivateForward(options) {
196
158
  if (!this.ws) {
197
159
  return;
@@ -206,7 +168,6 @@ class OneBotAPI {
206
168
  }
207
169
  });
208
170
  }
209
- /** 发送群转发 */
210
171
  sendGroupForward(options) {
211
172
  if (!this.ws) {
212
173
  return;
@@ -0,0 +1,7 @@
1
+ export declare const actionResolves: Map<string, {
2
+ resolve: (value: any) => void;
3
+ reject: (reason?: any) => void;
4
+ }>;
5
+ export declare const actionTimeouts: Map<string, NodeJS.Timeout>;
6
+ export declare const generateUniqueId: () => string;
7
+ export declare const timeoutTime: number;
package/lib/sdk/config.js CHANGED
@@ -1,12 +1,8 @@
1
- // 行为回调
2
1
  const actionResolves = new Map();
3
- // 超时器
4
2
  const actionTimeouts = new Map();
5
- // 生成唯一标识符
6
3
  const generateUniqueId = () => {
7
4
  return Date.now().toString(36) + Math.random().toString(36).substring(2);
8
5
  };
9
- // 超时时间
10
- const timeoutTime = 1000 * 12; // 12秒
6
+ const timeoutTime = 1000 * 12;
11
7
 
12
8
  export { actionResolves, actionTimeouts, generateUniqueId, timeoutTime };
@@ -28,8 +28,13 @@ type Message = {
28
28
  id: number;
29
29
  content: any[];
30
30
  };
31
+ } | {
32
+ type: 'reply';
33
+ data: {
34
+ id: string;
35
+ };
31
36
  };
32
- interface MESSAGES_TYPE {
37
+ export interface MESSAGES_TYPE {
33
38
  self_id: number;
34
39
  user_id: number;
35
40
  time: number;
@@ -46,7 +51,7 @@ interface MESSAGES_TYPE {
46
51
  post_type: 'message';
47
52
  group_id: number;
48
53
  }
49
- interface DIRECT_MESSAGE_TYPE {
54
+ export interface DIRECT_MESSAGE_TYPE {
50
55
  self_id: number;
51
56
  user_id: number;
52
57
  time: number;
@@ -68,5 +73,41 @@ interface DIRECT_MESSAGE_TYPE {
68
73
  group_id: number;
69
74
  temp_source: number;
70
75
  }
71
-
72
- export type { DIRECT_MESSAGE_TYPE, MESSAGES_TYPE };
76
+ export interface meta_event_lifecycle {
77
+ time: number;
78
+ self_id: number;
79
+ post_type: 'meta_event';
80
+ meta_event_type: 'lifecycle';
81
+ sub_type: 'connect';
82
+ }
83
+ export interface meta_event_heartbeat {
84
+ time: number;
85
+ self_id: number;
86
+ post_type: 'meta_event';
87
+ meta_event_type: 'heartbeat';
88
+ status: {
89
+ online: boolean;
90
+ good: boolean;
91
+ };
92
+ interval: number;
93
+ }
94
+ export interface group_recall {
95
+ time: number;
96
+ self_id: number;
97
+ post_type: 'notice';
98
+ group_id: number;
99
+ user_id: number;
100
+ notice_type: 'group_recall';
101
+ operator_id: number;
102
+ message_id: number;
103
+ }
104
+ export interface request_friend {
105
+ time: number;
106
+ self_id: number;
107
+ post_type: 'request';
108
+ request_type: 'friend';
109
+ user_id: number;
110
+ comment: string;
111
+ flag: string;
112
+ }
113
+ export {};
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,10 @@
1
+ import { MESSAGES_TYPE, DIRECT_MESSAGE_TYPE, meta_event_lifecycle, meta_event_heartbeat } from './types';
2
+ export type OneBotEventMap = {
3
+ DIRECT_MESSAGE: DIRECT_MESSAGE_TYPE;
4
+ MESSAGES: MESSAGES_TYPE;
5
+ META: meta_event_lifecycle | meta_event_heartbeat;
6
+ REQUEST_ADD_FRIEND: any;
7
+ REQUEST_ADD_GROUP: any;
8
+ NOTICE_GROUP_MEMBER_INCREASE: any;
9
+ NOTICE_GROUP_MEMBER_REDUCE: any;
10
+ };
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,13 @@
1
+ import { OneBotAPI } from './api';
2
+ import { OneBotEventMap } from './typing';
3
+ export declare class OneBotClient extends OneBotAPI {
4
+ #private;
5
+ constructor(opstion: {
6
+ url: string;
7
+ access_token: string;
8
+ reverse_enable: boolean;
9
+ reverse_port: number;
10
+ });
11
+ on<T extends keyof OneBotEventMap>(key: T, val: (event: OneBotEventMap[T]) => any): this;
12
+ connect(): void;
13
+ }
package/lib/sdk/wss.js CHANGED
@@ -2,9 +2,6 @@ import WebSocket, { WebSocketServer } from 'ws';
2
2
  import { OneBotAPI, consume } from './api.js';
3
3
  import dayjs from 'dayjs';
4
4
 
5
- /**
6
- * 连接
7
- */
8
5
  class OneBotClient extends OneBotAPI {
9
6
  #options = {
10
7
  url: '',
@@ -12,10 +9,6 @@ class OneBotClient extends OneBotAPI {
12
9
  reverse_enable: false,
13
10
  reverse_port: 17158
14
11
  };
15
- /**
16
- * 设置配置
17
- * @param opstion
18
- */
19
12
  constructor(opstion) {
20
13
  super();
21
14
  for (const key in opstion) {
@@ -25,7 +18,6 @@ class OneBotClient extends OneBotAPI {
25
18
  }
26
19
  }
27
20
  #events = {};
28
- // 重连次数
29
21
  #count = 0;
30
22
  #getReConnectTime() {
31
23
  const time = this.#count > 3 ? 1000 * 6 : 1000 * 1;
@@ -34,20 +26,10 @@ class OneBotClient extends OneBotAPI {
34
26
  this.#count++;
35
27
  return curTime;
36
28
  }
37
- /**
38
- * 注册事件处理程序
39
- * @param key 事件名称
40
- * @param val 事件处理函数
41
- */
42
29
  on(key, val) {
43
30
  this.#events[key] = val;
44
31
  return this;
45
32
  }
46
- /**
47
- *
48
- * @param cfg
49
- * @param conversation
50
- */
51
33
  connect() {
52
34
  const { url, access_token: token, reverse_enable, reverse_port } = this.#options;
53
35
  const notToken = !token || token === '';
@@ -83,20 +65,17 @@ class OneBotClient extends OneBotAPI {
83
65
  }
84
66
  else if (event?.post_type === 'notice') {
85
67
  if (event?.notice_type === 'group_increase') {
86
- // 群成员增加
87
68
  if (this.#events['NOTICE_GROUP_MEMBER_INCREASE']) {
88
69
  this.#events['NOTICE_GROUP_MEMBER_INCREASE'](event);
89
70
  }
90
71
  }
91
72
  else if (event?.notice_type === 'group_decrease') {
92
- // 群成员减少
93
73
  if (this.#events['NOTICE_GROUP_MEMBER_REDUCE']) {
94
74
  this.#events['NOTICE_GROUP_MEMBER_REDUCE'](event);
95
75
  }
96
76
  }
97
77
  }
98
78
  else if (event?.post_type === 'request') {
99
- // 收到加群 或 加好友的请求。
100
79
  if (event?.request_type === 'friend') {
101
80
  if (this.#events['REQUEST_ADD_FRIEND']) {
102
81
  this.#events['REQUEST_ADD_FRIEND'](event);
@@ -109,7 +88,6 @@ class OneBotClient extends OneBotAPI {
109
88
  }
110
89
  }
111
90
  else if (event?.echo) {
112
- // 消费
113
91
  consume(event);
114
92
  }
115
93
  }
@@ -129,27 +107,21 @@ class OneBotClient extends OneBotAPI {
129
107
  };
130
108
  if (!this.ws) {
131
109
  if (reverse_enable) {
132
- // reverse_open
133
110
  const server = new WebSocketServer({ port: reverse_port ?? 17158 });
134
111
  server.on('connection', ws => {
135
112
  this.ws = ws;
136
- // message
137
113
  this.ws.on('message', onMessage);
138
- // close
139
114
  this.ws.on('close', onClose);
140
115
  logger.info(`[OneBot] connected: ws://127.0.0.1:${reverse_port}`);
141
116
  });
142
117
  }
143
118
  else {
144
- // forward_open
145
119
  this.ws = new WebSocket(url, c);
146
120
  this.ws.on('open', () => {
147
121
  logger.info(`[OneBot] connected: ${url}`);
148
122
  this.#count = 0;
149
123
  });
150
- // message
151
124
  this.ws.on('message', onMessage);
152
- // close
153
125
  this.ws.on('close', onClose);
154
126
  }
155
127
  }
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@alemonjs/onebot",
3
- "version": "2.1.0-alpha.11",
4
- "description": "onebot v11",
3
+ "version": "2.1.0-alpha.12",
4
+ "description": "oneBot v11",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",
7
7
  "type": "module",
8
8
  "main": "lib/index.js",
9
9
  "types": "lib",
10
10
  "scripts": {
11
- "build": "node bundle.js"
11
+ "build": "lvy build"
12
12
  },
13
13
  "exports": {
14
14
  ".": {
@@ -47,4 +47,4 @@
47
47
  "type": "git",
48
48
  "url": "https://github.com/lemonade-lab/alemonjs.git"
49
49
  }
50
- }
50
+ }