koishi-plugin-forward-hime 1.3.2 → 1.3.6
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/lib/config.d.ts +5 -2
- package/lib/decorator.d.ts +9 -0
- package/package.json +2 -2
- package/lib/index.js +0 -524
package/lib/config.d.ts
CHANGED
|
@@ -6,8 +6,11 @@ export interface ForwardNode {
|
|
|
6
6
|
note?: string;
|
|
7
7
|
}
|
|
8
8
|
export interface ConfigSet {
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
DefaultDecorator: {
|
|
10
|
+
Prefix: string;
|
|
11
|
+
Newline: boolean;
|
|
12
|
+
};
|
|
13
|
+
DefaultFallbackMsgPrefix: string;
|
|
11
14
|
CacheTimeout: number;
|
|
12
15
|
ForwardGroups: {
|
|
13
16
|
Nodes: ForwardNode[];
|
package/lib/decorator.d.ts
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { Session, Element } from "koishi";
|
|
2
2
|
import { ForwardNode } from "./config";
|
|
3
|
+
import { ConfigSet } from "./config";
|
|
4
|
+
interface ForwardMsg {
|
|
5
|
+
head: Element[];
|
|
6
|
+
content: Element[];
|
|
7
|
+
}
|
|
8
|
+
export declare function decoratorInit(cfg: ConfigSet): void;
|
|
9
|
+
export declare function defaultDecorator({ head, content }: ForwardMsg): Element[];
|
|
10
|
+
export declare function defaultMiddleware(session: Session): ForwardMsg;
|
|
3
11
|
export declare function MsgMiddlewareCache(session: Session): Promise<void>;
|
|
4
12
|
export declare function MsgDecorator(session: Session, node: ForwardNode): Promise<any>;
|
|
5
13
|
export declare function MsgDecoratorFallback(session: Session, node: ForwardNode): Promise<Element[]>;
|
|
14
|
+
export {};
|
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.6",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "xianii",
|
|
7
7
|
"email": "jiyucheng007@gmail.com"
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
|
51
51
|
"prepare": "husky",
|
|
52
|
-
"build": "atsc -
|
|
52
|
+
"build": "atsc -p tsconfig.json",
|
|
53
53
|
"eslint": "eslint . --ext .js,.jsx,.ts,.tsx",
|
|
54
54
|
"format": "prettier --write .",
|
|
55
55
|
"pub": "npm publish --access public"
|
package/lib/index.js
DELETED
|
@@ -1,524 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name2 in all)
|
|
8
|
-
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var src_exports = {};
|
|
22
|
-
__export(src_exports, {
|
|
23
|
-
Config: () => Config,
|
|
24
|
-
apply: () => apply,
|
|
25
|
-
inject: () => inject,
|
|
26
|
-
name: () => name,
|
|
27
|
-
reusable: () => reusable,
|
|
28
|
-
usage: () => usage
|
|
29
|
-
});
|
|
30
|
-
module.exports = __toCommonJS(src_exports);
|
|
31
|
-
|
|
32
|
-
// src/config.ts
|
|
33
|
-
var import_koishi = require("koishi");
|
|
34
|
-
var createConfig = /* @__PURE__ */ __name(() => import_koishi.Schema.intersect([
|
|
35
|
-
import_koishi.Schema.object({
|
|
36
|
-
WithChannelName: import_koishi.Schema.boolean().description("是否包含频道名称").default(false),
|
|
37
|
-
WithPlatformName: import_koishi.Schema.boolean().description("是否包含平台名称").default(true)
|
|
38
|
-
}).description("转发格式").hidden(),
|
|
39
|
-
import_koishi.Schema.object({
|
|
40
|
-
CacheTimeout: import_koishi.Schema.number().description("消息缓存时间(分钟)- 影响跨平台删除与回复等功能").default(120).min(120).max(1440 * 7)
|
|
41
|
-
}).description("消息缓存"),
|
|
42
|
-
import_koishi.Schema.object({
|
|
43
|
-
ForwardGroups: import_koishi.Schema.array(
|
|
44
|
-
import_koishi.Schema.object({
|
|
45
|
-
Note: import_koishi.Schema.string().description("互通组备注"),
|
|
46
|
-
Nodes: import_koishi.Schema.array(
|
|
47
|
-
import_koishi.Schema.object({
|
|
48
|
-
Platform: import_koishi.Schema.string().role("").required().description("平台"),
|
|
49
|
-
Guild: import_koishi.Schema.string().required().description("频道ID"),
|
|
50
|
-
BotID: import_koishi.Schema.string().required().description("机器人ID")
|
|
51
|
-
})
|
|
52
|
-
).role("table").description("转发节点")
|
|
53
|
-
})
|
|
54
|
-
).description("互通转发组")
|
|
55
|
-
}).description("互通组")
|
|
56
|
-
]), "createConfig");
|
|
57
|
-
|
|
58
|
-
// src/logger.ts
|
|
59
|
-
var import_koishi2 = require("koishi");
|
|
60
|
-
var logger = new import_koishi2.Logger("forward-hime");
|
|
61
|
-
logger.level = import_koishi2.Logger.INFO;
|
|
62
|
-
|
|
63
|
-
// src/decorator.ts
|
|
64
|
-
var import_koishi5 = require("koishi");
|
|
65
|
-
|
|
66
|
-
// src/decorators/index.ts
|
|
67
|
-
var decorators_exports = {};
|
|
68
|
-
__export(decorators_exports, {
|
|
69
|
-
kook: () => kook_default,
|
|
70
|
-
onebot: () => onebot_default
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
// src/decorators/kook.ts
|
|
74
|
-
var import_koishi3 = require("koishi");
|
|
75
|
-
var import_buffer = require("buffer");
|
|
76
|
-
var transparentPixel = import_buffer.Buffer.from(
|
|
77
|
-
"R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==",
|
|
78
|
-
"base64"
|
|
79
|
-
);
|
|
80
|
-
function Decorator({ head, content }) {
|
|
81
|
-
let msg = [];
|
|
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
|
-
}
|
|
92
|
-
return msg;
|
|
93
|
-
}
|
|
94
|
-
__name(Decorator, "Decorator");
|
|
95
|
-
var kook_default = {
|
|
96
|
-
Decorator
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
// src/decorators/onebot.ts
|
|
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");
|
|
125
|
-
function Middleware(session) {
|
|
126
|
-
const platform = guessPlatform(session);
|
|
127
|
-
let newContent = [];
|
|
128
|
-
let head = [
|
|
129
|
-
(0, import_koishi4.h)("b", `${session.username}`),
|
|
130
|
-
(0, import_koishi4.h)("span", " 转发自 "),
|
|
131
|
-
(0, import_koishi4.h)("i", `${platform}`),
|
|
132
|
-
(0, import_koishi4.h)("span", `:`)
|
|
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
|
-
}
|
|
153
|
-
return { head, content: session.elements };
|
|
154
|
-
}
|
|
155
|
-
__name(Middleware, "Middleware");
|
|
156
|
-
function guessPlatform(session) {
|
|
157
|
-
if (session.event.user && session.event.user.avatar) {
|
|
158
|
-
if (session.event.user.avatar.includes("q.qlogo.cn")) {
|
|
159
|
-
return "QQ";
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
return session.platform;
|
|
163
|
-
}
|
|
164
|
-
__name(guessPlatform, "guessPlatform");
|
|
165
|
-
var onebot_default = {
|
|
166
|
-
Middleware
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
// src/cache.ts
|
|
170
|
-
var ctx;
|
|
171
|
-
var cacheTimeout = 86400 * 1e3;
|
|
172
|
-
function cacheNotEnabled() {
|
|
173
|
-
if (!ctx.cache) {
|
|
174
|
-
return true;
|
|
175
|
-
}
|
|
176
|
-
return false;
|
|
177
|
-
}
|
|
178
|
-
__name(cacheNotEnabled, "cacheNotEnabled");
|
|
179
|
-
function msgCacheInit(context, cfg) {
|
|
180
|
-
ctx = context;
|
|
181
|
-
cacheTimeout = 60 * cfg.CacheTimeout * 1e3;
|
|
182
|
-
}
|
|
183
|
-
__name(msgCacheInit, "msgCacheInit");
|
|
184
|
-
async function msgCache(mc) {
|
|
185
|
-
if (cacheNotEnabled()) {
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
const key = mc.guild + ":" + mc.msgid;
|
|
189
|
-
logger.debug(`[message-cache] ${mc.platform} ${key}`);
|
|
190
|
-
await ctx.cache.set("msgCache", key, mc, cacheTimeout);
|
|
191
|
-
}
|
|
192
|
-
__name(msgCache, "msgCache");
|
|
193
|
-
async function msgCacheDelete(key) {
|
|
194
|
-
if (cacheNotEnabled()) {
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
await ctx.cache.delete("msgCache", key);
|
|
198
|
-
}
|
|
199
|
-
__name(msgCacheDelete, "msgCacheDelete");
|
|
200
|
-
async function msgCacheFindByKey(key) {
|
|
201
|
-
if (cacheNotEnabled()) {
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
return await ctx.cache.get("msgCache", key);
|
|
205
|
-
}
|
|
206
|
-
__name(msgCacheFindByKey, "msgCacheFindByKey");
|
|
207
|
-
async function msgCacheFindByUUID(uuid) {
|
|
208
|
-
if (cacheNotEnabled()) {
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
let caches = await ctx.cache.entries("msgCache");
|
|
212
|
-
let result = [];
|
|
213
|
-
for await (const item of caches) {
|
|
214
|
-
if (item[1].uuid === uuid) {
|
|
215
|
-
result.push(item);
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
return result;
|
|
219
|
-
}
|
|
220
|
-
__name(msgCacheFindByUUID, "msgCacheFindByUUID");
|
|
221
|
-
async function msgCacheGetLocalIDByUUID(node, uuid) {
|
|
222
|
-
if (cacheNotEnabled()) {
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
let caches = await ctx.cache.entries("msgCache");
|
|
226
|
-
for await (const item of caches) {
|
|
227
|
-
if (item[1].uuid === uuid && item[1].platform === node.Platform && item[1].guild === node.Guild && item[1].bot === node.BotID) {
|
|
228
|
-
return item[1].msgid;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
__name(msgCacheGetLocalIDByUUID, "msgCacheGetLocalIDByUUID");
|
|
233
|
-
|
|
234
|
-
// src/decorator.ts
|
|
235
|
-
function defaultDecorator({ head, content }) {
|
|
236
|
-
let msg = [];
|
|
237
|
-
msg = msg.concat(head, (0, import_koishi5.h)("br"), content);
|
|
238
|
-
return msg;
|
|
239
|
-
}
|
|
240
|
-
__name(defaultDecorator, "defaultDecorator");
|
|
241
|
-
function defaultMiddleware(session) {
|
|
242
|
-
let head = [
|
|
243
|
-
(0, import_koishi5.h)("b", `${session.username}`),
|
|
244
|
-
(0, import_koishi5.h)("span", " 转发自 "),
|
|
245
|
-
(0, import_koishi5.h)("i", `${session.platform}`),
|
|
246
|
-
(0, import_koishi5.h)("span", `:`)
|
|
247
|
-
];
|
|
248
|
-
return { head, content: session.elements };
|
|
249
|
-
}
|
|
250
|
-
__name(defaultMiddleware, "defaultMiddleware");
|
|
251
|
-
var localDecorators = [atTranslator, quoteTranslator];
|
|
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) {
|
|
271
|
-
let elems = { head: [], content: [] };
|
|
272
|
-
let _platform_in = decorators_exports[session.platform];
|
|
273
|
-
if (_platform_in && typeof _platform_in.Middleware === "function") {
|
|
274
|
-
elems = _platform_in.Middleware(session);
|
|
275
|
-
} else {
|
|
276
|
-
elems = defaultMiddleware(session);
|
|
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
|
-
}
|
|
298
|
-
for (const fn of localDecorators) {
|
|
299
|
-
elems = await fn(session, node, elems);
|
|
300
|
-
}
|
|
301
|
-
if (_platform_out && typeof _platform_out.Decorator === "function") {
|
|
302
|
-
return _platform_out.Decorator(elems);
|
|
303
|
-
} else {
|
|
304
|
-
return defaultDecorator(elems);
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
__name(MsgDecorator, "MsgDecorator");
|
|
308
|
-
function defaultDecoratorFallback({ head, content }) {
|
|
309
|
-
let msg = [];
|
|
310
|
-
let newContent = [];
|
|
311
|
-
newContent.push((0, import_koishi5.h)("span", `[消息降级] `));
|
|
312
|
-
for (const key in content) {
|
|
313
|
-
if (["img", "audio", "video", "file"].includes(content[key].type)) {
|
|
314
|
-
newContent.push((0, import_koishi5.h)("span", ` [${content[key].type}] `));
|
|
315
|
-
} else {
|
|
316
|
-
newContent.push(content[key]);
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
msg = msg.concat(head, (0, import_koishi5.h)("br"), newContent);
|
|
320
|
-
return msg;
|
|
321
|
-
}
|
|
322
|
-
__name(defaultDecoratorFallback, "defaultDecoratorFallback");
|
|
323
|
-
async function MsgDecoratorFallback(session, node) {
|
|
324
|
-
let elems = { head: [], content: [] };
|
|
325
|
-
elems = defaultMiddleware(session);
|
|
326
|
-
for (const fn of localDecorators) {
|
|
327
|
-
elems = await fn(session, node, elems);
|
|
328
|
-
}
|
|
329
|
-
return defaultDecoratorFallback(elems);
|
|
330
|
-
}
|
|
331
|
-
__name(MsgDecoratorFallback, "MsgDecoratorFallback");
|
|
332
|
-
async function atTranslator(session, node, { head, content }) {
|
|
333
|
-
const newMsg = await new Promise((resolve, reject) => {
|
|
334
|
-
let newContent = [];
|
|
335
|
-
for (const key in content) {
|
|
336
|
-
const element = content[key];
|
|
337
|
-
if (element.type === "at") {
|
|
338
|
-
if (element.attrs.id !== session.selfId) {
|
|
339
|
-
newContent.push(
|
|
340
|
-
(0, import_koishi5.h)("span", `@${element.attrs.name || element.attrs.id}`)
|
|
341
|
-
);
|
|
342
|
-
}
|
|
343
|
-
} else {
|
|
344
|
-
newContent.push(element);
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
resolve({ head, content: newContent });
|
|
348
|
-
});
|
|
349
|
-
return newMsg;
|
|
350
|
-
}
|
|
351
|
-
__name(atTranslator, "atTranslator");
|
|
352
|
-
async function quoteTranslator(session, node, { head, content }) {
|
|
353
|
-
if (!session.quote || !session.quote.id) {
|
|
354
|
-
return { head, content };
|
|
355
|
-
}
|
|
356
|
-
const key = session.channelId + ":" + session.quote.id;
|
|
357
|
-
const cache = await msgCacheFindByKey(key);
|
|
358
|
-
if (cache) {
|
|
359
|
-
let msgid = await msgCacheGetLocalIDByUUID(node, cache.uuid);
|
|
360
|
-
if (msgid) {
|
|
361
|
-
let newHead = [(0, import_koishi5.h)("quote", { id: msgid })].concat(head);
|
|
362
|
-
return { head: newHead, content };
|
|
363
|
-
} else {
|
|
364
|
-
logger.error(`[msgCacheGetLocalIDByUUID] ${cache.uuid} not found`);
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
return { head, content };
|
|
368
|
-
}
|
|
369
|
-
__name(quoteTranslator, "quoteTranslator");
|
|
370
|
-
|
|
371
|
-
// src/message.ts
|
|
372
|
-
async function MessageSendWithDecorator(ctx2, node, session, Deco) {
|
|
373
|
-
const uuid = session.channelId + ":" + session.messageId;
|
|
374
|
-
const content = await Deco(session, node);
|
|
375
|
-
await ctx2.bots[`${node.Platform}:${node.BotID}`].sendMessage(node.Guild, content).then((res) => {
|
|
376
|
-
let mc = {
|
|
377
|
-
platform: node.Platform,
|
|
378
|
-
bot: node.BotID,
|
|
379
|
-
guild: node.Guild,
|
|
380
|
-
msgid: res[0],
|
|
381
|
-
uuid
|
|
382
|
-
};
|
|
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
|
-
}
|
|
389
|
-
}).catch((error) => {
|
|
390
|
-
logger.error(`content: ${content}`);
|
|
391
|
-
throw error;
|
|
392
|
-
});
|
|
393
|
-
}
|
|
394
|
-
__name(MessageSendWithDecorator, "MessageSendWithDecorator");
|
|
395
|
-
async function MessageForward(ctx2, node, session) {
|
|
396
|
-
if (!botExistsCheck(ctx2, node)) {
|
|
397
|
-
return;
|
|
398
|
-
}
|
|
399
|
-
MessageSendWithDecorator(ctx2, node, session, MsgDecorator).catch((error) => {
|
|
400
|
-
logger.error(`ERROR:<MessageSend ${node.Platform}> ${error}`);
|
|
401
|
-
MessageSendWithDecorator(ctx2, node, session, MsgDecoratorFallback).catch(
|
|
402
|
-
(error2) => {
|
|
403
|
-
logger.error(`ERROR:<MessageSendFallback ${node.Platform}> ${error2}`);
|
|
404
|
-
}
|
|
405
|
-
);
|
|
406
|
-
});
|
|
407
|
-
}
|
|
408
|
-
__name(MessageForward, "MessageForward");
|
|
409
|
-
async function MessageDelete(ctx2, msg) {
|
|
410
|
-
if (!botExistsCheck(ctx2, { Platform: msg.platform, BotID: msg.bot, Guild: msg.guild })) {
|
|
411
|
-
return;
|
|
412
|
-
}
|
|
413
|
-
await ctx2.bots[`${msg.platform}:${msg.bot}`].deleteMessage(msg.guild, msg.msgid).catch((error) => {
|
|
414
|
-
logger.error(`ERROR:<MessageDelete> ${error}`);
|
|
415
|
-
});
|
|
416
|
-
}
|
|
417
|
-
__name(MessageDelete, "MessageDelete");
|
|
418
|
-
function botExistsCheck(ctx2, node) {
|
|
419
|
-
if (ctx2.bots[`${node.Platform}:${node.BotID}`] == void 0) {
|
|
420
|
-
logger.error(`ERROR:<BOT not Exist> ${node.Platform}:${node.BotID}`);
|
|
421
|
-
return false;
|
|
422
|
-
}
|
|
423
|
-
return true;
|
|
424
|
-
}
|
|
425
|
-
__name(botExistsCheck, "botExistsCheck");
|
|
426
|
-
function MsgUUIDFromSession(session) {
|
|
427
|
-
return session.channelId + ":" + session.messageId;
|
|
428
|
-
}
|
|
429
|
-
__name(MsgUUIDFromSession, "MsgUUIDFromSession");
|
|
430
|
-
|
|
431
|
-
// src/index.ts
|
|
432
|
-
var name = `forward hime - 转发姬`;
|
|
433
|
-
var usage = `
|
|
434
|
-
# ${name}
|
|
435
|
-
## 配置说明
|
|
436
|
-
1. 添加 \`互通转发组\`
|
|
437
|
-
2. 为添加的 \`互通转发组\` 配置转发节点。每个转发节点对应某个平台的一个频道或群组
|
|
438
|
-
|
|
439
|
-
注意:当未配置\`cache\`时,跨平台删除、跨平台回复等功能将无法正常工作。
|
|
440
|
-
## 特性
|
|
441
|
-
- 可以配置多个 \`互通转发组\`,每个 \`互通转发组\` 之间相互独立
|
|
442
|
-
- 启用插件后,当一个 \`互通转发组\` 中的任意节点收到消息时,插件会自动将消息转发给**这个**\`互通转发组\`中的其他节点。
|
|
443
|
-
---`;
|
|
444
|
-
var reusable = true;
|
|
445
|
-
var inject = {
|
|
446
|
-
optional: ["cache"]
|
|
447
|
-
};
|
|
448
|
-
var Config = createConfig();
|
|
449
|
-
function apply(ctx2, cfg) {
|
|
450
|
-
msgCacheInit(ctx2, cfg);
|
|
451
|
-
ctx2.on("message-created", async (session) => {
|
|
452
|
-
const hitGroup = [];
|
|
453
|
-
for (const g in cfg.ForwardGroups) {
|
|
454
|
-
const group = cfg.ForwardGroups[g];
|
|
455
|
-
for (const k in group.Nodes) {
|
|
456
|
-
if (group.Nodes[k].Guild === session.channelId && group.Nodes[k].Platform === session.platform && group.Nodes[k].BotID !== session.userId) {
|
|
457
|
-
if (!session.channelId || !session.messageId) {
|
|
458
|
-
continue;
|
|
459
|
-
}
|
|
460
|
-
logger.debug(
|
|
461
|
-
"[message-created]",
|
|
462
|
-
session.platform,
|
|
463
|
-
session.channelId + ":" + session.messageId
|
|
464
|
-
);
|
|
465
|
-
let uuid = MsgUUIDFromSession(session);
|
|
466
|
-
msgCache({
|
|
467
|
-
platform: session.platform,
|
|
468
|
-
bot: group.Nodes[k].BotID,
|
|
469
|
-
guild: session.channelId,
|
|
470
|
-
msgid: session.messageId,
|
|
471
|
-
uuid
|
|
472
|
-
});
|
|
473
|
-
hitGroup.push(g);
|
|
474
|
-
break;
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
if (hitGroup.length > 0) {
|
|
479
|
-
await MsgMiddlewareCache(session);
|
|
480
|
-
}
|
|
481
|
-
for (const g in hitGroup) {
|
|
482
|
-
const group = cfg.ForwardGroups[hitGroup[g]];
|
|
483
|
-
for (const k in group.Nodes) {
|
|
484
|
-
if (group.Nodes[k].Guild !== session.channelId) {
|
|
485
|
-
MessageForward(ctx2, group.Nodes[k], session);
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
});
|
|
490
|
-
ctx2.on("message-deleted", async (session) => {
|
|
491
|
-
const cacheKey = session.channelId + ":" + session.messageId;
|
|
492
|
-
logger.debug("[message-deleted]", cacheKey);
|
|
493
|
-
msgCacheFindByKey(cacheKey).then((res) => {
|
|
494
|
-
if (res) {
|
|
495
|
-
logger.debug("[msgCacheFindByKey]", res);
|
|
496
|
-
msgCacheDelete(cacheKey);
|
|
497
|
-
const uuid = res.uuid;
|
|
498
|
-
msgCacheFindByUUID(uuid).then((res2) => {
|
|
499
|
-
if (res2) {
|
|
500
|
-
for (const k in res2) {
|
|
501
|
-
logger.debug("[message-delete]", res2[k][1]);
|
|
502
|
-
msgCacheDelete(res2[k][0]).then(() => {
|
|
503
|
-
MessageDelete(ctx2, res2[k][1]);
|
|
504
|
-
});
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
});
|
|
508
|
-
}
|
|
509
|
-
});
|
|
510
|
-
});
|
|
511
|
-
ctx2.on("message-updated", async (session) => {
|
|
512
|
-
logger.debug("[message-updated]", session.messageId, session);
|
|
513
|
-
});
|
|
514
|
-
}
|
|
515
|
-
__name(apply, "apply");
|
|
516
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
517
|
-
0 && (module.exports = {
|
|
518
|
-
Config,
|
|
519
|
-
apply,
|
|
520
|
-
inject,
|
|
521
|
-
name,
|
|
522
|
-
reusable,
|
|
523
|
-
usage
|
|
524
|
-
});
|