koishi-plugin-forward-hime 1.0.0-preview.0 → 1.1.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/LICENSE +21 -21
- package/lib/config.d.ts +14 -0
- package/lib/decorator.d.ts +3 -0
- package/lib/decorators/kook.d.ts +5 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.js +166 -0
- package/lib/logger.d.ts +2 -0
- package/lib/message.d.ts +3 -0
- package/package.json +73 -64
- package/readme.md +5 -5
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024 xianii
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 xianii
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/lib/config.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Schema } from "koishi";
|
|
2
|
+
export interface ForwardNode {
|
|
3
|
+
Platform: string;
|
|
4
|
+
Guild: string;
|
|
5
|
+
BotID: string;
|
|
6
|
+
note?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface ConfigSet {
|
|
9
|
+
ChannelName_Setting: boolean;
|
|
10
|
+
Forward_Groups: {
|
|
11
|
+
Forward_Node: ForwardNode[];
|
|
12
|
+
}[];
|
|
13
|
+
}
|
|
14
|
+
export declare const createConfig: () => Schema<ConfigSet>;
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Context } from "koishi";
|
|
2
|
+
import { ConfigSet } from "./config";
|
|
3
|
+
export declare const reusable = true;
|
|
4
|
+
export declare const usage = "Test usage";
|
|
5
|
+
export declare const Config: import("schemastery")<ConfigSet>;
|
|
6
|
+
export declare function apply(ctx: Context, cfg: ConfigSet): void;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
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 name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], 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
|
+
reusable: () => reusable,
|
|
26
|
+
usage: () => usage
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(src_exports);
|
|
29
|
+
|
|
30
|
+
// src/config.ts
|
|
31
|
+
var import_koishi = require("koishi");
|
|
32
|
+
var createConfig = /* @__PURE__ */ __name(() => import_koishi.Schema.intersect([
|
|
33
|
+
import_koishi.Schema.object({
|
|
34
|
+
ChannelName_Setting: import_koishi.Schema.boolean().description("是否包含频道名称").default(false)
|
|
35
|
+
}).description("转发格式"),
|
|
36
|
+
import_koishi.Schema.object({
|
|
37
|
+
Forward_Groups: import_koishi.Schema.array(
|
|
38
|
+
import_koishi.Schema.object({
|
|
39
|
+
Forward_Node: import_koishi.Schema.array(
|
|
40
|
+
import_koishi.Schema.object({
|
|
41
|
+
Platform: import_koishi.Schema.union([
|
|
42
|
+
"telegram",
|
|
43
|
+
"discord",
|
|
44
|
+
"onebot",
|
|
45
|
+
"kook",
|
|
46
|
+
"slack",
|
|
47
|
+
"qq"
|
|
48
|
+
]).role("select").required().description("平台"),
|
|
49
|
+
Guild: import_koishi.Schema.string().required().description("频道ID"),
|
|
50
|
+
BotID: import_koishi.Schema.string().required().description("机器人ID"),
|
|
51
|
+
note: import_koishi.Schema.string().description("备注")
|
|
52
|
+
})
|
|
53
|
+
).role("table").description("配置转发节点")
|
|
54
|
+
})
|
|
55
|
+
).description("互通转发组")
|
|
56
|
+
})
|
|
57
|
+
]), "createConfig");
|
|
58
|
+
|
|
59
|
+
// src/logger.ts
|
|
60
|
+
var import_koishi2 = require("koishi");
|
|
61
|
+
var logger = new import_koishi2.Logger("forward-hime");
|
|
62
|
+
|
|
63
|
+
// src/decorator.ts
|
|
64
|
+
var import_koishi4 = require("koishi");
|
|
65
|
+
|
|
66
|
+
// src/decorators/kook.ts
|
|
67
|
+
var import_koishi3 = require("koishi");
|
|
68
|
+
var import_buffer = require("buffer");
|
|
69
|
+
var transparentPixel = import_buffer.Buffer.from(
|
|
70
|
+
"R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==",
|
|
71
|
+
"base64"
|
|
72
|
+
);
|
|
73
|
+
function kook({ head, content }) {
|
|
74
|
+
let msg = [];
|
|
75
|
+
msg = msg.concat(head, (0, import_koishi3.h)("br"), content, import_koishi3.h.image(transparentPixel, "image/gif"));
|
|
76
|
+
return msg;
|
|
77
|
+
}
|
|
78
|
+
__name(kook, "kook");
|
|
79
|
+
|
|
80
|
+
// src/decorator.ts
|
|
81
|
+
var decorators = {
|
|
82
|
+
kook
|
|
83
|
+
};
|
|
84
|
+
function defaultDeco({ head, content }) {
|
|
85
|
+
let msg = [];
|
|
86
|
+
msg = msg.concat(head, (0, import_koishi4.h)("br"), content);
|
|
87
|
+
return msg;
|
|
88
|
+
}
|
|
89
|
+
__name(defaultDeco, "defaultDeco");
|
|
90
|
+
function defaultMiddleware(session) {
|
|
91
|
+
let head = [
|
|
92
|
+
(0, import_koishi4.h)("b", `${session.author.name}`),
|
|
93
|
+
(0, import_koishi4.h)("span", " 转发自 "),
|
|
94
|
+
(0, import_koishi4.h)("i", `${session.platform}`),
|
|
95
|
+
(0, import_koishi4.h)("span", `:`)
|
|
96
|
+
];
|
|
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
|
+
return { head, content: session.elements };
|
|
105
|
+
}
|
|
106
|
+
__name(defaultMiddleware, "defaultMiddleware");
|
|
107
|
+
function MsgDecorator(session, node) {
|
|
108
|
+
const fw = defaultMiddleware(session);
|
|
109
|
+
if (typeof decorators[node.Platform] === "function") {
|
|
110
|
+
return decorators[node.Platform](fw);
|
|
111
|
+
} else {
|
|
112
|
+
return defaultDeco(fw);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
__name(MsgDecorator, "MsgDecorator");
|
|
116
|
+
|
|
117
|
+
// src/message.ts
|
|
118
|
+
async function MessageForward(ctx, node, session) {
|
|
119
|
+
try {
|
|
120
|
+
if (ctx.bots[`${node.Platform}:${node.BotID}`] == void 0) {
|
|
121
|
+
throw new Error("Bot Not Found");
|
|
122
|
+
}
|
|
123
|
+
await ctx.bots[`${node.Platform}:${node.BotID}`].sendMessage(
|
|
124
|
+
node.Guild,
|
|
125
|
+
MsgDecorator(session, node)
|
|
126
|
+
);
|
|
127
|
+
} catch (error) {
|
|
128
|
+
logger.error(`ERROR:<MessageSend> ${error}`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
__name(MessageForward, "MessageForward");
|
|
132
|
+
|
|
133
|
+
// src/index.ts
|
|
134
|
+
var reusable = true;
|
|
135
|
+
var usage = `Test usage`;
|
|
136
|
+
var Config = createConfig();
|
|
137
|
+
function apply(ctx, cfg) {
|
|
138
|
+
ctx.on("message", async (session) => {
|
|
139
|
+
const hitGroup = [];
|
|
140
|
+
for (const g in cfg.Forward_Groups) {
|
|
141
|
+
const group = cfg.Forward_Groups[g];
|
|
142
|
+
for (const k in group.Forward_Node) {
|
|
143
|
+
if (group.Forward_Node[k].Guild === session.channelId && group.Forward_Node[k].Platform === session.platform && group.Forward_Node[k].BotID !== session.userId) {
|
|
144
|
+
hitGroup.push(g);
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
for (const g in hitGroup) {
|
|
150
|
+
const group = cfg.Forward_Groups[hitGroup[g]];
|
|
151
|
+
for (const k in group.Forward_Node) {
|
|
152
|
+
if (group.Forward_Node[k].Guild !== session.channelId) {
|
|
153
|
+
MessageForward(ctx, group.Forward_Node[k], session);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
__name(apply, "apply");
|
|
160
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
161
|
+
0 && (module.exports = {
|
|
162
|
+
Config,
|
|
163
|
+
apply,
|
|
164
|
+
reusable,
|
|
165
|
+
usage
|
|
166
|
+
});
|
package/lib/logger.d.ts
ADDED
package/lib/message.d.ts
ADDED
package/package.json
CHANGED
|
@@ -1,64 +1,73 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "koishi-plugin-forward-hime",
|
|
3
|
-
"description": "多群组消息互通",
|
|
4
|
-
"version": "1.
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"url": "https://github.com/Nigh/forward-hime
|
|
23
|
-
},
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
"
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"eslint-plugin
|
|
40
|
-
"eslint
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"prettier": "^
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
"
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "koishi-plugin-forward-hime",
|
|
3
|
+
"description": "多群组消息互通",
|
|
4
|
+
"version": "1.1.0",
|
|
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
|
+
"preview": true,
|
|
16
|
+
"browser": true
|
|
17
|
+
},
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"homepage": "https://github.com/Nigh/forward-hime",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/Nigh/forward-hime.git"
|
|
23
|
+
},
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/Nigh/forward-hime/issues"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"chatbot",
|
|
29
|
+
"koishi",
|
|
30
|
+
"plugin",
|
|
31
|
+
"koishi-plugin",
|
|
32
|
+
"forward",
|
|
33
|
+
"message-forwarding"
|
|
34
|
+
],
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"koishi": "^4.17.8"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@typescript-eslint/eslint-plugin": "^7.13.0",
|
|
40
|
+
"@typescript-eslint/parser": "^7.13.0",
|
|
41
|
+
"atsc": "^2.1.0",
|
|
42
|
+
"eslint": "^9.4.0",
|
|
43
|
+
"eslint-config-prettier": "^9.1.0",
|
|
44
|
+
"eslint-plugin-prettier": "^5.1.3",
|
|
45
|
+
"eslint-plugin-unused-imports": "^4.0.0",
|
|
46
|
+
"husky": "^9.0.11",
|
|
47
|
+
"lint-staged": "^15.2.7",
|
|
48
|
+
"prettier": "^3.3.2",
|
|
49
|
+
"typescript": "^5.4.5"
|
|
50
|
+
},
|
|
51
|
+
"scripts": {
|
|
52
|
+
"prepare": "husky",
|
|
53
|
+
"build": "atsc -b",
|
|
54
|
+
"eslint": "eslint . --ext .js,.jsx,.ts,.tsx",
|
|
55
|
+
"format": "prettier --write .",
|
|
56
|
+
"pub": "npm publish --access public"
|
|
57
|
+
},
|
|
58
|
+
"husky": {
|
|
59
|
+
"hooks": {
|
|
60
|
+
"pre-commit": "lint-staged"
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
"lint-staged": {
|
|
64
|
+
"*.{js,jsx,ts,tsx,json,css,scss,md}": [
|
|
65
|
+
"eslint --fix",
|
|
66
|
+
"prettier --write"
|
|
67
|
+
]
|
|
68
|
+
},
|
|
69
|
+
"publishConfig": {
|
|
70
|
+
"registry": "https://registry.npmjs.org/",
|
|
71
|
+
"access": "public"
|
|
72
|
+
}
|
|
73
|
+
}
|
package/readme.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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` 多群组消息互通插件
|
|
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` 多群组消息互通插件
|