karin-plugin-adapter-all 0.0.0-stage → 1.2.0

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.
Files changed (34) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +106 -2
  3. package/dist/config-DKcb6lmw.js +54 -0
  4. package/dist/dir.js +49 -0
  5. package/dist/icqq-BR8miqDV.js +1771 -0
  6. package/dist/index.js +10 -0
  7. package/dist/server.js +13577 -0
  8. package/dist/web.config.js +36 -0
  9. package/package.json +69 -4
  10. package/resources/image//345/220/257/347/250/213/345/256/243/345/217/221.png +0 -0
  11. package/resources/reactions.json +50 -0
  12. package/resources/template/test.html +21 -0
  13. package/resources/web/404/index.html +1 -0
  14. package/resources/web/404.html +1 -0
  15. package/resources/web/_next/static/SIPU0JhZAVD0DvlvpoXqx/_buildManifest.js +1 -0
  16. package/resources/web/_next/static/SIPU0JhZAVD0DvlvpoXqx/_ssgManifest.js +1 -0
  17. package/resources/web/_next/static/chunks/2592325e-57fbed9f64536727.js +1 -0
  18. package/resources/web/_next/static/chunks/634-7552fa79f7816d81.js +1 -0
  19. package/resources/web/_next/static/chunks/778-0a7f658317254539.js +1 -0
  20. package/resources/web/_next/static/chunks/78-98f9c6d536c55c8d.js +1 -0
  21. package/resources/web/_next/static/chunks/app/_not-found/page-479700a6cdca1b89.js +1 -0
  22. package/resources/web/_next/static/chunks/app/layout-2fcd97f6eeeb705f.js +1 -0
  23. package/resources/web/_next/static/chunks/app/not-found-479700a6cdca1b89.js +1 -0
  24. package/resources/web/_next/static/chunks/app/page-32d138e107d21bbf.js +1 -0
  25. package/resources/web/_next/static/chunks/framework-939e80bc3ec79f24.js +1 -0
  26. package/resources/web/_next/static/chunks/main-app-9148086af618c8de.js +1 -0
  27. package/resources/web/_next/static/chunks/main-bff001951bd96286.js +1 -0
  28. package/resources/web/_next/static/chunks/pages/_app-04ed26170c78d2cb.js +1 -0
  29. package/resources/web/_next/static/chunks/pages/_error-2a3f5266a349ca5b.js +1 -0
  30. package/resources/web/_next/static/chunks/polyfills-42372ed130431b0a.js +1 -0
  31. package/resources/web/_next/static/chunks/webpack-eb9f7b784f442cad.js +1 -0
  32. package/resources/web/_next/static/css/5ca80a6ff000abd3.css +1 -0
  33. package/resources/web/index.html +1 -0
  34. package/resources/web/index.txt +21 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 karinjs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,107 @@
1
- # Temporary Holding Version
1
+ # karin-plugin-adapter-SnowLuma
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ 基于 [node-karin](https://www.npmjs.com/package/node-karin) 的多协议统一适配器插件,一套配置同时接入多种机器人协议,统一转换为 Karin 的消息与事件结构。
4
+
5
+ ## 支持的协议
6
+
7
+ | 协议 | 说明 |
8
+ | --- | --- |
9
+ | OneBot 11 | 支持 SnowLuma / NapCat / Lagrange / 标准实现,通信方式支持 HTTP、正向 WebSocket、反向 WebSocket、SSE |
10
+ | OneBot 12 | 标准 OneBot 12 实现 |
11
+ | ICQQ | QQ 协议直连(快速登录 / 密码 / 扫码),支持滑动验证码多通道处理 |
12
+ | Milky | WebSocket / SSE / WebHook 三种事件接收方式 |
13
+ | Kook | 官方 API 直连,支持官方 Gateway(WS)与 WebHook 两种事件接收方式 |
14
+ | QQBot | 官方开放平台 API 直连(api-v2 鉴权),支持官方 WebSocket Gateway 与 WebHook,支持扫码绑定 AppID/AppSecret |
15
+
16
+ ## 功能特性
17
+
18
+ - **可视化配置面板**:插件自带的 Web 界面支持添加 / 编辑 / 删除机器人,实时保存热更新,无需重启 Karin
19
+ - **QQBot 扫码绑定**:在配置面板扫码快速获取 AppID / AppSecret,绑定成功后自动保存配置并开始连接机器人
20
+ - **富媒体消息**:图片、语音、视频、文件消息完整支持(QQBot 走官方富媒体上传通道)
21
+ - **断线重连**:所有网络型连接均内置自动重连与心跳
22
+ - **icqq 滑动验证**:GT 网页验证、txhelper、手动 ticket、自建 Cloudflare Pages 多通道并行处理
23
+
24
+ ## 安装
25
+
26
+ ```bash
27
+ pnpm add karin-plugin-adapter-all -w
28
+ ```
29
+
30
+ 然后在 Karin 根目录启动,插件会自动注册。
31
+
32
+ ### ICQQ 协议
33
+
34
+ icqq 依赖包名 `icqq`(npm 别名指向 `@icqqjs/icqq`),安装本插件时已自动装好;若被手动移除,一条命令重装:
35
+
36
+ ```bash
37
+ pnpm add icqq@npm:@icqqjs/icqq -w
38
+ ```
39
+
40
+ 装好后无需重启,在配置面板添加 ICQQ 机器人并保存即可热更新生效。
41
+
42
+ ## 配置
43
+
44
+ 访问 Karin 提供的插件 Web 控制台(默认地址与 Karin 主控制台相同),在「适配器」页面添加机器人:
45
+
46
+ 1. 选择协议(OneBot 11 / OneBot 12 / ICQQ / Milky / Kook / QQBot)
47
+ 2. 按需填写连接地址、Token、AppID / AppSecret 等参数
48
+ 3. 保存即热更新生效
49
+
50
+ ### QQBot 扫码绑定
51
+
52
+ QQBot 协议可在配置面板直接扫码:
53
+
54
+ 1. 在 QQBot 配置处点击「扫码绑定」
55
+ 2. 用 QQ 扫描二维码完成授权
56
+ 3. 授权成功后 AppID / AppSecret 自动回填并保存,立即开始连接
57
+
58
+ ### 消息正则替换
59
+
60
+ Kook / QQBot 入站消息默认开启正则替换,可将协议端命令风格转换为 Karin 默认前缀,例如:
61
+
62
+ ```json
63
+ { "match": "^\\s*\\\\/", "to": "#" }
64
+ ```
65
+
66
+ 将 `/命令` 转为 `#命令`。可在配置中通过 `msgReplaceEnable: false` 关闭。
67
+
68
+ ## 开发
69
+
70
+ ```bash
71
+ pnpm install
72
+ pnpm dev # 开发模式(核心 + 构建 Web 面板)
73
+ pnpm build # 编译 TS + 构建 Web 面板资源
74
+ pnpm app # 运行编译产物
75
+ ```
76
+
77
+ 目录结构:
78
+
79
+ ```
80
+ src/
81
+ ├── adapters/ # 各协议实现(onebot11 / onebot12 / icqq / milky / kook / qqbot)
82
+ ├── utils/ # 配置、扫码绑定、事件工具
83
+ ├── server.ts # 控制台服务(配置保存 API、扫码、WebHook 入口)
84
+ └── index.ts # 插件入口
85
+ web/ # 配置面板(Next.js + Tailwind)
86
+ ```
87
+
88
+ ## 自动化发布
89
+
90
+ 推送到 `main` 分支后,GitHub Actions 自动完成:
91
+
92
+ 1. **release-please** 依据 Conventional Commits 自动生成版本号(feat → minor,fix → patch)、打 tag 并创建 GitHub Release
93
+ 2. 自动构建并发布到 npm(需配置 `NPM_TOKEN` secret)
94
+ 3. **sync-build** 构建编译产物并强制同步到 `build` 分支,`build` 分支始终与最新 `main` 保持一致且包含 `dist/` 产物
95
+
96
+ 日常开发流程:
97
+
98
+ ```bash
99
+ git commit -m "feat: 新增 xxx"
100
+ git push
101
+ ```
102
+
103
+ 发布成功后在 [npm](https://www.npmjs.com/) 与 GitHub Releases 页面即可看到新版本。
104
+
105
+ ## License
106
+
107
+ [MIT](./LICENSE)
@@ -0,0 +1,54 @@
1
+ import { dir } from "./dir.js";
2
+ import { copyConfigSync, filesByExt, requireFileSync, watch } from "node-karin";
3
+ import fs from "node:fs";
4
+
5
+ //#region src/utils/config.ts
6
+ /** 网页面板访问前缀 须与 web/next.config.mjs 的 basePath 保持一致 */
7
+ const WEB_PREFIX = "/adapter-all";
8
+ /**
9
+ * @description 初始化配置文件
10
+ */
11
+ copyConfigSync(dir.defConfigDir, dir.ConfigDir, [".json"]);
12
+ /**
13
+ * @description 配置文件
14
+ * force 强制重读: requireFileSync 默认缓存 300 秒且命中会续期,
15
+ * 否则热更新/网页面板保存后读到的仍是旧配置
16
+ */
17
+ const config$1 = () => {
18
+ const cfg = requireFileSync(`${dir.ConfigDir}/config.json`, { force: true });
19
+ const def = requireFileSync(`${dir.defConfigDir}/config.json`);
20
+ return {
21
+ ...def,
22
+ ...cfg
23
+ };
24
+ };
25
+ /**
26
+ * @description 写入配置文件 (网页面板保存用)
27
+ */
28
+ const saveConfig = (data) => {
29
+ fs.writeFileSync(`${dir.ConfigDir}/config.json`, JSON.stringify(data, null, 2));
30
+ };
31
+ const changeListeners = new Set();
32
+ /**
33
+ * @description 订阅配置文件变更 文件被保存/修改后触发 (热更新等场景使用)
34
+ */
35
+ const onConfigChange = (cb) => {
36
+ changeListeners.add(cb);
37
+ return () => changeListeners.delete(cb);
38
+ };
39
+ /**
40
+ * @description 监听配置文件
41
+ */
42
+ setTimeout(() => {
43
+ const list = filesByExt(dir.ConfigDir, ".json", "abs");
44
+ list.forEach((file) => watch(file, () => {
45
+ changeListeners.forEach((cb) => {
46
+ try {
47
+ cb();
48
+ } catch {}
49
+ });
50
+ }));
51
+ }, 2e3);
52
+
53
+ //#endregion
54
+ export { saveConfig as i, config$1 as n, onConfigChange as r, WEB_PREFIX as t };
package/dist/dir.js ADDED
@@ -0,0 +1,49 @@
1
+ import path from "node:path";
2
+ import { URL, fileURLToPath } from "node:url";
3
+ import { karinPathBase, requireFileSync } from "node-karin";
4
+
5
+ //#region src/dir.ts
6
+ /** 插件包绝对路径 */
7
+ const pluginDir = fileURLToPath(new URL("../", import.meta.url));
8
+ /** 插件包目录名称 */
9
+ const pluginName = path.basename(pluginDir);
10
+ /** package.json */
11
+ const pkg = requireFileSync(path.join(pluginDir, "package.json"));
12
+ /**
13
+ * 插件目录信息
14
+ */
15
+ const dir = {
16
+ /** 根目录绝对路径 */
17
+ pluginDir,
18
+ /** 插件目录名称 */
19
+ pluginName,
20
+ /** package.json */
21
+ pkg,
22
+ /** 插件版本 package.json 的 version */
23
+ get version() {
24
+ return pkg.version;
25
+ },
26
+ /** 插件名称 package.json 的 name */
27
+ get name() {
28
+ return pkg.name;
29
+ },
30
+ /** 插件默认配置目录 */
31
+ get defConfigDir() {
32
+ return path.join(pluginDir, "config");
33
+ },
34
+ /** 在`@karinjs`中的绝对路径 */
35
+ get karinPath() {
36
+ return path.join(karinPathBase, pluginName);
37
+ },
38
+ /** 插件配置目录 `@karinjs/karin-plugin-xxx/config` */
39
+ get ConfigDir() {
40
+ return path.join(this.karinPath, "config");
41
+ },
42
+ /** 插件资源目录 `@karinjs/karin-plugin-xxx/resources` */
43
+ get defResourcesDir() {
44
+ return path.join(this.karinPath, "resources");
45
+ }
46
+ };
47
+
48
+ //#endregion
49
+ export { dir };