koishi-plugin-fake-message 1.0.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/lib/index.d.ts +9 -0
- package/lib/index.js +138 -0
- package/package.json +28 -0
- package/readme.md +44 -0
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Context, Schema } from 'koishi';
|
|
2
|
+
export declare const name = "fake-message";
|
|
3
|
+
export interface Config {
|
|
4
|
+
userSplit: string;
|
|
5
|
+
messageSplit: string;
|
|
6
|
+
blockedUsers: string[];
|
|
7
|
+
}
|
|
8
|
+
export declare const Config: Schema<Config>;
|
|
9
|
+
export declare function apply(ctx: Context, config: Config): void;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
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
|
+
name: () => name
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(src_exports);
|
|
28
|
+
var import_koishi = require("koishi");
|
|
29
|
+
var name = "fake-message";
|
|
30
|
+
var Config = import_koishi.Schema.object({
|
|
31
|
+
userSplit: import_koishi.Schema.string().default("|").description("用户消息分隔符"),
|
|
32
|
+
messageSplit: import_koishi.Schema.string().default(" ").description("同一用户多条消息分隔符"),
|
|
33
|
+
blockedUsers: import_koishi.Schema.array(import_koishi.Schema.string()).default([]).description("被屏蔽的QQ号列表,这些QQ号将无法被伪造消息")
|
|
34
|
+
});
|
|
35
|
+
var fakeMsgRegex = /^\d{6,10}说/;
|
|
36
|
+
function apply(ctx, config) {
|
|
37
|
+
ctx.using(["help"], (ctx2) => {
|
|
38
|
+
ctx2.command("fakemsg").action(() => [
|
|
39
|
+
"消息伪造插件",
|
|
40
|
+
"用法:【QQ号】说【内容】|【QQ号】说【内容】",
|
|
41
|
+
"示例:123456说你好|654321说早上好",
|
|
42
|
+
"注意:被屏蔽的QQ号将无法被伪造消息"
|
|
43
|
+
].join("\n"));
|
|
44
|
+
});
|
|
45
|
+
const checkIfFakeMsg = /* @__PURE__ */ __name((content) => {
|
|
46
|
+
return fakeMsgRegex.test(content);
|
|
47
|
+
}, "checkIfFakeMsg");
|
|
48
|
+
const isUserBlocked = /* @__PURE__ */ __name((userId) => {
|
|
49
|
+
return config.blockedUsers.includes(userId);
|
|
50
|
+
}, "isUserBlocked");
|
|
51
|
+
ctx.middleware(async (session, next) => {
|
|
52
|
+
const content = session.content;
|
|
53
|
+
if (!checkIfFakeMsg(content)) {
|
|
54
|
+
return next();
|
|
55
|
+
}
|
|
56
|
+
await session.send("正在伪造消息……");
|
|
57
|
+
try {
|
|
58
|
+
const fakeMessages = [];
|
|
59
|
+
const userMessages = content.split(config.userSplit);
|
|
60
|
+
for (const userMsg of userMessages) {
|
|
61
|
+
const trimmedMsg = userMsg.trim();
|
|
62
|
+
if (!trimmedMsg || !trimmedMsg.includes("说")) continue;
|
|
63
|
+
const [userQQ, message] = trimmedMsg.split("说", 2);
|
|
64
|
+
if (!userQQ || !message) continue;
|
|
65
|
+
if (isUserBlocked(userQQ)) {
|
|
66
|
+
await session.send(`QQ号 ${userQQ} 已被屏蔽,无法伪造该用户的消息`);
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
try {
|
|
70
|
+
const userInfo = await session.bot.getUser(userQQ);
|
|
71
|
+
const userName = userInfo?.name || userQQ;
|
|
72
|
+
const messages = message.split(config.messageSplit);
|
|
73
|
+
for (const msg of messages) {
|
|
74
|
+
if (msg.trim()) {
|
|
75
|
+
fakeMessages.push({
|
|
76
|
+
userId: userQQ,
|
|
77
|
+
nickname: userName,
|
|
78
|
+
content: msg.trim()
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
} catch (e) {
|
|
83
|
+
console.error(`获取用户 ${userQQ} 信息失败:`, e);
|
|
84
|
+
const messages = message.split(config.messageSplit);
|
|
85
|
+
for (const msg of messages) {
|
|
86
|
+
if (msg.trim()) {
|
|
87
|
+
fakeMessages.push({
|
|
88
|
+
userId: userQQ,
|
|
89
|
+
nickname: userQQ,
|
|
90
|
+
content: msg.trim()
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (fakeMessages.length > 0) {
|
|
97
|
+
await sendForwardMessage(session, fakeMessages);
|
|
98
|
+
} else {
|
|
99
|
+
await session.send("消息格式错误,请检查后重试");
|
|
100
|
+
}
|
|
101
|
+
} catch (e) {
|
|
102
|
+
console.error("伪造消息失败:", e);
|
|
103
|
+
await session.send(`发送失败: ${e.message || "未知错误"}`);
|
|
104
|
+
}
|
|
105
|
+
return;
|
|
106
|
+
});
|
|
107
|
+
async function sendForwardMessage(session, messages) {
|
|
108
|
+
try {
|
|
109
|
+
const nodes = messages.map((msg) => ({
|
|
110
|
+
type: "node",
|
|
111
|
+
data: {
|
|
112
|
+
name: msg.nickname,
|
|
113
|
+
uin: msg.userId,
|
|
114
|
+
content: msg.content
|
|
115
|
+
}
|
|
116
|
+
}));
|
|
117
|
+
if (session.subtype === "group") {
|
|
118
|
+
await session.bot.internal.sendGroupForwardMsg(session.guildId, nodes);
|
|
119
|
+
} else {
|
|
120
|
+
await session.bot.internal.sendPrivateForwardMsg(session.userId, nodes);
|
|
121
|
+
}
|
|
122
|
+
} catch (e) {
|
|
123
|
+
console.error("发送合并转发消息失败:", e);
|
|
124
|
+
await session.send("合并转发失败,将逐条发送消息");
|
|
125
|
+
for (const msg of messages) {
|
|
126
|
+
await session.send(`${msg.nickname}:${msg.content}`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
__name(sendForwardMessage, "sendForwardMessage");
|
|
131
|
+
}
|
|
132
|
+
__name(apply, "apply");
|
|
133
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
134
|
+
0 && (module.exports = {
|
|
135
|
+
Config,
|
|
136
|
+
apply,
|
|
137
|
+
name
|
|
138
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "koishi-plugin-fake-message",
|
|
3
|
+
"description": "伪造消息,可用于恶搞群友或好友",
|
|
4
|
+
"version": "1.0.1",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"typings": "lib/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"lib",
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsc"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"chatbot",
|
|
17
|
+
"koishi",
|
|
18
|
+
"plugin",
|
|
19
|
+
"fake-message",
|
|
20
|
+
"forward-message"
|
|
21
|
+
],
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"typescript": "^5.0.0"
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"koishi": "^4.18.7"
|
|
27
|
+
}
|
|
28
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# koishi-plugin-fake-message
|
|
2
|
+
|
|
3
|
+
一个用于伪造消息的 Koishi 插件,移植自 [nonebot-plugin-fakemsg](https://github.com/Cvandia/nonebot-plugin-fakemsg)。
|
|
4
|
+
|
|
5
|
+
## 功能介绍
|
|
6
|
+
|
|
7
|
+
本插件可以伪造任意用户的消息,形成一个合并转发消息,用于恶搞群友或好友。
|
|
8
|
+
|
|
9
|
+
## 使用方法
|
|
10
|
+
|
|
11
|
+
触发格式:`QQ号说内容`
|
|
12
|
+
|
|
13
|
+
例如:
|
|
14
|
+
```
|
|
15
|
+
123456说你好
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
如果要同时伪造多个用户的消息,可以使用 `|` 分隔:
|
|
19
|
+
```
|
|
20
|
+
123456说你好|654321说早上好
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
如果要伪造同一用户的多条消息,可以使用空格分隔:
|
|
24
|
+
```
|
|
25
|
+
123456说你好 早上好 今天天气真不错
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
当然,你也可以综合使用:
|
|
29
|
+
```
|
|
30
|
+
123456说你好 早上好|654321说今天天气真不错 周末要不要出去玩
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## 配置项
|
|
34
|
+
|
|
35
|
+
- `userSplit`: 用户消息分隔符,默认为 `|`
|
|
36
|
+
- `messageSplit`: 同一用户多条消息分隔符,默认为空格
|
|
37
|
+
- `blockedUsers`: 被屏蔽的QQ号列表,这些QQ号将无法被伪造消息,默认为空数组
|
|
38
|
+
|
|
39
|
+
## 注意事项
|
|
40
|
+
|
|
41
|
+
1. 伪造消息的 QQ 号必须是真实存在的用户
|
|
42
|
+
2. 如果合并转发消息发送失败,插件会自动退化为逐条发送文本消息
|
|
43
|
+
3. 本插件适用于所有适配器,但合并转发功能可能只在部分适配器中可用
|
|
44
|
+
4. 被屏蔽的QQ号将无法被伪造消息,尝试伪造被屏蔽QQ号的消息时会收到提示
|