koishi-plugin-forward-hime 1.0.0-beta.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 -0
- package/lib/config.d.ts +14 -0
- package/lib/config.js +30 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.js +70 -0
- package/lib/logger.d.ts +2 -0
- package/lib/logger.js +2 -0
- package/lib/message.d.ts +3 -0
- package/lib/message.js +21 -0
- package/package.json +70 -0
- package/readme.md +5 -0
package/LICENSE
ADDED
|
@@ -0,0 +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.
|
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/config.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Schema } from "koishi";
|
|
2
|
+
export const createConfig = () => Schema.intersect([
|
|
3
|
+
Schema.object({
|
|
4
|
+
ChannelName_Setting: Schema.boolean()
|
|
5
|
+
.description("是否包含频道名称")
|
|
6
|
+
.default(false),
|
|
7
|
+
}).description("转发格式"),
|
|
8
|
+
Schema.object({
|
|
9
|
+
Forward_Groups: Schema.array(Schema.object({
|
|
10
|
+
Forward_Node: Schema.array(Schema.object({
|
|
11
|
+
Platform: Schema.union([
|
|
12
|
+
"telegram",
|
|
13
|
+
"discord",
|
|
14
|
+
"onebot",
|
|
15
|
+
"kook",
|
|
16
|
+
"slack",
|
|
17
|
+
"qq",
|
|
18
|
+
])
|
|
19
|
+
.role("select")
|
|
20
|
+
.required()
|
|
21
|
+
.description("平台"),
|
|
22
|
+
Guild: Schema.string().required().description("频道ID"),
|
|
23
|
+
BotID: Schema.string().required().description("机器人ID"),
|
|
24
|
+
note: Schema.string().description("备注"),
|
|
25
|
+
}))
|
|
26
|
+
.role("table")
|
|
27
|
+
.description("配置转发节点"),
|
|
28
|
+
})).description("互通转发组"),
|
|
29
|
+
}),
|
|
30
|
+
]);
|
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,70 @@
|
|
|
1
|
+
// import {} from "@koishijs/cache";
|
|
2
|
+
import { createConfig } from "./config";
|
|
3
|
+
// import {logger} from "./logger";
|
|
4
|
+
import { MessageForward } from "./message";
|
|
5
|
+
export const reusable = true;
|
|
6
|
+
// export const inject = {
|
|
7
|
+
// optional: ["cache"],
|
|
8
|
+
// };
|
|
9
|
+
export const usage = `Test usage`;
|
|
10
|
+
export const Config = createConfig();
|
|
11
|
+
// declare module "@koishijs/cache" {
|
|
12
|
+
// interface Tables {
|
|
13
|
+
// mpmf_message: string;
|
|
14
|
+
// mpmf_unity: string[];
|
|
15
|
+
// }
|
|
16
|
+
// }
|
|
17
|
+
export function apply(ctx, cfg) {
|
|
18
|
+
// if (ctx.cache) {
|
|
19
|
+
// var cachechannel: string[] = [];
|
|
20
|
+
// cfg.Forward_Groups.forEach((channels) => {
|
|
21
|
+
// channels.Forward_Node.forEach((channel) => {
|
|
22
|
+
// cachechannel.push(channel.Guild);
|
|
23
|
+
// });
|
|
24
|
+
// });
|
|
25
|
+
// }
|
|
26
|
+
// let pass = [];
|
|
27
|
+
// ctx.command("TemporaryExclusion <time>", "临时排除转发功能(time单位:毫秒)", {
|
|
28
|
+
// authority: 3,
|
|
29
|
+
// }).action(({session}, time) => {
|
|
30
|
+
// pass.push(session.channelId);
|
|
31
|
+
// let time_num = parseInt(time);
|
|
32
|
+
// ctx.setTimeout(() => {
|
|
33
|
+
// pass.splice(pass.indexOf(session.channelId), 1);
|
|
34
|
+
// session.send(`已恢复转发功能`);
|
|
35
|
+
// }, time_num);
|
|
36
|
+
// session.send(`已临时排除此频道转发功能${time_num}毫秒`);
|
|
37
|
+
// });
|
|
38
|
+
// ctx.command("CancelTE", "取消临时排除转发功能", {authority: 3}).action(
|
|
39
|
+
// ({session}) => {
|
|
40
|
+
// if (pass.includes(session.channelId)) {
|
|
41
|
+
// pass.splice(pass.indexOf(session.channelId), 1);
|
|
42
|
+
// session.send("已恢复转发功能");
|
|
43
|
+
// } else if (!pass.includes(session.channelId)) {
|
|
44
|
+
// session.send("此频道未排除转发");
|
|
45
|
+
// }
|
|
46
|
+
// },
|
|
47
|
+
// );
|
|
48
|
+
ctx.on("message", async (session) => {
|
|
49
|
+
const hitGroup = [];
|
|
50
|
+
for (const g in cfg.Forward_Groups) {
|
|
51
|
+
const group = cfg.Forward_Groups[g];
|
|
52
|
+
for (const k in group.Forward_Node) {
|
|
53
|
+
if (group.Forward_Node[k].Guild === session.channelId &&
|
|
54
|
+
group.Forward_Node[k].Platform === session.platform &&
|
|
55
|
+
group.Forward_Node[k].BotID !== session.userId) {
|
|
56
|
+
hitGroup.push(g);
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
for (const g in hitGroup) {
|
|
62
|
+
const group = cfg.Forward_Groups[hitGroup[g]];
|
|
63
|
+
for (const k in group.Forward_Node) {
|
|
64
|
+
if (group.Forward_Node[k].Guild !== session.channelId) {
|
|
65
|
+
MessageForward(ctx, group.Forward_Node[k], session);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
package/lib/logger.d.ts
ADDED
package/lib/logger.js
ADDED
package/lib/message.d.ts
ADDED
package/lib/message.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { logger } from "./logger";
|
|
2
|
+
function getUserName(Session) {
|
|
3
|
+
return Session.author.name;
|
|
4
|
+
}
|
|
5
|
+
function getPlatform(Session) {
|
|
6
|
+
return Session.platform;
|
|
7
|
+
}
|
|
8
|
+
// TODO: 临时装饰器
|
|
9
|
+
function msgDecorator(Session) {
|
|
10
|
+
const msg = `<b>${getUserName(Session)}</b> 转发自 <i>${getPlatform(Session)}</i>:<br/>${Session.content}`;
|
|
11
|
+
return msg;
|
|
12
|
+
}
|
|
13
|
+
export async function MessageForward(ctx, Node, Session) {
|
|
14
|
+
try {
|
|
15
|
+
// TODO: 增加统一装饰器于平台装饰器
|
|
16
|
+
await ctx.bots[`${Node.Platform}:${Node.BotID}`].sendMessage(Node.Guild, msgDecorator(Session));
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
logger.error(`ERROR:<MessageSend> ${error}`);
|
|
20
|
+
}
|
|
21
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "koishi-plugin-forward-hime",
|
|
3
|
+
"description": "多群组消息互通",
|
|
4
|
+
"version": "1.0.0-beta.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
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"koishi": {
|
|
16
|
+
"preview": true,
|
|
17
|
+
"browser": true
|
|
18
|
+
},
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"homepage": "https://github.com/Nigh/forward-hime",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/Nigh/forward-hime.git"
|
|
24
|
+
},
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/Nigh/forward-hime/issues"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"chatbot",
|
|
30
|
+
"koishi",
|
|
31
|
+
"plugin",
|
|
32
|
+
"koishi-plugin",
|
|
33
|
+
"forward",
|
|
34
|
+
"message-forwarding"
|
|
35
|
+
],
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"koishi": "^4.17.8"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@typescript-eslint/eslint-plugin": "^7.13.0",
|
|
41
|
+
"@typescript-eslint/parser": "^7.13.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
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"prepare": "husky",
|
|
52
|
+
"eslint": "eslint . --ext .js,.jsx,.ts,.tsx",
|
|
53
|
+
"format": "prettier --write ."
|
|
54
|
+
},
|
|
55
|
+
"husky": {
|
|
56
|
+
"hooks": {
|
|
57
|
+
"pre-commit": "lint-staged"
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
"lint-staged": {
|
|
61
|
+
"*.{js,jsx,ts,tsx,json,css,scss,md}": [
|
|
62
|
+
"eslint --fix",
|
|
63
|
+
"prettier --write"
|
|
64
|
+
]
|
|
65
|
+
},
|
|
66
|
+
"publishConfig": {
|
|
67
|
+
"registry": "https://registry.npmjs.org/",
|
|
68
|
+
"access": "public"
|
|
69
|
+
}
|
|
70
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +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` 多群组消息互通插件
|