koishi-plugin-forward-hime 1.3.0 → 1.3.1
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 +4 -0
- package/lib/decorator.d.ts +1 -0
- package/lib/index.js +93 -6
- package/lib/message.d.ts +1 -0
- package/package.json +2 -2
package/README.md
CHANGED
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
|
@@ -89,14 +89,51 @@ var kook_default = {
|
|
|
89
89
|
|
|
90
90
|
// src/decorators/onebot.ts
|
|
91
91
|
var import_koishi4 = require("koishi");
|
|
92
|
+
function cqJsonTranslator(content, elem) {
|
|
93
|
+
let json = JSON.parse(elem.attrs.data);
|
|
94
|
+
let hit = 0;
|
|
95
|
+
if (json) {
|
|
96
|
+
if (json.prompt) {
|
|
97
|
+
hit += 1;
|
|
98
|
+
content.push((0, import_koishi4.h)("p", `${json.prompt}`));
|
|
99
|
+
}
|
|
100
|
+
if (json.meta && json.meta.detail_1) {
|
|
101
|
+
if (json.meta.detail_1.preview) {
|
|
102
|
+
hit += 1;
|
|
103
|
+
content.push(import_koishi4.h.image(json.meta.detail_1.preview));
|
|
104
|
+
}
|
|
105
|
+
if (json.meta.detail_1.qqdocurl) {
|
|
106
|
+
hit += 1;
|
|
107
|
+
content.push((0, import_koishi4.h)("span", `${json.meta.detail_1.qqdocurl}`));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (hit === 0) {
|
|
112
|
+
content.push((0, import_koishi4.h)("span", `[CQ:JSON消息]`));
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
__name(cqJsonTranslator, "cqJsonTranslator");
|
|
92
116
|
function Middleware(session) {
|
|
93
117
|
const platform = guessPlatform(session);
|
|
118
|
+
let newContent = [];
|
|
94
119
|
let head = [
|
|
95
120
|
(0, import_koishi4.h)("b", `${session.username}`),
|
|
96
121
|
(0, import_koishi4.h)("span", " 转发自 "),
|
|
97
122
|
(0, import_koishi4.h)("i", `${platform}`),
|
|
98
123
|
(0, import_koishi4.h)("span", `:`)
|
|
99
124
|
];
|
|
125
|
+
if (platform === "QQ") {
|
|
126
|
+
for (const key in session.elements) {
|
|
127
|
+
if (session.elements[key].type === "forward") {
|
|
128
|
+
newContent.push((0, import_koishi4.h)("span", `[CQ:转发消息]`));
|
|
129
|
+
} else if (session.elements[key].type === "json") {
|
|
130
|
+
cqJsonTranslator(newContent, session.elements[key]);
|
|
131
|
+
} else {
|
|
132
|
+
newContent.push(session.elements[key]);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return { head, content: newContent };
|
|
136
|
+
}
|
|
100
137
|
return { head, content: session.elements };
|
|
101
138
|
}
|
|
102
139
|
__name(Middleware, "Middleware");
|
|
@@ -196,15 +233,52 @@ function defaultMiddleware(session) {
|
|
|
196
233
|
}
|
|
197
234
|
__name(defaultMiddleware, "defaultMiddleware");
|
|
198
235
|
var localDecorators = [atTranslator, quoteTranslator];
|
|
199
|
-
|
|
236
|
+
var msgMiddleCache = [];
|
|
237
|
+
function msgMiddleCacheAppend(msg) {
|
|
238
|
+
msgMiddleCache.push(msg);
|
|
239
|
+
if (msgMiddleCache.length > 16) {
|
|
240
|
+
msgMiddleCache.shift();
|
|
241
|
+
}
|
|
242
|
+
logger.debug(`[msgMiddleCache]`, msgMiddleCache.length);
|
|
243
|
+
}
|
|
244
|
+
__name(msgMiddleCacheAppend, "msgMiddleCacheAppend");
|
|
245
|
+
function msgMiddleCacheFind(uuid) {
|
|
246
|
+
for (const item of msgMiddleCache) {
|
|
247
|
+
if (item.UUID === uuid) {
|
|
248
|
+
return item.msg;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return null;
|
|
252
|
+
}
|
|
253
|
+
__name(msgMiddleCacheFind, "msgMiddleCacheFind");
|
|
254
|
+
function MsgToMiddleware(session) {
|
|
200
255
|
let elems = { head: [], content: [] };
|
|
201
256
|
let _platform_in = decorators_exports[session.platform];
|
|
202
|
-
let _platform_out = decorators_exports[node.Platform];
|
|
203
257
|
if (_platform_in && typeof _platform_in.Middleware === "function") {
|
|
204
258
|
elems = _platform_in.Middleware(session);
|
|
205
259
|
} else {
|
|
206
260
|
elems = defaultMiddleware(session);
|
|
207
261
|
}
|
|
262
|
+
return elems;
|
|
263
|
+
}
|
|
264
|
+
__name(MsgToMiddleware, "MsgToMiddleware");
|
|
265
|
+
async function MsgMiddlewareCache(session) {
|
|
266
|
+
let elems = MsgToMiddleware(session);
|
|
267
|
+
msgMiddleCacheAppend({ UUID: MsgUUIDFromSession(session), msg: elems });
|
|
268
|
+
logger.debug(`[msgMiddleCache] CACHED`);
|
|
269
|
+
}
|
|
270
|
+
__name(MsgMiddlewareCache, "MsgMiddlewareCache");
|
|
271
|
+
async function MsgDecorator(session, node) {
|
|
272
|
+
let elems;
|
|
273
|
+
let _platform_out = decorators_exports[node.Platform];
|
|
274
|
+
let elemCache = msgMiddleCacheFind(MsgUUIDFromSession(session));
|
|
275
|
+
if (elemCache) {
|
|
276
|
+
logger.debug(`[msgMiddleCache] HIT`);
|
|
277
|
+
elems = elemCache;
|
|
278
|
+
} else {
|
|
279
|
+
logger.debug(`[msgMiddleCache] MISSED`);
|
|
280
|
+
elems = MsgToMiddleware(session);
|
|
281
|
+
}
|
|
208
282
|
for (const fn of localDecorators) {
|
|
209
283
|
elems = await fn(session, node, elems);
|
|
210
284
|
}
|
|
@@ -268,7 +342,8 @@ async function quoteTranslator(session, node, { head, content }) {
|
|
|
268
342
|
if (cache) {
|
|
269
343
|
let msgid = await msgCacheGetLocalIDByUUID(node, cache.uuid);
|
|
270
344
|
if (msgid) {
|
|
271
|
-
|
|
345
|
+
let newHead = [(0, import_koishi5.h)("quote", { id: msgid })].concat(head);
|
|
346
|
+
return { head: newHead, content };
|
|
272
347
|
} else {
|
|
273
348
|
logger.error(`[msgCacheGetLocalIDByUUID] ${cache.uuid} not found`);
|
|
274
349
|
}
|
|
@@ -289,9 +364,14 @@ async function MessageSendWithDecorator(ctx2, node, session, Deco) {
|
|
|
289
364
|
msgid: res[0],
|
|
290
365
|
uuid
|
|
291
366
|
};
|
|
292
|
-
|
|
293
|
-
|
|
367
|
+
if (!mc.msgid) {
|
|
368
|
+
throw new Error(`Empty Message ID`);
|
|
369
|
+
} else {
|
|
370
|
+
msgCache(mc);
|
|
371
|
+
logger.debug(`[MessageForward] to ${mc.platform} ${mc.uuid}`);
|
|
372
|
+
}
|
|
294
373
|
}).catch((error) => {
|
|
374
|
+
logger.error(`content: ${content}`);
|
|
295
375
|
throw error;
|
|
296
376
|
});
|
|
297
377
|
}
|
|
@@ -327,6 +407,10 @@ function botExistsCheck(ctx2, node) {
|
|
|
327
407
|
return true;
|
|
328
408
|
}
|
|
329
409
|
__name(botExistsCheck, "botExistsCheck");
|
|
410
|
+
function MsgUUIDFromSession(session) {
|
|
411
|
+
return session.channelId + ":" + session.messageId;
|
|
412
|
+
}
|
|
413
|
+
__name(MsgUUIDFromSession, "MsgUUIDFromSession");
|
|
330
414
|
|
|
331
415
|
// src/index.ts
|
|
332
416
|
var name = `forward hime - 转发姬`;
|
|
@@ -362,7 +446,7 @@ function apply(ctx2, cfg) {
|
|
|
362
446
|
session.platform,
|
|
363
447
|
session.channelId + ":" + session.messageId
|
|
364
448
|
);
|
|
365
|
-
let uuid = session
|
|
449
|
+
let uuid = MsgUUIDFromSession(session);
|
|
366
450
|
msgCache({
|
|
367
451
|
platform: session.platform,
|
|
368
452
|
bot: group.Nodes[k].BotID,
|
|
@@ -375,6 +459,9 @@ function apply(ctx2, cfg) {
|
|
|
375
459
|
}
|
|
376
460
|
}
|
|
377
461
|
}
|
|
462
|
+
if (hitGroup.length > 0) {
|
|
463
|
+
await MsgMiddlewareCache(session);
|
|
464
|
+
}
|
|
378
465
|
for (const g in hitGroup) {
|
|
379
466
|
const group = cfg.ForwardGroups[hitGroup[g]];
|
|
380
467
|
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,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koishi-plugin-forward-hime",
|
|
3
3
|
"description": "多群组消息互通",
|
|
4
|
-
"version": "1.3.
|
|
4
|
+
"version": "1.3.1",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "xianii",
|
|
7
7
|
"email": "jiyucheng007@gmail.com"
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"browser": true
|
|
16
16
|
},
|
|
17
17
|
"license": "MIT",
|
|
18
|
-
"homepage": "https://github.
|
|
18
|
+
"homepage": "https://nigh.github.io/forward-hime/",
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|
|
21
21
|
"url": "git+https://github.com/Nigh/forward-hime.git"
|