hotcat-bot-qq 0.1.6 → 0.1.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hotcat-bot-qq",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
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.7',
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.7',
11
11
  description: 'HotCat 默认插件(#hotCat 指令查询 bot 状态)',
12
12
  author: 'CHCAT1320',
13
13
  }