hotcat-bot-qq 0.1.6 → 0.1.8

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/dist/botEvent.js CHANGED
@@ -24,11 +24,16 @@ export class MessageEvent {
24
24
  });
25
25
  this.napcat = napcat;
26
26
  this.client = client;
27
+ this.napcat.on('message.group', (event) => {
28
+ new BotConsole('groupMessage', event).log();
29
+ });
30
+ this.napcat.on('message.private', (event) => {
31
+ new BotConsole('privateMessage', event).log();
32
+ });
27
33
  }
28
34
  onGroupMessage(fn) {
29
35
  const w = async (event) => {
30
36
  try {
31
- new BotConsole('groupMessage', event).log();
32
37
  await fn(this.client, event);
33
38
  }
34
39
  catch (e) {
@@ -48,7 +53,6 @@ export class MessageEvent {
48
53
  onGroupNormal(fn) {
49
54
  const w = async (event) => {
50
55
  try {
51
- new BotConsole('groupMessage', event).log();
52
56
  await fn(this.client, event);
53
57
  }
54
58
  catch (e) {
@@ -68,7 +72,6 @@ export class MessageEvent {
68
72
  onPrivateMessage(fn) {
69
73
  const w = async (event) => {
70
74
  try {
71
- new BotConsole('privateMessage', event).log();
72
75
  await fn(this.client, event);
73
76
  }
74
77
  catch (e) {
@@ -88,7 +91,6 @@ export class MessageEvent {
88
91
  onPrivateFriend(fn) {
89
92
  const w = async (event) => {
90
93
  try {
91
- new BotConsole('privateMessage', event).log();
92
94
  await fn(this.client, event);
93
95
  }
94
96
  catch (e) {
@@ -108,7 +110,6 @@ export class MessageEvent {
108
110
  onPrivateGroup(fn) {
109
111
  const w = async (event) => {
110
112
  try {
111
- new BotConsole('privateMessage', event).log();
112
113
  await fn(this.client, event);
113
114
  }
114
115
  catch (e) {
@@ -151,11 +152,16 @@ export class MessageSent {
151
152
  });
152
153
  this.napcat = napcat;
153
154
  this.client = client;
155
+ this.napcat.on('message_sent.group', (event) => {
156
+ new BotConsole('groupMessageSelf', event).log();
157
+ });
158
+ this.napcat.on('message_sent.private', (event) => {
159
+ new BotConsole('privateMessageSelf', event).log();
160
+ });
154
161
  }
155
162
  onGroupSent(fn) {
156
163
  const w = async (event) => {
157
164
  try {
158
- new BotConsole('groupMessageSelf', event).log();
159
165
  await fn(this.client, event);
160
166
  }
161
167
  catch (e) {
@@ -175,7 +181,6 @@ export class MessageSent {
175
181
  onGroupNormal(fn) {
176
182
  const w = async (event) => {
177
183
  try {
178
- new BotConsole('groupMessageSelf', event).log();
179
184
  await fn(this.client, event);
180
185
  }
181
186
  catch (e) {
@@ -195,7 +200,6 @@ export class MessageSent {
195
200
  onPrivateSent(fn) {
196
201
  const w = async (event) => {
197
202
  try {
198
- new BotConsole('privateMessageSelf', event).log();
199
203
  await fn(this.client, event);
200
204
  }
201
205
  catch (e) {
@@ -215,7 +219,6 @@ export class MessageSent {
215
219
  onPrivateFriend(fn) {
216
220
  const w = async (event) => {
217
221
  try {
218
- new BotConsole('privateMessageSelf', event).log();
219
222
  await fn(this.client, event);
220
223
  }
221
224
  catch (e) {
@@ -235,7 +238,6 @@ export class MessageSent {
235
238
  onPrivateGroup(fn) {
236
239
  const w = async (event) => {
237
240
  try {
238
- new BotConsole('privateMessageSelf', event).log();
239
241
  await fn(this.client, event);
240
242
  }
241
243
  catch (e) {
@@ -278,11 +280,19 @@ export class RequestEvent {
278
280
  });
279
281
  this.napcat = napcat;
280
282
  this.client = client;
283
+ this.napcat.on('request.friend', (event) => {
284
+ new BotConsole('requestFriend', event).log();
285
+ });
286
+ this.napcat.on('request.group.add', (event) => {
287
+ new BotConsole('requestGroupAdd', event).log();
288
+ });
289
+ this.napcat.on('request.group.invite', (event) => {
290
+ new BotConsole('requestGroupInvite', event).log();
291
+ });
281
292
  }
282
293
  onFriend(fn) {
283
294
  const w = async (event) => {
284
295
  try {
285
- new BotConsole('requestFriend', event).log();
286
296
  await fn(this.client, event);
287
297
  }
288
298
  catch (e) {
@@ -302,7 +312,6 @@ export class RequestEvent {
302
312
  onGroupAdd(fn) {
303
313
  const w = async (event) => {
304
314
  try {
305
- new BotConsole('requestGroupAdd', event).log();
306
315
  await fn(this.client, event);
307
316
  }
308
317
  catch (e) {
@@ -322,7 +331,6 @@ export class RequestEvent {
322
331
  onGroupInvite(fn) {
323
332
  const w = async (event) => {
324
333
  try {
325
- new BotConsole('requestGroupInvite', event).log();
326
334
  await fn(this.client, event);
327
335
  }
328
336
  catch (e) {
@@ -342,8 +350,6 @@ export class RequestEvent {
342
350
  onGroupRequest(fn) {
343
351
  const w = async (event) => {
344
352
  try {
345
- const type = event.sub_type === 'add' ? 'requestGroupAdd' : 'requestGroupInvite';
346
- new BotConsole(type, event).log();
347
353
  await fn(this.client, event);
348
354
  }
349
355
  catch (e) {
@@ -386,11 +392,29 @@ export class NoticeEvent {
386
392
  });
387
393
  this.napcat = napcat;
388
394
  this.client = client;
395
+ const log = (event) => {
396
+ new BotConsole('notice', event).log();
397
+ };
398
+ this.napcat.on('notice.friend_add', log);
399
+ this.napcat.on('notice.friend_recall', log);
400
+ this.napcat.on('notice.group_admin', log);
401
+ this.napcat.on('notice.group_ban', log);
402
+ this.napcat.on('notice.group_card', log);
403
+ this.napcat.on('notice.group_decrease', log);
404
+ this.napcat.on('notice.group_increase', log);
405
+ this.napcat.on('notice.group_recall', log);
406
+ this.napcat.on('notice.group_upload', log);
407
+ this.napcat.on('notice.group_msg_emoji_like', log);
408
+ this.napcat.on('notice.essence', log);
409
+ this.napcat.on('notice.notify.poke', log);
410
+ this.napcat.on('notice.notify.group_name', log);
411
+ this.napcat.on('notice.notify.title', log);
412
+ this.napcat.on('notice.notify.profile_like', log);
413
+ this.napcat.on('notice.bot_offline', log);
389
414
  }
390
415
  onFriendAdd(fn) {
391
416
  const w = async (event) => {
392
417
  try {
393
- new BotConsole('notice', event).log();
394
418
  await fn(this.client, event);
395
419
  }
396
420
  catch (e) {
@@ -410,7 +434,6 @@ export class NoticeEvent {
410
434
  onFriendRecall(fn) {
411
435
  const w = async (event) => {
412
436
  try {
413
- new BotConsole('notice', event).log();
414
437
  await fn(this.client, event);
415
438
  }
416
439
  catch (e) {
@@ -430,7 +453,6 @@ export class NoticeEvent {
430
453
  onGroupAdmin(fn) {
431
454
  const w = async (event) => {
432
455
  try {
433
- new BotConsole('notice', event).log();
434
456
  await fn(this.client, event);
435
457
  }
436
458
  catch (e) {
@@ -450,7 +472,6 @@ export class NoticeEvent {
450
472
  onGroupBan(fn) {
451
473
  const w = async (event) => {
452
474
  try {
453
- new BotConsole('notice', event).log();
454
475
  await fn(this.client, event);
455
476
  }
456
477
  catch (e) {
@@ -470,7 +491,6 @@ export class NoticeEvent {
470
491
  onGroupCard(fn) {
471
492
  const w = async (event) => {
472
493
  try {
473
- new BotConsole('notice', event).log();
474
494
  await fn(this.client, event);
475
495
  }
476
496
  catch (e) {
@@ -490,7 +510,6 @@ export class NoticeEvent {
490
510
  onGroupDecrease(fn) {
491
511
  const w = async (event) => {
492
512
  try {
493
- new BotConsole('notice', event).log();
494
513
  await fn(this.client, event);
495
514
  }
496
515
  catch (e) {
@@ -510,7 +529,6 @@ export class NoticeEvent {
510
529
  onGroupIncrease(fn) {
511
530
  const w = async (event) => {
512
531
  try {
513
- new BotConsole('notice', event).log();
514
532
  await fn(this.client, event);
515
533
  }
516
534
  catch (e) {
@@ -530,7 +548,6 @@ export class NoticeEvent {
530
548
  onGroupRecall(fn) {
531
549
  const w = async (event) => {
532
550
  try {
533
- new BotConsole('notice', event).log();
534
551
  await fn(this.client, event);
535
552
  }
536
553
  catch (e) {
@@ -550,7 +567,6 @@ export class NoticeEvent {
550
567
  onGroupUpload(fn) {
551
568
  const w = async (event) => {
552
569
  try {
553
- new BotConsole('notice', event).log();
554
570
  await fn(this.client, event);
555
571
  }
556
572
  catch (e) {
@@ -570,7 +586,6 @@ export class NoticeEvent {
570
586
  onGroupEmojiLike(fn) {
571
587
  const w = async (event) => {
572
588
  try {
573
- new BotConsole('notice', event).log();
574
589
  await fn(this.client, event);
575
590
  }
576
591
  catch (e) {
@@ -590,7 +605,6 @@ export class NoticeEvent {
590
605
  onGroupEssence(fn) {
591
606
  const w = async (event) => {
592
607
  try {
593
- new BotConsole('notice', event).log();
594
608
  await fn(this.client, event);
595
609
  }
596
610
  catch (e) {
@@ -610,7 +624,6 @@ export class NoticeEvent {
610
624
  onPoke(fn) {
611
625
  const w = async (event) => {
612
626
  try {
613
- new BotConsole('notice', event).log();
614
627
  await fn(this.client, event);
615
628
  }
616
629
  catch (e) {
@@ -630,7 +643,6 @@ export class NoticeEvent {
630
643
  onGroupNameChange(fn) {
631
644
  const w = async (event) => {
632
645
  try {
633
- new BotConsole('notice', event).log();
634
646
  await fn(this.client, event);
635
647
  }
636
648
  catch (e) {
@@ -650,7 +662,6 @@ export class NoticeEvent {
650
662
  onTitleChange(fn) {
651
663
  const w = async (event) => {
652
664
  try {
653
- new BotConsole('notice', event).log();
654
665
  await fn(this.client, event);
655
666
  }
656
667
  catch (e) {
@@ -670,7 +681,6 @@ export class NoticeEvent {
670
681
  onProfileLike(fn) {
671
682
  const w = async (event) => {
672
683
  try {
673
- new BotConsole('notice', event).log();
674
684
  await fn(this.client, event);
675
685
  }
676
686
  catch (e) {
@@ -690,7 +700,6 @@ export class NoticeEvent {
690
700
  onBotOffline(fn) {
691
701
  const w = async (event) => {
692
702
  try {
693
- new BotConsole('notice', event).log();
694
703
  await fn(this.client, event);
695
704
  }
696
705
  catch (e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hotcat-bot-qq",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "基于 node-napcat-ts 的 TypeScript QQ 机器人框架",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -52,7 +52,8 @@
52
52
  ],
53
53
  "scripts": {
54
54
  "build": "tsc -p tsconfig.build.json",
55
- "prepublishOnly": "bun run build",
55
+ "build:plugin": "tsc --outDir plugins/hotCatPlugin --rootDir plugins/hotCatPlugin --module ESNext --target ES2020 --moduleResolution bundler --declaration --skipLibCheck plugins/hotCatPlugin/index.ts",
56
+ "prepublishOnly": "bun run build && bun run build:plugin",
56
57
  "docs:dev": "vitepress dev docs",
57
58
  "docs:build": "vitepress build docs",
58
59
  "docs:preview": "vitepress preview docs"
@@ -0,0 +1,17 @@
1
+ import { PluginBase } from 'hotcat-bot-qq/plugin';
2
+ import { BotApi } from 'hotcat-bot-qq/botApi';
3
+ import { BotClient } from 'hotcat-bot-qq/botClient';
4
+ export declare class HotCatPlugin extends PluginBase {
5
+ static meta: {
6
+ name: string;
7
+ version: string;
8
+ description: string;
9
+ author: string;
10
+ };
11
+ private startTime;
12
+ static create(api: BotApi, bot: BotClient): HotCatPlugin;
13
+ load(): Promise<void>;
14
+ unload(): Promise<void>;
15
+ private onGroupMsg;
16
+ private formatUptime;
17
+ }
@@ -0,0 +1,51 @@
1
+ import { PluginBase } from 'hotcat-bot-qq/plugin';
2
+ import { Message } from 'hotcat-bot-qq/message';
3
+ import * as os from 'os';
4
+ export class HotCatPlugin extends PluginBase {
5
+ constructor() {
6
+ super(...arguments);
7
+ this.startTime = 0;
8
+ this.onGroupMsg = async (_bot, event) => {
9
+ const msg = event.raw_message.trim();
10
+ if (msg === '#hotCat' || msg === '#hotcat') {
11
+ const uptime = this.formatUptime(Date.now() - this.startTime);
12
+ const platform = os.platform();
13
+ const arch = os.arch();
14
+ await this.api.sendGroupMessage(event.group_id, Message.reply(event.message_id), Message.text(`HotCat 信息\n` +
15
+ `版本:${this.meta.version}\n` +
16
+ `平台:${platform} ${arch}\n` +
17
+ `运行时间:${uptime}`));
18
+ }
19
+ };
20
+ }
21
+ static create(api, bot) {
22
+ return new HotCatPlugin(api, bot);
23
+ }
24
+ async load() {
25
+ this.startTime = Date.now();
26
+ this.bot.event.message.onGroupMessage(this.onGroupMsg);
27
+ }
28
+ async unload() {
29
+ this.bot.event.message.offGroupMessage(this.onGroupMsg);
30
+ }
31
+ formatUptime(ms) {
32
+ const s = Math.floor(ms / 1000);
33
+ const d = Math.floor(s / 86400);
34
+ const h = Math.floor((s % 86400) / 3600);
35
+ const m = Math.floor((s % 3600) / 60);
36
+ const parts = [];
37
+ if (d > 0)
38
+ parts.push(`${d}天`);
39
+ if (h > 0)
40
+ parts.push(`${h}小时`);
41
+ if (m > 0)
42
+ parts.push(`${m}分钟`);
43
+ return parts.length > 0 ? parts.join(' ') : '小于1分钟';
44
+ }
45
+ }
46
+ HotCatPlugin.meta = {
47
+ name: 'hotCatPlugin',
48
+ version: '0.1.8',
49
+ description: 'HotCat 默认插件(#hotCat 指令查询 bot 状态)',
50
+ author: 'CHCAT1320',
51
+ };
@@ -7,7 +7,7 @@ import * as os from 'os'
7
7
  export class HotCatPlugin extends PluginBase {
8
8
  static meta = {
9
9
  name: 'hotCatPlugin',
10
- version: '0.1.6',
10
+ version: '0.1.8',
11
11
  description: 'HotCat 默认插件(#hotCat 指令查询 bot 状态)',
12
12
  author: 'CHCAT1320',
13
13
  }