koishi-plugin-forward-hime 1.1.1 → 1.2.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 +26 -0
- package/lib/cache.d.ts +17 -0
- package/lib/config.d.ts +4 -3
- package/lib/decorators/index.d.ts +2 -0
- package/lib/decorators/kook.d.ts +5 -1
- package/lib/decorators/onebot.d.ts +9 -0
- package/lib/index.d.ts +5 -1
- package/lib/index.js +221 -58
- package/lib/message.d.ts +3 -0
- package/package.json +72 -73
- package/readme.md +0 -5
package/README.md
ADDED
|
@@ -0,0 +1,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
|
+
## 安装
|
|
11
|
+
|
|
12
|
+
在 Koishi WebUI 或 Koishi 桌面应用中,打开插件市场,搜索 `forward-hime`,找到本插件后,点击 `添加` 按钮后点击 `安装` 即可。
|
|
13
|
+
|
|
14
|
+
## 配置
|
|
15
|
+
|
|
16
|
+
在插件配置页面中,可以添加 `互通转发组`。然后需要为 `互通转发组` 配置转发节点。每个转发节点对应某个平台的一个频道或群组。
|
|
17
|
+
|
|
18
|
+
可以配置多个 `互通转发组`,每个 `互通转发组` 之间相互独立。
|
|
19
|
+
|
|
20
|
+
## 使用
|
|
21
|
+
|
|
22
|
+
启用插件后,当一个 `互通转发组` 中的任意节点收到消息时,插件会自动将消息转发给**这个**`互通转发组`中的其他节点。
|
|
23
|
+
|
|
24
|
+
## 贡献者
|
|
25
|
+
|
|
26
|
+
[](https://github.com/Nigh/forward-hime/graphs/contributors)
|
package/lib/cache.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Context } from "koishi";
|
|
2
|
+
export interface MsgCache {
|
|
3
|
+
platform: string;
|
|
4
|
+
bot: string;
|
|
5
|
+
guild: string;
|
|
6
|
+
msgid: string;
|
|
7
|
+
uuid: string;
|
|
8
|
+
}
|
|
9
|
+
declare module "@koishijs/cache" {
|
|
10
|
+
interface Tables {
|
|
11
|
+
msgCache: MsgCache;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export declare function msgCache(ctx: Context, mc: MsgCache): Promise<void>;
|
|
15
|
+
export declare function msgCacheDelete(ctx: Context, key: string): Promise<void>;
|
|
16
|
+
export declare function msgCacheFindByKey(ctx: Context, key: string): Promise<MsgCache>;
|
|
17
|
+
export declare function msgCacheFindByUUID(ctx: Context, uuid: string): Promise<any[]>;
|
package/lib/config.d.ts
CHANGED
|
@@ -6,9 +6,10 @@ export interface ForwardNode {
|
|
|
6
6
|
note?: string;
|
|
7
7
|
}
|
|
8
8
|
export interface ConfigSet {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
WithChannelName: boolean;
|
|
10
|
+
WithPlatformName: boolean;
|
|
11
|
+
ForwardGroups: {
|
|
12
|
+
Nodes: ForwardNode[];
|
|
12
13
|
}[];
|
|
13
14
|
}
|
|
14
15
|
export declare const createConfig: () => Schema<ConfigSet>;
|
package/lib/decorators/kook.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { Element } from "koishi";
|
|
2
|
-
|
|
2
|
+
declare function Decorator({ head, content }: {
|
|
3
3
|
head: any;
|
|
4
4
|
content: any;
|
|
5
5
|
}): Element[];
|
|
6
|
+
declare const _default: {
|
|
7
|
+
Decorator: typeof Decorator;
|
|
8
|
+
};
|
|
9
|
+
export default _default;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { Context } from "koishi";
|
|
2
2
|
import { ConfigSet } from "./config";
|
|
3
|
+
export declare const name = "forward hime - \u8F6C\u53D1\u59EC";
|
|
4
|
+
export declare const usage = "\n# forward hime - \u8F6C\u53D1\u59EC <sub>v1.2.1</sub>\n## \u914D\u7F6E\u8BF4\u660E\n1. \u6DFB\u52A0 `\u4E92\u901A\u8F6C\u53D1\u7EC4`\n2. \u4E3A\u6DFB\u52A0\u7684 `\u4E92\u901A\u8F6C\u53D1\u7EC4` \u914D\u7F6E\u8F6C\u53D1\u8282\u70B9\u3002\u6BCF\u4E2A\u8F6C\u53D1\u8282\u70B9\u5BF9\u5E94\u67D0\u4E2A\u5E73\u53F0\u7684\u4E00\u4E2A\u9891\u9053\u6216\u7FA4\u7EC4\n\n\u6CE8\u610F\uFF1A\u5F53\u672A\u914D\u7F6E`cache`\u65F6\uFF0C\u8DE8\u5E73\u53F0\u5220\u9664\u3001\u8DE8\u5E73\u53F0\u56DE\u590D\u7B49\u529F\u80FD\u5C06\u65E0\u6CD5\u6B63\u5E38\u5DE5\u4F5C\u3002\n## \u7279\u6027\n- \u53EF\u4EE5\u914D\u7F6E\u591A\u4E2A `\u4E92\u901A\u8F6C\u53D1\u7EC4`\uFF0C\u6BCF\u4E2A `\u4E92\u901A\u8F6C\u53D1\u7EC4` \u4E4B\u95F4\u76F8\u4E92\u72EC\u7ACB\n- \u542F\u7528\u63D2\u4EF6\u540E\uFF0C\u5F53\u4E00\u4E2A `\u4E92\u901A\u8F6C\u53D1\u7EC4` \u4E2D\u7684\u4EFB\u610F\u8282\u70B9\u6536\u5230\u6D88\u606F\u65F6\uFF0C\u63D2\u4EF6\u4F1A\u81EA\u52A8\u5C06\u6D88\u606F\u8F6C\u53D1\u7ED9**\u8FD9\u4E2A**`\u4E92\u901A\u8F6C\u53D1\u7EC4`\u4E2D\u7684\u5176\u4ED6\u8282\u70B9\u3002\n---";
|
|
3
5
|
export declare const reusable = true;
|
|
4
|
-
export declare const
|
|
6
|
+
export declare const inject: {
|
|
7
|
+
optional: string[];
|
|
8
|
+
};
|
|
5
9
|
export declare const Config: import("schemastery")<ConfigSet>;
|
|
6
10
|
export declare function apply(ctx: Context, cfg: ConfigSet): void;
|
package/lib/index.js
CHANGED
|
@@ -4,8 +4,8 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
5
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
6
|
var __export = (target, all) => {
|
|
7
|
-
for (var
|
|
8
|
-
__defProp(target,
|
|
7
|
+
for (var name2 in all)
|
|
8
|
+
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
9
9
|
};
|
|
10
10
|
var __copyProps = (to, from, except, desc) => {
|
|
11
11
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
@@ -22,6 +22,8 @@ var src_exports = {};
|
|
|
22
22
|
__export(src_exports, {
|
|
23
23
|
Config: () => Config,
|
|
24
24
|
apply: () => apply,
|
|
25
|
+
inject: () => inject,
|
|
26
|
+
name: () => name,
|
|
25
27
|
reusable: () => reusable,
|
|
26
28
|
usage: () => usage
|
|
27
29
|
});
|
|
@@ -31,29 +33,23 @@ module.exports = __toCommonJS(src_exports);
|
|
|
31
33
|
var import_koishi = require("koishi");
|
|
32
34
|
var createConfig = /* @__PURE__ */ __name(() => import_koishi.Schema.intersect([
|
|
33
35
|
import_koishi.Schema.object({
|
|
34
|
-
|
|
36
|
+
WithChannelName: import_koishi.Schema.boolean().description("是否包含频道名称").default(false),
|
|
37
|
+
WithPlatformName: import_koishi.Schema.boolean().description("是否包含平台名称").default(true)
|
|
35
38
|
}).description("转发格式"),
|
|
36
39
|
import_koishi.Schema.object({
|
|
37
|
-
|
|
40
|
+
ForwardGroups: import_koishi.Schema.array(
|
|
38
41
|
import_koishi.Schema.object({
|
|
39
|
-
|
|
42
|
+
Note: import_koishi.Schema.string().description("互通组备注"),
|
|
43
|
+
Nodes: import_koishi.Schema.array(
|
|
40
44
|
import_koishi.Schema.object({
|
|
41
|
-
Platform: import_koishi.Schema.
|
|
42
|
-
"telegram",
|
|
43
|
-
"discord",
|
|
44
|
-
"onebot",
|
|
45
|
-
"kook",
|
|
46
|
-
"slack",
|
|
47
|
-
"qq"
|
|
48
|
-
]).role("select").required().description("平台"),
|
|
45
|
+
Platform: import_koishi.Schema.string().role("").required().description("平台"),
|
|
49
46
|
Guild: import_koishi.Schema.string().required().description("频道ID"),
|
|
50
|
-
BotID: import_koishi.Schema.string().required().description("机器人ID")
|
|
51
|
-
note: import_koishi.Schema.string().description("备注")
|
|
47
|
+
BotID: import_koishi.Schema.string().required().description("机器人ID")
|
|
52
48
|
})
|
|
53
|
-
).role("table").description("
|
|
49
|
+
).role("table").description("转发节点")
|
|
54
50
|
})
|
|
55
51
|
).description("互通转发组")
|
|
56
|
-
})
|
|
52
|
+
}).description("互通组")
|
|
57
53
|
]), "createConfig");
|
|
58
54
|
|
|
59
55
|
// src/logger.ts
|
|
@@ -61,7 +57,14 @@ var import_koishi2 = require("koishi");
|
|
|
61
57
|
var logger = new import_koishi2.Logger("forward-hime");
|
|
62
58
|
|
|
63
59
|
// src/decorator.ts
|
|
64
|
-
var
|
|
60
|
+
var import_koishi5 = require("koishi");
|
|
61
|
+
|
|
62
|
+
// src/decorators/index.ts
|
|
63
|
+
var decorators_exports = {};
|
|
64
|
+
__export(decorators_exports, {
|
|
65
|
+
kook: () => kook_default,
|
|
66
|
+
onebot: () => onebot_default
|
|
67
|
+
});
|
|
65
68
|
|
|
66
69
|
// src/decorators/kook.ts
|
|
67
70
|
var import_koishi3 = require("koishi");
|
|
@@ -70,97 +73,257 @@ var transparentPixel = import_buffer.Buffer.from(
|
|
|
70
73
|
"R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==",
|
|
71
74
|
"base64"
|
|
72
75
|
);
|
|
73
|
-
function
|
|
76
|
+
function Decorator({ head, content }) {
|
|
74
77
|
let msg = [];
|
|
75
78
|
msg = msg.concat(head, (0, import_koishi3.h)("br"), content, import_koishi3.h.image(transparentPixel, "image/gif"));
|
|
76
79
|
return msg;
|
|
77
80
|
}
|
|
78
|
-
__name(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
var decorators = {
|
|
82
|
-
kook
|
|
81
|
+
__name(Decorator, "Decorator");
|
|
82
|
+
var kook_default = {
|
|
83
|
+
Decorator
|
|
83
84
|
};
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
__name(defaultDeco, "defaultDeco");
|
|
90
|
-
function defaultMiddleware(session) {
|
|
85
|
+
|
|
86
|
+
// src/decorators/onebot.ts
|
|
87
|
+
var import_koishi4 = require("koishi");
|
|
88
|
+
function Middleware(session) {
|
|
89
|
+
const platform = guessPlatform(session);
|
|
91
90
|
let head = [
|
|
92
91
|
(0, import_koishi4.h)("b", `${session.username}`),
|
|
93
92
|
(0, import_koishi4.h)("span", " 转发自 "),
|
|
94
|
-
(0, import_koishi4.h)("i", `${
|
|
93
|
+
(0, import_koishi4.h)("i", `${platform}`),
|
|
95
94
|
(0, import_koishi4.h)("span", `:`)
|
|
96
95
|
];
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
96
|
+
return { head, content: session.elements };
|
|
97
|
+
}
|
|
98
|
+
__name(Middleware, "Middleware");
|
|
99
|
+
function guessPlatform(session) {
|
|
100
|
+
if (session.event.user && session.event.user.avatar) {
|
|
101
|
+
if (session.event.user.avatar.includes("q.qlogo.cn")) {
|
|
102
|
+
return "QQ";
|
|
102
103
|
}
|
|
103
104
|
}
|
|
105
|
+
return session.platform;
|
|
106
|
+
}
|
|
107
|
+
__name(guessPlatform, "guessPlatform");
|
|
108
|
+
var onebot_default = {
|
|
109
|
+
Middleware
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
// src/decorator.ts
|
|
113
|
+
function defaultDecorator({ head, content }) {
|
|
114
|
+
let msg = [];
|
|
115
|
+
msg = msg.concat(head, (0, import_koishi5.h)("br"), content);
|
|
116
|
+
return msg;
|
|
117
|
+
}
|
|
118
|
+
__name(defaultDecorator, "defaultDecorator");
|
|
119
|
+
function defaultMiddleware(session) {
|
|
120
|
+
let head = [
|
|
121
|
+
(0, import_koishi5.h)("b", `${session.username}`),
|
|
122
|
+
(0, import_koishi5.h)("span", " 转发自 "),
|
|
123
|
+
(0, import_koishi5.h)("i", `${session.platform}`),
|
|
124
|
+
(0, import_koishi5.h)("span", `:`)
|
|
125
|
+
];
|
|
104
126
|
return { head, content: session.elements };
|
|
105
127
|
}
|
|
106
128
|
__name(defaultMiddleware, "defaultMiddleware");
|
|
129
|
+
var localDecorators = [at2Name];
|
|
107
130
|
function MsgDecorator(session, node) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
131
|
+
let elems;
|
|
132
|
+
let _platform_in = decorators_exports[session.platform];
|
|
133
|
+
let _platform_out = decorators_exports[node.Platform];
|
|
134
|
+
if (_platform_in && typeof _platform_in.Middleware === "function") {
|
|
135
|
+
elems = _platform_in.Middleware(session);
|
|
111
136
|
} else {
|
|
112
|
-
|
|
137
|
+
elems = defaultMiddleware(session);
|
|
138
|
+
}
|
|
139
|
+
localDecorators.forEach((fn) => {
|
|
140
|
+
elems = fn(elems);
|
|
141
|
+
});
|
|
142
|
+
if (_platform_out && typeof _platform_out.Decorator === "function") {
|
|
143
|
+
return _platform_out.Decorator(elems);
|
|
144
|
+
} else {
|
|
145
|
+
return defaultDecorator(elems);
|
|
113
146
|
}
|
|
114
147
|
}
|
|
115
148
|
__name(MsgDecorator, "MsgDecorator");
|
|
149
|
+
function at2Name({ head, content }) {
|
|
150
|
+
for (const key in content) {
|
|
151
|
+
const element = content[key];
|
|
152
|
+
if (element.type === "at") {
|
|
153
|
+
content[key] = (0, import_koishi5.h)("span", `@${element.attrs.name || element.attrs.id}`);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return { head, content };
|
|
157
|
+
}
|
|
158
|
+
__name(at2Name, "at2Name");
|
|
159
|
+
|
|
160
|
+
// src/cache.ts
|
|
161
|
+
function cacheNotEnabled(ctx) {
|
|
162
|
+
if (!ctx.cache) {
|
|
163
|
+
return true;
|
|
164
|
+
}
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
__name(cacheNotEnabled, "cacheNotEnabled");
|
|
168
|
+
async function msgCache(ctx, mc) {
|
|
169
|
+
if (cacheNotEnabled(ctx)) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
const key = mc.guild + ":" + mc.msgid;
|
|
173
|
+
logger.debug("[message-cache]", key, mc);
|
|
174
|
+
await ctx.cache.set("msgCache", key, mc, 7200 * 1e3);
|
|
175
|
+
}
|
|
176
|
+
__name(msgCache, "msgCache");
|
|
177
|
+
async function msgCacheDelete(ctx, key) {
|
|
178
|
+
if (cacheNotEnabled(ctx)) {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
await ctx.cache.delete("msgCache", key);
|
|
182
|
+
}
|
|
183
|
+
__name(msgCacheDelete, "msgCacheDelete");
|
|
184
|
+
async function msgCacheFindByKey(ctx, key) {
|
|
185
|
+
if (cacheNotEnabled(ctx)) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
return await ctx.cache.get("msgCache", key);
|
|
189
|
+
}
|
|
190
|
+
__name(msgCacheFindByKey, "msgCacheFindByKey");
|
|
191
|
+
async function msgCacheFindByUUID(ctx, uuid) {
|
|
192
|
+
if (cacheNotEnabled(ctx)) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
let caches = await ctx.cache.entries("msgCache");
|
|
196
|
+
let result = [];
|
|
197
|
+
for await (const item of caches) {
|
|
198
|
+
if (item[1].uuid === uuid) {
|
|
199
|
+
result.push(item);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return result;
|
|
203
|
+
}
|
|
204
|
+
__name(msgCacheFindByUUID, "msgCacheFindByUUID");
|
|
116
205
|
|
|
117
206
|
// src/message.ts
|
|
118
207
|
async function MessageForward(ctx, node, session) {
|
|
119
208
|
try {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
209
|
+
botExistsCheck(ctx, node);
|
|
210
|
+
const uuid = session.channelId + ":" + session.messageId;
|
|
211
|
+
await ctx.bots[`${node.Platform}:${node.BotID}`].sendMessage(node.Guild, MsgDecorator(session, node)).then((res) => {
|
|
212
|
+
let mc = {
|
|
213
|
+
platform: node.Platform,
|
|
214
|
+
bot: node.BotID,
|
|
215
|
+
guild: node.Guild,
|
|
216
|
+
msgid: res[0],
|
|
217
|
+
uuid
|
|
218
|
+
};
|
|
219
|
+
msgCache(ctx, mc);
|
|
220
|
+
logger.debug("Forward", mc);
|
|
221
|
+
});
|
|
127
222
|
} catch (error) {
|
|
128
223
|
logger.error(`ERROR:<MessageSend> ${error}`);
|
|
129
224
|
}
|
|
130
225
|
}
|
|
131
226
|
__name(MessageForward, "MessageForward");
|
|
227
|
+
async function MessageDelete(ctx, msg) {
|
|
228
|
+
try {
|
|
229
|
+
botExistsCheck(ctx, { Platform: msg.platform, BotID: msg.bot, Guild: msg.guild });
|
|
230
|
+
await ctx.bots[`${msg.platform}:${msg.bot}`].deleteMessage(msg.guild, msg.msgid);
|
|
231
|
+
} catch (error) {
|
|
232
|
+
logger.error(`ERROR:<MessageDelete> ${error}`);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
__name(MessageDelete, "MessageDelete");
|
|
236
|
+
function botExistsCheck(ctx, node) {
|
|
237
|
+
if (ctx.bots[`${node.Platform}:${node.BotID}`] == void 0) {
|
|
238
|
+
throw new Error("Bot Not Found");
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
__name(botExistsCheck, "botExistsCheck");
|
|
132
242
|
|
|
133
243
|
// src/index.ts
|
|
244
|
+
var name = `forward hime - 转发姬`;
|
|
245
|
+
var version = `<sub>v1.2.1</sub>`;
|
|
246
|
+
var usage = `
|
|
247
|
+
# ${name} ${version}
|
|
248
|
+
## 配置说明
|
|
249
|
+
1. 添加 \`互通转发组\`
|
|
250
|
+
2. 为添加的 \`互通转发组\` 配置转发节点。每个转发节点对应某个平台的一个频道或群组
|
|
251
|
+
|
|
252
|
+
注意:当未配置\`cache\`时,跨平台删除、跨平台回复等功能将无法正常工作。
|
|
253
|
+
## 特性
|
|
254
|
+
- 可以配置多个 \`互通转发组\`,每个 \`互通转发组\` 之间相互独立
|
|
255
|
+
- 启用插件后,当一个 \`互通转发组\` 中的任意节点收到消息时,插件会自动将消息转发给**这个**\`互通转发组\`中的其他节点。
|
|
256
|
+
---`;
|
|
134
257
|
var reusable = true;
|
|
135
|
-
var
|
|
258
|
+
var inject = {
|
|
259
|
+
optional: ["cache"]
|
|
260
|
+
};
|
|
136
261
|
var Config = createConfig();
|
|
137
262
|
function apply(ctx, cfg) {
|
|
138
|
-
ctx.on("message", async (session) => {
|
|
263
|
+
ctx.on("message-created", async (session) => {
|
|
139
264
|
const hitGroup = [];
|
|
140
|
-
for (const g in cfg.
|
|
141
|
-
const group = cfg.
|
|
142
|
-
for (const k in group.
|
|
143
|
-
if (group.
|
|
265
|
+
for (const g in cfg.ForwardGroups) {
|
|
266
|
+
const group = cfg.ForwardGroups[g];
|
|
267
|
+
for (const k in group.Nodes) {
|
|
268
|
+
if (group.Nodes[k].Guild === session.channelId && group.Nodes[k].Platform === session.platform && group.Nodes[k].BotID !== session.userId) {
|
|
269
|
+
logger.debug(
|
|
270
|
+
"[message-created]",
|
|
271
|
+
session.channelId + ":" + session.messageId
|
|
272
|
+
);
|
|
273
|
+
let uuid = session.channelId + ":" + session.messageId;
|
|
274
|
+
msgCache(ctx, {
|
|
275
|
+
platform: session.platform,
|
|
276
|
+
bot: group.Nodes[k].BotID,
|
|
277
|
+
guild: session.channelId,
|
|
278
|
+
msgid: session.messageId,
|
|
279
|
+
uuid
|
|
280
|
+
});
|
|
144
281
|
hitGroup.push(g);
|
|
145
282
|
break;
|
|
146
283
|
}
|
|
147
284
|
}
|
|
148
285
|
}
|
|
149
286
|
for (const g in hitGroup) {
|
|
150
|
-
const group = cfg.
|
|
151
|
-
for (const k in group.
|
|
152
|
-
if (group.
|
|
153
|
-
MessageForward(ctx, group.
|
|
287
|
+
const group = cfg.ForwardGroups[hitGroup[g]];
|
|
288
|
+
for (const k in group.Nodes) {
|
|
289
|
+
if (group.Nodes[k].Guild !== session.channelId) {
|
|
290
|
+
MessageForward(ctx, group.Nodes[k], session);
|
|
154
291
|
}
|
|
155
292
|
}
|
|
156
293
|
}
|
|
157
294
|
});
|
|
295
|
+
ctx.on("message-deleted", async (session) => {
|
|
296
|
+
const cacheKey = session.channelId + ":" + session.messageId;
|
|
297
|
+
logger.debug("[message-deleted]", cacheKey);
|
|
298
|
+
msgCacheFindByKey(ctx, cacheKey).then((res) => {
|
|
299
|
+
if (res) {
|
|
300
|
+
logger.debug("[msgCacheFindByKey]", res);
|
|
301
|
+
msgCacheDelete(ctx, cacheKey);
|
|
302
|
+
const uuid = res.uuid;
|
|
303
|
+
msgCacheFindByUUID(ctx, uuid).then((res2) => {
|
|
304
|
+
if (res2) {
|
|
305
|
+
for (const k in res2) {
|
|
306
|
+
logger.debug("[message-delete]", res2[k][1]);
|
|
307
|
+
msgCacheDelete(ctx, res2[k][0]).then(() => {
|
|
308
|
+
MessageDelete(ctx, res2[k][1]);
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
});
|
|
316
|
+
ctx.on("message-updated", async (session) => {
|
|
317
|
+
logger.debug("[message-updated]", session.messageId, session);
|
|
318
|
+
});
|
|
158
319
|
}
|
|
159
320
|
__name(apply, "apply");
|
|
160
321
|
// Annotate the CommonJS export names for ESM import in node:
|
|
161
322
|
0 && (module.exports = {
|
|
162
323
|
Config,
|
|
163
324
|
apply,
|
|
325
|
+
inject,
|
|
326
|
+
name,
|
|
164
327
|
reusable,
|
|
165
328
|
usage
|
|
166
329
|
});
|
package/lib/message.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import { Context, Session } from "koishi";
|
|
2
2
|
import { ForwardNode } from "./config";
|
|
3
|
+
import { MsgCache } from "./cache";
|
|
3
4
|
export declare function MessageForward(ctx: Context, node: ForwardNode, session: Session): Promise<void>;
|
|
5
|
+
export declare function MessageDelete(ctx: Context, msg: MsgCache): Promise<void>;
|
|
6
|
+
export declare function MessageEdit(ctx: Context, node: ForwardNode, session: Session): Promise<void>;
|
package/package.json
CHANGED
|
@@ -1,73 +1,72 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "koishi-plugin-forward-hime",
|
|
3
|
-
"description": "多群组消息互通",
|
|
4
|
-
"version": "1.
|
|
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
|
-
"
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"plugin",
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"@typescript-eslint/
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"eslint": "^9.
|
|
43
|
-
"eslint-
|
|
44
|
-
"eslint-plugin-
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
"
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
"
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "koishi-plugin-forward-hime",
|
|
3
|
+
"description": "多群组消息互通",
|
|
4
|
+
"version": "1.2.1",
|
|
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.com/Nigh/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
|
+
}
|
package/readme.md
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
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
|
-
</div>
|
|
4
|
-
|
|
5
|
-
`Koishi` 多群组消息互通插件
|