hotcat-bot-qq 0.1.9 → 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.js +5 -5
- 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 +1 -1
- package/plugins/hotCatPlugin/index.ts +1 -1
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.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { BotApi } from './botApi';
|
|
2
|
-
import { BotConsole } from './botConsole';
|
|
3
|
-
import { BotEvent } from './botEvent';
|
|
4
|
-
import { BotScheduler } from './botScheduler';
|
|
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
5
|
import { existsSync, mkdirSync, cpSync, readdirSync, readFileSync, statSync, lstatSync } from 'fs';
|
|
6
6
|
import { join, dirname, relative } from 'path';
|
|
7
7
|
import { fileURLToPath } from 'url';
|
|
@@ -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();
|
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",
|