koishi-plugin-forward-hime 1.3.0 → 1.3.2
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 +30 -26
- package/lib/decorator.d.ts +1 -0
- package/lib/index.js +110 -7
- package/lib/message.d.ts +1 -0
- package/package.json +72 -72
package/README.md
CHANGED
|
@@ -1,26 +1,30 @@
|
|
|
1
|
-
<div align="center">
|
|
2
|
-
<img src="https://socialify.git.ci/Nigh/forward-hime/image?description=1&logo=https%3A%2F%2Fraw.githubusercontent.com%2FNigh%2Fforward-hime%2Fmain%2Fassets%2Flogo.png&name=1&pattern=Plus&theme=Auto" alt="forward-hime" width="640" height="320" />
|
|
3
|
-
|
|
4
|
-
# [Koishi](https://koishi.chat) 多群组消息互通插件
|
|
5
|
-
|
|
6
|
-
[](https://www.npmjs.com/package/koishi-plugin-forward-hime)
|
|
7
|
-
|
|
8
|
-
</div>
|
|
9
|
-
|
|
10
|
-
##
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
##
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
##
|
|
25
|
-
|
|
26
|
-
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img src="https://socialify.git.ci/Nigh/forward-hime/image?description=1&logo=https%3A%2F%2Fraw.githubusercontent.com%2FNigh%2Fforward-hime%2Fmain%2Fassets%2Flogo.png&name=1&pattern=Plus&theme=Auto" alt="forward-hime" width="640" height="320" />
|
|
3
|
+
|
|
4
|
+
# [Koishi](https://koishi.chat) 多群组消息互通插件
|
|
5
|
+
|
|
6
|
+
[](https://www.npmjs.com/package/koishi-plugin-forward-hime)
|
|
7
|
+
|
|
8
|
+
</div>
|
|
9
|
+
|
|
10
|
+
## Screenshot
|
|
11
|
+
|
|
12
|
+

|
|
13
|
+
|
|
14
|
+
## 安装
|
|
15
|
+
|
|
16
|
+
在 Koishi WebUI 或 Koishi 桌面应用中,打开插件市场,搜索 `forward-hime`,找到本插件后,点击 `添加` 按钮后点击 `安装` 即可。
|
|
17
|
+
|
|
18
|
+
## 配置
|
|
19
|
+
|
|
20
|
+
在插件配置页面中,可以添加 `互通转发组`。然后需要为 `互通转发组` 配置转发节点。每个转发节点对应某个平台的一个频道或群组。
|
|
21
|
+
|
|
22
|
+
可以配置多个 `互通转发组`,每个 `互通转发组` 之间相互独立。
|
|
23
|
+
|
|
24
|
+
## 使用
|
|
25
|
+
|
|
26
|
+
启用插件后,当一个 `互通转发组` 中的任意节点收到消息时,插件会自动将消息转发给**这个**`互通转发组`中的其他节点。
|
|
27
|
+
|
|
28
|
+
## 贡献者
|
|
29
|
+
|
|
30
|
+
[](https://github.com/Nigh/forward-hime/graphs/contributors)
|
package/lib/decorator.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Session, Element } from "koishi";
|
|
2
2
|
import { ForwardNode } from "./config";
|
|
3
|
+
export declare function MsgMiddlewareCache(session: Session): Promise<void>;
|
|
3
4
|
export declare function MsgDecorator(session: Session, node: ForwardNode): Promise<any>;
|
|
4
5
|
export declare function MsgDecoratorFallback(session: Session, node: ForwardNode): Promise<Element[]>;
|
package/lib/index.js
CHANGED
|
@@ -79,7 +79,16 @@ var transparentPixel = import_buffer.Buffer.from(
|
|
|
79
79
|
);
|
|
80
80
|
function Decorator({ head, content }) {
|
|
81
81
|
let msg = [];
|
|
82
|
-
|
|
82
|
+
let hasImage = false;
|
|
83
|
+
for (const key in content) {
|
|
84
|
+
if (content[key].type === "image") {
|
|
85
|
+
hasImage = true;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
msg = msg.concat(head, (0, import_koishi3.h)("br"), content);
|
|
89
|
+
if (!hasImage) {
|
|
90
|
+
msg = msg.concat(import_koishi3.h.image(transparentPixel, "image/gif"));
|
|
91
|
+
}
|
|
83
92
|
return msg;
|
|
84
93
|
}
|
|
85
94
|
__name(Decorator, "Decorator");
|
|
@@ -89,14 +98,58 @@ var kook_default = {
|
|
|
89
98
|
|
|
90
99
|
// src/decorators/onebot.ts
|
|
91
100
|
var import_koishi4 = require("koishi");
|
|
101
|
+
function cqJsonTranslator(content, elem) {
|
|
102
|
+
let json = JSON.parse(elem.attrs.data);
|
|
103
|
+
let hit = 0;
|
|
104
|
+
if (json) {
|
|
105
|
+
if (json.prompt) {
|
|
106
|
+
hit += 1;
|
|
107
|
+
content.push((0, import_koishi4.h)("p", `${json.prompt}`));
|
|
108
|
+
}
|
|
109
|
+
if (json.meta && json.meta.detail_1) {
|
|
110
|
+
if (json.meta.detail_1.preview) {
|
|
111
|
+
hit += 1;
|
|
112
|
+
content.push(import_koishi4.h.image(json.meta.detail_1.preview, "image/jpeg"));
|
|
113
|
+
}
|
|
114
|
+
if (json.meta.detail_1.qqdocurl) {
|
|
115
|
+
hit += 1;
|
|
116
|
+
content.push((0, import_koishi4.h)("span", `${json.meta.detail_1.qqdocurl}`));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (hit === 0) {
|
|
121
|
+
content.push((0, import_koishi4.h)("span", `[CQ:JSON消息]`));
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
__name(cqJsonTranslator, "cqJsonTranslator");
|
|
92
125
|
function Middleware(session) {
|
|
93
126
|
const platform = guessPlatform(session);
|
|
127
|
+
let newContent = [];
|
|
94
128
|
let head = [
|
|
95
129
|
(0, import_koishi4.h)("b", `${session.username}`),
|
|
96
130
|
(0, import_koishi4.h)("span", " 转发自 "),
|
|
97
131
|
(0, import_koishi4.h)("i", `${platform}`),
|
|
98
132
|
(0, import_koishi4.h)("span", `:`)
|
|
99
133
|
];
|
|
134
|
+
if (platform === "QQ") {
|
|
135
|
+
for (const key in session.elements) {
|
|
136
|
+
switch (session.elements[key].type) {
|
|
137
|
+
case "forward":
|
|
138
|
+
newContent.push((0, import_koishi4.h)("span", `[CQ:转发消息]`));
|
|
139
|
+
break;
|
|
140
|
+
case "json":
|
|
141
|
+
cqJsonTranslator(newContent, session.elements[key]);
|
|
142
|
+
break;
|
|
143
|
+
case "mface":
|
|
144
|
+
newContent.push(import_koishi4.h.image(session.elements[key].attrs.url));
|
|
145
|
+
break;
|
|
146
|
+
default:
|
|
147
|
+
newContent.push(session.elements[key]);
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return { head, content: newContent };
|
|
152
|
+
}
|
|
100
153
|
return { head, content: session.elements };
|
|
101
154
|
}
|
|
102
155
|
__name(Middleware, "Middleware");
|
|
@@ -196,15 +249,52 @@ function defaultMiddleware(session) {
|
|
|
196
249
|
}
|
|
197
250
|
__name(defaultMiddleware, "defaultMiddleware");
|
|
198
251
|
var localDecorators = [atTranslator, quoteTranslator];
|
|
199
|
-
|
|
252
|
+
var msgMiddleCache = [];
|
|
253
|
+
function msgMiddleCacheAppend(msg) {
|
|
254
|
+
msgMiddleCache.push(msg);
|
|
255
|
+
if (msgMiddleCache.length > 16) {
|
|
256
|
+
msgMiddleCache.shift();
|
|
257
|
+
}
|
|
258
|
+
logger.debug(`[msgMiddleCache]`, msgMiddleCache.length);
|
|
259
|
+
}
|
|
260
|
+
__name(msgMiddleCacheAppend, "msgMiddleCacheAppend");
|
|
261
|
+
function msgMiddleCacheFind(uuid) {
|
|
262
|
+
for (const item of msgMiddleCache) {
|
|
263
|
+
if (item.UUID === uuid) {
|
|
264
|
+
return item.msg;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
return null;
|
|
268
|
+
}
|
|
269
|
+
__name(msgMiddleCacheFind, "msgMiddleCacheFind");
|
|
270
|
+
function MsgToMiddleware(session) {
|
|
200
271
|
let elems = { head: [], content: [] };
|
|
201
272
|
let _platform_in = decorators_exports[session.platform];
|
|
202
|
-
let _platform_out = decorators_exports[node.Platform];
|
|
203
273
|
if (_platform_in && typeof _platform_in.Middleware === "function") {
|
|
204
274
|
elems = _platform_in.Middleware(session);
|
|
205
275
|
} else {
|
|
206
276
|
elems = defaultMiddleware(session);
|
|
207
277
|
}
|
|
278
|
+
return elems;
|
|
279
|
+
}
|
|
280
|
+
__name(MsgToMiddleware, "MsgToMiddleware");
|
|
281
|
+
async function MsgMiddlewareCache(session) {
|
|
282
|
+
let elems = MsgToMiddleware(session);
|
|
283
|
+
msgMiddleCacheAppend({ UUID: MsgUUIDFromSession(session), msg: elems });
|
|
284
|
+
logger.debug(`[msgMiddleCache] CACHED`);
|
|
285
|
+
}
|
|
286
|
+
__name(MsgMiddlewareCache, "MsgMiddlewareCache");
|
|
287
|
+
async function MsgDecorator(session, node) {
|
|
288
|
+
let elems;
|
|
289
|
+
let _platform_out = decorators_exports[node.Platform];
|
|
290
|
+
let elemCache = msgMiddleCacheFind(MsgUUIDFromSession(session));
|
|
291
|
+
if (elemCache) {
|
|
292
|
+
logger.debug(`[msgMiddleCache] HIT`);
|
|
293
|
+
elems = elemCache;
|
|
294
|
+
} else {
|
|
295
|
+
logger.debug(`[msgMiddleCache] MISSED`);
|
|
296
|
+
elems = MsgToMiddleware(session);
|
|
297
|
+
}
|
|
208
298
|
for (const fn of localDecorators) {
|
|
209
299
|
elems = await fn(session, node, elems);
|
|
210
300
|
}
|
|
@@ -268,7 +358,8 @@ async function quoteTranslator(session, node, { head, content }) {
|
|
|
268
358
|
if (cache) {
|
|
269
359
|
let msgid = await msgCacheGetLocalIDByUUID(node, cache.uuid);
|
|
270
360
|
if (msgid) {
|
|
271
|
-
|
|
361
|
+
let newHead = [(0, import_koishi5.h)("quote", { id: msgid })].concat(head);
|
|
362
|
+
return { head: newHead, content };
|
|
272
363
|
} else {
|
|
273
364
|
logger.error(`[msgCacheGetLocalIDByUUID] ${cache.uuid} not found`);
|
|
274
365
|
}
|
|
@@ -289,9 +380,14 @@ async function MessageSendWithDecorator(ctx2, node, session, Deco) {
|
|
|
289
380
|
msgid: res[0],
|
|
290
381
|
uuid
|
|
291
382
|
};
|
|
292
|
-
|
|
293
|
-
|
|
383
|
+
if (!mc.msgid) {
|
|
384
|
+
throw new Error(`Empty Message ID`);
|
|
385
|
+
} else {
|
|
386
|
+
msgCache(mc);
|
|
387
|
+
logger.debug(`[MessageForward] to ${mc.platform} ${mc.uuid}`);
|
|
388
|
+
}
|
|
294
389
|
}).catch((error) => {
|
|
390
|
+
logger.error(`content: ${content}`);
|
|
295
391
|
throw error;
|
|
296
392
|
});
|
|
297
393
|
}
|
|
@@ -327,6 +423,10 @@ function botExistsCheck(ctx2, node) {
|
|
|
327
423
|
return true;
|
|
328
424
|
}
|
|
329
425
|
__name(botExistsCheck, "botExistsCheck");
|
|
426
|
+
function MsgUUIDFromSession(session) {
|
|
427
|
+
return session.channelId + ":" + session.messageId;
|
|
428
|
+
}
|
|
429
|
+
__name(MsgUUIDFromSession, "MsgUUIDFromSession");
|
|
330
430
|
|
|
331
431
|
// src/index.ts
|
|
332
432
|
var name = `forward hime - 转发姬`;
|
|
@@ -362,7 +462,7 @@ function apply(ctx2, cfg) {
|
|
|
362
462
|
session.platform,
|
|
363
463
|
session.channelId + ":" + session.messageId
|
|
364
464
|
);
|
|
365
|
-
let uuid = session
|
|
465
|
+
let uuid = MsgUUIDFromSession(session);
|
|
366
466
|
msgCache({
|
|
367
467
|
platform: session.platform,
|
|
368
468
|
bot: group.Nodes[k].BotID,
|
|
@@ -375,6 +475,9 @@ function apply(ctx2, cfg) {
|
|
|
375
475
|
}
|
|
376
476
|
}
|
|
377
477
|
}
|
|
478
|
+
if (hitGroup.length > 0) {
|
|
479
|
+
await MsgMiddlewareCache(session);
|
|
480
|
+
}
|
|
378
481
|
for (const g in hitGroup) {
|
|
379
482
|
const group = cfg.ForwardGroups[hitGroup[g]];
|
|
380
483
|
for (const k in group.Nodes) {
|
package/lib/message.d.ts
CHANGED
|
@@ -4,3 +4,4 @@ import { MsgCache } from "./cache";
|
|
|
4
4
|
export declare function MessageForward(ctx: Context, node: ForwardNode, session: Session): Promise<void>;
|
|
5
5
|
export declare function MessageDelete(ctx: Context, msg: MsgCache): Promise<void>;
|
|
6
6
|
export declare function MessageEdit(ctx: Context, node: ForwardNode, session: Session): Promise<void>;
|
|
7
|
+
export declare function MsgUUIDFromSession(session: Session): string;
|
package/package.json
CHANGED
|
@@ -1,72 +1,72 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "koishi-plugin-forward-hime",
|
|
3
|
-
"description": "多群组消息互通",
|
|
4
|
-
"version": "1.3.
|
|
5
|
-
"author": {
|
|
6
|
-
"name": "xianii",
|
|
7
|
-
"email": "jiyucheng007@gmail.com"
|
|
8
|
-
},
|
|
9
|
-
"main": "lib/index.js",
|
|
10
|
-
"typings": "lib/index.d.ts",
|
|
11
|
-
"files": [
|
|
12
|
-
"lib"
|
|
13
|
-
],
|
|
14
|
-
"koishi": {
|
|
15
|
-
"browser": true
|
|
16
|
-
},
|
|
17
|
-
"license": "MIT",
|
|
18
|
-
"homepage": "https://github.
|
|
19
|
-
"repository": {
|
|
20
|
-
"type": "git",
|
|
21
|
-
"url": "git+https://github.com/Nigh/forward-hime.git"
|
|
22
|
-
},
|
|
23
|
-
"bugs": {
|
|
24
|
-
"url": "https://github.com/Nigh/forward-hime/issues"
|
|
25
|
-
},
|
|
26
|
-
"keywords": [
|
|
27
|
-
"chatbot",
|
|
28
|
-
"koishi",
|
|
29
|
-
"plugin",
|
|
30
|
-
"koishi-plugin",
|
|
31
|
-
"forward",
|
|
32
|
-
"message-forwarding"
|
|
33
|
-
],
|
|
34
|
-
"peerDependencies": {
|
|
35
|
-
"koishi": "^4.17.8"
|
|
36
|
-
},
|
|
37
|
-
"devDependencies": {
|
|
38
|
-
"@typescript-eslint/eslint-plugin": "^7.13.0",
|
|
39
|
-
"@typescript-eslint/parser": "^7.13.0",
|
|
40
|
-
"atsc": "^2.1.0",
|
|
41
|
-
"eslint": "^9.4.0",
|
|
42
|
-
"eslint-config-prettier": "^9.1.0",
|
|
43
|
-
"eslint-plugin-prettier": "^5.1.3",
|
|
44
|
-
"eslint-plugin-unused-imports": "^4.0.0",
|
|
45
|
-
"husky": "^9.0.11",
|
|
46
|
-
"lint-staged": "^15.2.7",
|
|
47
|
-
"prettier": "^3.3.2",
|
|
48
|
-
"typescript": "^5.4.5"
|
|
49
|
-
},
|
|
50
|
-
"scripts": {
|
|
51
|
-
"prepare": "husky",
|
|
52
|
-
"build": "atsc -b",
|
|
53
|
-
"eslint": "eslint . --ext .js,.jsx,.ts,.tsx",
|
|
54
|
-
"format": "prettier --write .",
|
|
55
|
-
"pub": "npm publish --access public"
|
|
56
|
-
},
|
|
57
|
-
"husky": {
|
|
58
|
-
"hooks": {
|
|
59
|
-
"pre-commit": "lint-staged"
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
"lint-staged": {
|
|
63
|
-
"*.{js,jsx,ts,tsx,json,css,scss,md}": [
|
|
64
|
-
"eslint --fix",
|
|
65
|
-
"prettier --write"
|
|
66
|
-
]
|
|
67
|
-
},
|
|
68
|
-
"publishConfig": {
|
|
69
|
-
"registry": "https://registry.npmjs.org/",
|
|
70
|
-
"access": "public"
|
|
71
|
-
}
|
|
72
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "koishi-plugin-forward-hime",
|
|
3
|
+
"description": "多群组消息互通",
|
|
4
|
+
"version": "1.3.2",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "xianii",
|
|
7
|
+
"email": "jiyucheng007@gmail.com"
|
|
8
|
+
},
|
|
9
|
+
"main": "lib/index.js",
|
|
10
|
+
"typings": "lib/index.d.ts",
|
|
11
|
+
"files": [
|
|
12
|
+
"lib"
|
|
13
|
+
],
|
|
14
|
+
"koishi": {
|
|
15
|
+
"browser": true
|
|
16
|
+
},
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"homepage": "https://nigh.github.io/forward-hime/",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/Nigh/forward-hime.git"
|
|
22
|
+
},
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/Nigh/forward-hime/issues"
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"chatbot",
|
|
28
|
+
"koishi",
|
|
29
|
+
"plugin",
|
|
30
|
+
"koishi-plugin",
|
|
31
|
+
"forward",
|
|
32
|
+
"message-forwarding"
|
|
33
|
+
],
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"koishi": "^4.17.8"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@typescript-eslint/eslint-plugin": "^7.13.0",
|
|
39
|
+
"@typescript-eslint/parser": "^7.13.0",
|
|
40
|
+
"atsc": "^2.1.0",
|
|
41
|
+
"eslint": "^9.4.0",
|
|
42
|
+
"eslint-config-prettier": "^9.1.0",
|
|
43
|
+
"eslint-plugin-prettier": "^5.1.3",
|
|
44
|
+
"eslint-plugin-unused-imports": "^4.0.0",
|
|
45
|
+
"husky": "^9.0.11",
|
|
46
|
+
"lint-staged": "^15.2.7",
|
|
47
|
+
"prettier": "^3.3.2",
|
|
48
|
+
"typescript": "^5.4.5"
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"prepare": "husky",
|
|
52
|
+
"build": "atsc -b",
|
|
53
|
+
"eslint": "eslint . --ext .js,.jsx,.ts,.tsx",
|
|
54
|
+
"format": "prettier --write .",
|
|
55
|
+
"pub": "npm publish --access public"
|
|
56
|
+
},
|
|
57
|
+
"husky": {
|
|
58
|
+
"hooks": {
|
|
59
|
+
"pre-commit": "lint-staged"
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
"lint-staged": {
|
|
63
|
+
"*.{js,jsx,ts,tsx,json,css,scss,md}": [
|
|
64
|
+
"eslint --fix",
|
|
65
|
+
"prettier --write"
|
|
66
|
+
]
|
|
67
|
+
},
|
|
68
|
+
"publishConfig": {
|
|
69
|
+
"registry": "https://registry.npmjs.org/",
|
|
70
|
+
"access": "public"
|
|
71
|
+
}
|
|
72
|
+
}
|