hotcat-bot-qq 0.1.8 → 0.1.10
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/README.md +54 -53
- package/dist/botApi.js +1 -1
- package/dist/botClient.d.ts +1 -0
- package/dist/botClient.js +57 -12
- package/dist/botEvent.js +1 -1
- package/dist/botPlugin.js +6 -3
- package/dist/index.js +8 -8
- package/package.json +2 -2
- package/plugins/hotCatPlugin/index.js +7 -2
- package/plugins/hotCatPlugin/index.ts +7 -2
package/README.md
CHANGED
|
@@ -1,53 +1,54 @@
|
|
|
1
|
-
# HotCat Bot
|
|
2
|
-
|
|
3
|
-
基于 [node-napcat-ts](https://github.com/HkTeamX/node-napcat-ts) 的 TypeScript QQ 机器人框架。
|
|
4
|
-
|
|
5
|
-
<p align="center">
|
|
6
|
-
<img src="logo.png" width="120" alt="HotCat Bot Logo">
|
|
7
|
-
</p>
|
|
8
|
-
|
|
9
|
-
## 安装
|
|
10
|
-
|
|
11
|
-
```bash
|
|
12
|
-
npm add hotcat-bot-qq
|
|
13
|
-
# or
|
|
14
|
-
pnpm add hotcat-bot-qq
|
|
15
|
-
# or
|
|
16
|
-
bun add hotcat-bot-qq
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
## 快速开始
|
|
20
|
-
|
|
21
|
-
```ts
|
|
22
|
-
import { BotClient } from './botClient'
|
|
23
|
-
import { Message } from './message'
|
|
24
|
-
|
|
25
|
-
const bot = new BotClient({
|
|
26
|
-
baseUrl: 'ws://localhost:8082/onebot/v11/ws/',
|
|
27
|
-
accessToken: 'your-access-token',
|
|
28
|
-
})
|
|
29
|
-
await bot.start()
|
|
30
|
-
|
|
31
|
-
bot.event.message.onGroupMessage(async (bot, event) => {
|
|
32
|
-
await bot.api.sendGroupMessage(event.group_id,
|
|
33
|
-
Message.reply(event.message_id),
|
|
34
|
-
Message.text('pong!')
|
|
35
|
-
)
|
|
36
|
-
})
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
## 特性
|
|
40
|
-
|
|
41
|
-
- **类型安全** — 完整的 TypeScript 类型推导,封装 napcat 全部 API
|
|
42
|
-
- **消息段构建** — `Message` 类支持文本、图片、表情、文件等所有消息类型
|
|
43
|
-
- **事件系统** — `BotEvent` 按类别分组暴露 message/messageSent/request/notice 事件
|
|
44
|
-
- **定时任务** — `BotScheduler` 支持 cron 表达式、固定间隔、指定时间
|
|
45
|
-
- **插件系统** — 继承 `PluginBase` 即可开发插件,支持热重载、目录监听自动加载,`scan` + `watch` 零配置接入
|
|
46
|
-
|
|
47
|
-
## 文档
|
|
48
|
-
|
|
49
|
-
完整文档 → [框架开发文档](https://hotcat-bot-qq.docs.chcat1320.top)
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
1
|
+
# HotCat Bot
|
|
2
|
+
|
|
3
|
+
基于 [node-napcat-ts](https://github.com/HkTeamX/node-napcat-ts) 的 TypeScript QQ 机器人框架。
|
|
4
|
+
|
|
5
|
+
<p align="center">
|
|
6
|
+
<img src="logo.png" width="120" alt="HotCat Bot Logo">
|
|
7
|
+
</p>
|
|
8
|
+
|
|
9
|
+
## 安装
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm add hotcat-bot-qq
|
|
13
|
+
# or
|
|
14
|
+
pnpm add hotcat-bot-qq
|
|
15
|
+
# or
|
|
16
|
+
bun add hotcat-bot-qq
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## 快速开始
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { BotClient } from './botClient'
|
|
23
|
+
import { Message } from './message'
|
|
24
|
+
|
|
25
|
+
const bot = new BotClient({
|
|
26
|
+
baseUrl: 'ws://localhost:8082/onebot/v11/ws/',
|
|
27
|
+
accessToken: 'your-access-token',
|
|
28
|
+
})
|
|
29
|
+
await bot.start()
|
|
30
|
+
|
|
31
|
+
bot.event.message.onGroupMessage(async (bot, event) => {
|
|
32
|
+
await bot.api.sendGroupMessage(event.group_id,
|
|
33
|
+
Message.reply(event.message_id),
|
|
34
|
+
Message.text('pong!')
|
|
35
|
+
)
|
|
36
|
+
})
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## 特性
|
|
40
|
+
|
|
41
|
+
- **类型安全** — 完整的 TypeScript 类型推导,封装 napcat 全部 API
|
|
42
|
+
- **消息段构建** — `Message` 类支持文本、图片、表情、文件等所有消息类型
|
|
43
|
+
- **事件系统** — `BotEvent` 按类别分组暴露 message/messageSent/request/notice 事件
|
|
44
|
+
- **定时任务** — `BotScheduler` 支持 cron 表达式、固定间隔、指定时间
|
|
45
|
+
- **插件系统** — 继承 `PluginBase` 即可开发插件,支持热重载、目录监听自动加载,`scan` + `watch` 零配置接入
|
|
46
|
+
|
|
47
|
+
## 文档
|
|
48
|
+
|
|
49
|
+
完整文档 → [框架开发文档](https://hotcat-bot-qq.docs.chcat1320.top)
|
|
50
|
+
|
|
51
|
+
交流群638144340
|
|
52
|
+
## 协议
|
|
53
|
+
|
|
54
|
+
MIT © CHCAT1320
|
package/dist/botApi.js
CHANGED
package/dist/botClient.d.ts
CHANGED
package/dist/botClient.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { BotApi } from './botApi';
|
|
2
|
-
import { BotConsole } from './botConsole';
|
|
3
|
-
import { BotEvent } from './botEvent';
|
|
4
|
-
import { BotScheduler } from './botScheduler';
|
|
5
|
-
import { existsSync, mkdirSync, cpSync } from 'fs';
|
|
6
|
-
import { join, dirname } from 'path';
|
|
1
|
+
import { BotApi } from './botApi.js';
|
|
2
|
+
import { BotConsole } from './botConsole.js';
|
|
3
|
+
import { BotEvent } from './botEvent.js';
|
|
4
|
+
import { BotScheduler } from './botScheduler.js';
|
|
5
|
+
import { existsSync, mkdirSync, cpSync, readdirSync, readFileSync, statSync, lstatSync } from 'fs';
|
|
6
|
+
import { join, dirname, relative } from 'path';
|
|
7
7
|
import { fileURLToPath } from 'url';
|
|
8
8
|
/**
|
|
9
9
|
* Bot 客户端,封装连接、启动流程及 bot 自身信息。
|
|
@@ -65,7 +65,7 @@ export class BotClient {
|
|
|
65
65
|
*/
|
|
66
66
|
async start() {
|
|
67
67
|
await this.api.connect();
|
|
68
|
-
const { BotPluginSystem } = await import('./botPlugin');
|
|
68
|
+
const { BotPluginSystem } = await import('./botPlugin.js');
|
|
69
69
|
this.plugin = new BotPluginSystem(this.api, this);
|
|
70
70
|
this.api.napcat.on('meta_event.lifecycle.connect', () => {
|
|
71
71
|
new BotConsole('system', 'napcat服务器连接成功').log();
|
|
@@ -84,15 +84,60 @@ export class BotClient {
|
|
|
84
84
|
this.plugin.watch('./plugins');
|
|
85
85
|
}
|
|
86
86
|
seedDefaultPlugin() {
|
|
87
|
-
const dest = join(process.cwd(), 'plugins', 'hotCatPlugin');
|
|
88
|
-
if (existsSync(dest))
|
|
89
|
-
return;
|
|
90
87
|
const selfDir = dirname(fileURLToPath(import.meta.url));
|
|
91
88
|
const src = join(selfDir, '..', 'plugins', 'hotCatPlugin');
|
|
92
89
|
if (!existsSync(src))
|
|
93
90
|
return;
|
|
91
|
+
const dest = join(process.cwd(), 'plugins', 'hotCatPlugin');
|
|
94
92
|
mkdirSync(join(process.cwd(), 'plugins'), { recursive: true });
|
|
95
|
-
|
|
96
|
-
|
|
93
|
+
if (!existsSync(dest)) {
|
|
94
|
+
cpSync(src, dest, { recursive: true });
|
|
95
|
+
new BotConsole('system', '默认插件 hotCatPlugin 已创建').log();
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const updated = this.syncPluginFiles(src, dest);
|
|
99
|
+
if (updated.length > 0) {
|
|
100
|
+
new BotConsole('system', `默认插件 hotCatPlugin 已更新: ${updated.join(', ')}`).log();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
syncPluginFiles(src, dest) {
|
|
104
|
+
const updated = [];
|
|
105
|
+
const walkDir = (dir) => {
|
|
106
|
+
const entries = readdirSync(dir);
|
|
107
|
+
const files = [];
|
|
108
|
+
for (const entry of entries) {
|
|
109
|
+
const full = join(dir, entry);
|
|
110
|
+
if (lstatSync(full).isDirectory()) {
|
|
111
|
+
files.push(...walkDir(full));
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
files.push(full);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return files;
|
|
118
|
+
};
|
|
119
|
+
const srcFiles = walkDir(src);
|
|
120
|
+
for (const file of srcFiles) {
|
|
121
|
+
const rel = relative(src, file);
|
|
122
|
+
const target = join(dest, rel);
|
|
123
|
+
if (!existsSync(target)) {
|
|
124
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
125
|
+
cpSync(file, target);
|
|
126
|
+
updated.push(rel);
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
if (statSync(file).size !== statSync(target).size) {
|
|
130
|
+
cpSync(file, target);
|
|
131
|
+
updated.push(rel);
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
const srcContent = readFileSync(file);
|
|
135
|
+
const destContent = readFileSync(target);
|
|
136
|
+
if (!srcContent.equals(destContent)) {
|
|
137
|
+
cpSync(file, target);
|
|
138
|
+
updated.push(rel);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return updated;
|
|
97
142
|
}
|
|
98
143
|
}
|
package/dist/botEvent.js
CHANGED
package/dist/botPlugin.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { BotConsole } from './botConsole';
|
|
1
|
+
import { BotConsole } from './botConsole.js';
|
|
2
2
|
import * as fs from 'fs';
|
|
3
3
|
import * as path from 'path';
|
|
4
|
+
import { pathToFileURL } from 'url';
|
|
4
5
|
/**
|
|
5
6
|
* 插件管理器,通过 `bot.plugin.xxx()` 访问。
|
|
6
7
|
*
|
|
@@ -150,7 +151,9 @@ export class BotPluginSystem {
|
|
|
150
151
|
if (!indexPath)
|
|
151
152
|
continue;
|
|
152
153
|
try {
|
|
153
|
-
|
|
154
|
+
// Node 的 ESM 加载器不接受裸 Windows 绝对路径(ERR_UNSUPPORTED_ESM_URL_SCHEME),
|
|
155
|
+
// 必须转成 file:// URL;Bun 两者都接受。
|
|
156
|
+
const mod = await import(pathToFileURL(path.resolve(indexPath)).href);
|
|
154
157
|
const ctor = mod[name.charAt(0).toUpperCase() + name.slice(1) + 'Plugin'] || mod.default || Object.values(mod).find((v) => typeof v === 'function' && v.create);
|
|
155
158
|
if (!ctor || typeof ctor.create !== 'function') {
|
|
156
159
|
new BotConsole('error', `插件目录 "${name}" 未导出符合规范的插件类`).log();
|
|
@@ -236,7 +239,7 @@ export class BotPluginSystem {
|
|
|
236
239
|
if (!indexPath)
|
|
237
240
|
return;
|
|
238
241
|
try {
|
|
239
|
-
const mod = await import(indexPath);
|
|
242
|
+
const mod = await import(pathToFileURL(path.resolve(indexPath)).href);
|
|
240
243
|
const ctor = mod[name.charAt(0).toUpperCase() + name.slice(1) + 'Plugin'] || mod.default || Object.values(mod).find((v) => typeof v === 'function' && v.create);
|
|
241
244
|
if (!ctor || typeof ctor.create !== 'function')
|
|
242
245
|
return;
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export { BotClient } from './botClient';
|
|
2
|
-
export { BotApi } from './botApi';
|
|
3
|
-
export { BotEvent, MessageEvent, MessageSent, RequestEvent, NoticeEvent } from './botEvent';
|
|
4
|
-
export { BotScheduler } from './botScheduler';
|
|
5
|
-
export { BotPluginSystem } from './botPlugin';
|
|
6
|
-
export { BotConsole, colors, parseCQ, formatMessage } from './botConsole';
|
|
7
|
-
export { Message } from './message';
|
|
8
|
-
export { PluginBase } from './plugin';
|
|
1
|
+
export { BotClient } from './botClient.js';
|
|
2
|
+
export { BotApi } from './botApi.js';
|
|
3
|
+
export { BotEvent, MessageEvent, MessageSent, RequestEvent, NoticeEvent } from './botEvent.js';
|
|
4
|
+
export { BotScheduler } from './botScheduler.js';
|
|
5
|
+
export { BotPluginSystem } from './botPlugin.js';
|
|
6
|
+
export { BotConsole, colors, parseCQ, formatMessage } from './botConsole.js';
|
|
7
|
+
export { Message } from './message.js';
|
|
8
|
+
export { PluginBase } from './plugin.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hotcat-bot-qq",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
4
4
|
"description": "基于 node-napcat-ts 的 TypeScript QQ 机器人框架",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"logo.png"
|
|
52
52
|
],
|
|
53
53
|
"scripts": {
|
|
54
|
-
"build": "tsc -p tsconfig.build.json",
|
|
54
|
+
"build": "tsc -p tsconfig.build.json && node scripts/fix-dist-extensions.mjs",
|
|
55
55
|
"build:plugin": "tsc --outDir plugins/hotCatPlugin --rootDir plugins/hotCatPlugin --module ESNext --target ES2020 --moduleResolution bundler --declaration --skipLibCheck plugins/hotCatPlugin/index.ts",
|
|
56
56
|
"prepublishOnly": "bun run build && bun run build:plugin",
|
|
57
57
|
"docs:dev": "vitepress dev docs",
|
|
@@ -14,7 +14,12 @@ export class HotCatPlugin extends PluginBase {
|
|
|
14
14
|
await this.api.sendGroupMessage(event.group_id, Message.reply(event.message_id), Message.text(`HotCat 信息\n` +
|
|
15
15
|
`版本:${this.meta.version}\n` +
|
|
16
16
|
`平台:${platform} ${arch}\n` +
|
|
17
|
-
`运行时间:${uptime}`
|
|
17
|
+
`运行时间:${uptime}\n` +
|
|
18
|
+
`Github: https://github.com/CHCAT1320/hotCat-bot-qq\n` +
|
|
19
|
+
`开发文档: https://hotcat-bot-qq.docs.chcat1320.top\n` +
|
|
20
|
+
`交流群: 638144340\n` +
|
|
21
|
+
`管理员QQ: 1095216448\n` +
|
|
22
|
+
`基于 MIT 许可发布 版权所有 © 2026 CHCAT1320`));
|
|
18
23
|
}
|
|
19
24
|
};
|
|
20
25
|
}
|
|
@@ -45,7 +50,7 @@ export class HotCatPlugin extends PluginBase {
|
|
|
45
50
|
}
|
|
46
51
|
HotCatPlugin.meta = {
|
|
47
52
|
name: 'hotCatPlugin',
|
|
48
|
-
version: '0.1.
|
|
53
|
+
version: '0.1.10',
|
|
49
54
|
description: 'HotCat 默认插件(#hotCat 指令查询 bot 状态)',
|
|
50
55
|
author: 'CHCAT1320',
|
|
51
56
|
};
|
|
@@ -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.
|
|
10
|
+
version: '0.1.10',
|
|
11
11
|
description: 'HotCat 默认插件(#hotCat 指令查询 bot 状态)',
|
|
12
12
|
author: 'CHCAT1320',
|
|
13
13
|
}
|
|
@@ -41,7 +41,12 @@ export class HotCatPlugin extends PluginBase {
|
|
|
41
41
|
`HotCat 信息\n` +
|
|
42
42
|
`版本:${this.meta.version}\n` +
|
|
43
43
|
`平台:${platform} ${arch}\n` +
|
|
44
|
-
`运行时间:${uptime}`
|
|
44
|
+
`运行时间:${uptime}\n` +
|
|
45
|
+
`Github: https://github.com/CHCAT1320/hotCat-bot-qq\n` +
|
|
46
|
+
`开发文档: https://hotcat-bot-qq.docs.chcat1320.top\n` +
|
|
47
|
+
`交流群: 638144340\n` +
|
|
48
|
+
`管理员QQ: 1095216448\n` +
|
|
49
|
+
`基于 MIT 许可发布 版权所有 © 2026 CHCAT1320`
|
|
45
50
|
)
|
|
46
51
|
)
|
|
47
52
|
}
|