koishi-plugin-forward-hime 1.1.0 → 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.
- package/README.md +26 -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 +2 -1
- package/lib/index.js +115 -51
- package/package.json +1 -1
- 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/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,7 @@
|
|
|
1
1
|
import { Context } from "koishi";
|
|
2
2
|
import { ConfigSet } from "./config";
|
|
3
3
|
export declare const reusable = true;
|
|
4
|
-
export declare const
|
|
4
|
+
export declare const name = "forward hime - \u8F6C\u53D1\u59EC";
|
|
5
|
+
export declare const usage = "\n# forward hime - \u8F6C\u53D1\u59EC <sub>v1.2.0</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## \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---";
|
|
5
6
|
export declare const Config: import("schemastery")<ConfigSet>;
|
|
6
7
|
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,7 @@ var src_exports = {};
|
|
|
22
22
|
__export(src_exports, {
|
|
23
23
|
Config: () => Config,
|
|
24
24
|
apply: () => apply,
|
|
25
|
+
name: () => name,
|
|
25
26
|
reusable: () => reusable,
|
|
26
27
|
usage: () => usage
|
|
27
28
|
});
|
|
@@ -31,29 +32,23 @@ module.exports = __toCommonJS(src_exports);
|
|
|
31
32
|
var import_koishi = require("koishi");
|
|
32
33
|
var createConfig = /* @__PURE__ */ __name(() => import_koishi.Schema.intersect([
|
|
33
34
|
import_koishi.Schema.object({
|
|
34
|
-
|
|
35
|
+
WithChannelName: import_koishi.Schema.boolean().description("是否包含频道名称").default(false),
|
|
36
|
+
WithPlatformName: import_koishi.Schema.boolean().description("是否包含平台名称").default(true)
|
|
35
37
|
}).description("转发格式"),
|
|
36
38
|
import_koishi.Schema.object({
|
|
37
|
-
|
|
39
|
+
ForwardGroups: import_koishi.Schema.array(
|
|
38
40
|
import_koishi.Schema.object({
|
|
39
|
-
|
|
41
|
+
Note: import_koishi.Schema.string().description("互通组备注"),
|
|
42
|
+
Nodes: import_koishi.Schema.array(
|
|
40
43
|
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("平台"),
|
|
44
|
+
Platform: import_koishi.Schema.string().role("").required().description("平台"),
|
|
49
45
|
Guild: import_koishi.Schema.string().required().description("频道ID"),
|
|
50
|
-
BotID: import_koishi.Schema.string().required().description("机器人ID")
|
|
51
|
-
note: import_koishi.Schema.string().description("备注")
|
|
46
|
+
BotID: import_koishi.Schema.string().required().description("机器人ID")
|
|
52
47
|
})
|
|
53
|
-
).role("table").description("
|
|
48
|
+
).role("table").description("转发节点")
|
|
54
49
|
})
|
|
55
50
|
).description("互通转发组")
|
|
56
|
-
})
|
|
51
|
+
}).description("互通组")
|
|
57
52
|
]), "createConfig");
|
|
58
53
|
|
|
59
54
|
// src/logger.ts
|
|
@@ -61,7 +56,14 @@ var import_koishi2 = require("koishi");
|
|
|
61
56
|
var logger = new import_koishi2.Logger("forward-hime");
|
|
62
57
|
|
|
63
58
|
// src/decorator.ts
|
|
64
|
-
var
|
|
59
|
+
var import_koishi5 = require("koishi");
|
|
60
|
+
|
|
61
|
+
// src/decorators/index.ts
|
|
62
|
+
var decorators_exports = {};
|
|
63
|
+
__export(decorators_exports, {
|
|
64
|
+
kook: () => kook_default,
|
|
65
|
+
onebot: () => onebot_default
|
|
66
|
+
});
|
|
65
67
|
|
|
66
68
|
// src/decorators/kook.ts
|
|
67
69
|
var import_koishi3 = require("koishi");
|
|
@@ -70,49 +72,89 @@ var transparentPixel = import_buffer.Buffer.from(
|
|
|
70
72
|
"R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==",
|
|
71
73
|
"base64"
|
|
72
74
|
);
|
|
73
|
-
function
|
|
75
|
+
function Decorator({ head, content }) {
|
|
74
76
|
let msg = [];
|
|
75
77
|
msg = msg.concat(head, (0, import_koishi3.h)("br"), content, import_koishi3.h.image(transparentPixel, "image/gif"));
|
|
76
78
|
return msg;
|
|
77
79
|
}
|
|
78
|
-
__name(
|
|
80
|
+
__name(Decorator, "Decorator");
|
|
81
|
+
var kook_default = {
|
|
82
|
+
Decorator
|
|
83
|
+
};
|
|
79
84
|
|
|
80
|
-
// src/
|
|
81
|
-
var
|
|
82
|
-
|
|
85
|
+
// src/decorators/onebot.ts
|
|
86
|
+
var import_koishi4 = require("koishi");
|
|
87
|
+
function Middleware(session) {
|
|
88
|
+
const platform = guessPlatform(session);
|
|
89
|
+
let head = [
|
|
90
|
+
(0, import_koishi4.h)("b", `${session.username}`),
|
|
91
|
+
(0, import_koishi4.h)("span", " 转发自 "),
|
|
92
|
+
(0, import_koishi4.h)("i", `${platform}`),
|
|
93
|
+
(0, import_koishi4.h)("span", `:`)
|
|
94
|
+
];
|
|
95
|
+
return { head, content: session.elements };
|
|
96
|
+
}
|
|
97
|
+
__name(Middleware, "Middleware");
|
|
98
|
+
function guessPlatform(session) {
|
|
99
|
+
if (session.event.user && session.event.user.avatar) {
|
|
100
|
+
if (session.event.user.avatar.includes("q.qlogo.cn")) {
|
|
101
|
+
return "QQ";
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return session.platform;
|
|
105
|
+
}
|
|
106
|
+
__name(guessPlatform, "guessPlatform");
|
|
107
|
+
var onebot_default = {
|
|
108
|
+
Middleware
|
|
83
109
|
};
|
|
84
|
-
|
|
110
|
+
|
|
111
|
+
// src/decorator.ts
|
|
112
|
+
function defaultDecorator({ head, content }) {
|
|
85
113
|
let msg = [];
|
|
86
|
-
msg = msg.concat(head, (0,
|
|
114
|
+
msg = msg.concat(head, (0, import_koishi5.h)("br"), content);
|
|
87
115
|
return msg;
|
|
88
116
|
}
|
|
89
|
-
__name(
|
|
117
|
+
__name(defaultDecorator, "defaultDecorator");
|
|
90
118
|
function defaultMiddleware(session) {
|
|
91
119
|
let head = [
|
|
92
|
-
(0,
|
|
93
|
-
(0,
|
|
94
|
-
(0,
|
|
95
|
-
(0,
|
|
120
|
+
(0, import_koishi5.h)("b", `${session.username}`),
|
|
121
|
+
(0, import_koishi5.h)("span", " 转发自 "),
|
|
122
|
+
(0, import_koishi5.h)("i", `${session.platform}`),
|
|
123
|
+
(0, import_koishi5.h)("span", `:`)
|
|
96
124
|
];
|
|
97
|
-
for (const key in session.elements) {
|
|
98
|
-
const element = session.elements[key];
|
|
99
|
-
if (element.type === "at") {
|
|
100
|
-
logger.info(element);
|
|
101
|
-
session.elements[key] = (0, import_koishi4.h)("span", `@${element.attrs.name}`);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
125
|
return { head, content: session.elements };
|
|
105
126
|
}
|
|
106
127
|
__name(defaultMiddleware, "defaultMiddleware");
|
|
128
|
+
var localDecorators = [at2Name];
|
|
107
129
|
function MsgDecorator(session, node) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
130
|
+
let elems;
|
|
131
|
+
let _platform_in = decorators_exports[session.platform];
|
|
132
|
+
let _platform_out = decorators_exports[node.Platform];
|
|
133
|
+
if (_platform_in && typeof _platform_in.Middleware === "function") {
|
|
134
|
+
elems = _platform_in.Middleware(session);
|
|
111
135
|
} else {
|
|
112
|
-
|
|
136
|
+
elems = defaultMiddleware(session);
|
|
137
|
+
}
|
|
138
|
+
localDecorators.forEach((fn) => {
|
|
139
|
+
elems = fn(elems);
|
|
140
|
+
});
|
|
141
|
+
if (_platform_out && typeof _platform_out.Decorator === "function") {
|
|
142
|
+
return _platform_out.Decorator(elems);
|
|
143
|
+
} else {
|
|
144
|
+
return defaultDecorator(elems);
|
|
113
145
|
}
|
|
114
146
|
}
|
|
115
147
|
__name(MsgDecorator, "MsgDecorator");
|
|
148
|
+
function at2Name({ head, content }) {
|
|
149
|
+
for (const key in content) {
|
|
150
|
+
const element = content[key];
|
|
151
|
+
if (element.type === "at") {
|
|
152
|
+
content[key] = (0, import_koishi5.h)("span", `@${element.attrs.name || element.attrs.id}`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return { head, content };
|
|
156
|
+
}
|
|
157
|
+
__name(at2Name, "at2Name");
|
|
116
158
|
|
|
117
159
|
// src/message.ts
|
|
118
160
|
async function MessageForward(ctx, node, session) {
|
|
@@ -132,35 +174,57 @@ __name(MessageForward, "MessageForward");
|
|
|
132
174
|
|
|
133
175
|
// src/index.ts
|
|
134
176
|
var reusable = true;
|
|
135
|
-
var
|
|
177
|
+
var name = `forward hime - 转发姬`;
|
|
178
|
+
var version = `<sub>v1.2.0</sub>`;
|
|
179
|
+
var usage = `
|
|
180
|
+
# ${name} ${version}
|
|
181
|
+
## 配置说明
|
|
182
|
+
1. 添加 \`互通转发组\`
|
|
183
|
+
2. 为添加的 \`互通转发组\` 配置转发节点。每个转发节点对应某个平台的一个频道或群组
|
|
184
|
+
## 特性
|
|
185
|
+
- 可以配置多个 \`互通转发组\`,每个 \`互通转发组\` 之间相互独立
|
|
186
|
+
- 启用插件后,当一个 \`互通转发组\` 中的任意节点收到消息时,插件会自动将消息转发给**这个**\`互通转发组\`中的其他节点。
|
|
187
|
+
---`;
|
|
136
188
|
var Config = createConfig();
|
|
137
189
|
function apply(ctx, cfg) {
|
|
138
|
-
ctx.on("message", async (session) => {
|
|
190
|
+
ctx.on("message-created", async (session) => {
|
|
139
191
|
const hitGroup = [];
|
|
140
|
-
for (const g in cfg.
|
|
141
|
-
const group = cfg.
|
|
142
|
-
for (const k in group.
|
|
143
|
-
if (group.
|
|
192
|
+
for (const g in cfg.ForwardGroups) {
|
|
193
|
+
const group = cfg.ForwardGroups[g];
|
|
194
|
+
for (const k in group.Nodes) {
|
|
195
|
+
if (group.Nodes[k].Guild === session.channelId && group.Nodes[k].Platform === session.platform && group.Nodes[k].BotID !== session.userId) {
|
|
196
|
+
logger.debug(
|
|
197
|
+
"[message-created]",
|
|
198
|
+
session.messageId,
|
|
199
|
+
session.elements
|
|
200
|
+
);
|
|
144
201
|
hitGroup.push(g);
|
|
145
202
|
break;
|
|
146
203
|
}
|
|
147
204
|
}
|
|
148
205
|
}
|
|
149
206
|
for (const g in hitGroup) {
|
|
150
|
-
const group = cfg.
|
|
151
|
-
for (const k in group.
|
|
152
|
-
if (group.
|
|
153
|
-
MessageForward(ctx, group.
|
|
207
|
+
const group = cfg.ForwardGroups[hitGroup[g]];
|
|
208
|
+
for (const k in group.Nodes) {
|
|
209
|
+
if (group.Nodes[k].Guild !== session.channelId) {
|
|
210
|
+
MessageForward(ctx, group.Nodes[k], session);
|
|
154
211
|
}
|
|
155
212
|
}
|
|
156
213
|
}
|
|
157
214
|
});
|
|
215
|
+
ctx.on("message-deleted", async (session) => {
|
|
216
|
+
logger.debug("[message-deleted]", session.messageId);
|
|
217
|
+
});
|
|
218
|
+
ctx.on("message-updated", async (session) => {
|
|
219
|
+
logger.debug("[message-updated]", session.messageId, session);
|
|
220
|
+
});
|
|
158
221
|
}
|
|
159
222
|
__name(apply, "apply");
|
|
160
223
|
// Annotate the CommonJS export names for ESM import in node:
|
|
161
224
|
0 && (module.exports = {
|
|
162
225
|
Config,
|
|
163
226
|
apply,
|
|
227
|
+
name,
|
|
164
228
|
reusable,
|
|
165
229
|
usage
|
|
166
230
|
});
|
package/package.json
CHANGED
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` 多群组消息互通插件
|