@koishi-ce/plugin-inspect 1.0.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/lib/assets/zh-CN-Dm2KmiOI.yml +18 -0
- package/lib/index.d.ts +9 -0
- package/lib/index.mjs +37 -0
- package/locales/de-DE.yml +18 -0
- package/locales/en-US.yml +18 -0
- package/locales/fr-FR.yml +18 -0
- package/locales/ja-JP.yml +18 -0
- package/locales/ru-RU.yml +18 -0
- package/locales/zh-CN.yml +18 -0
- package/locales/zh-TW.yml +18 -0
- package/package.json +66 -0
- package/src/index.test.ts +55 -0
- package/src/index.ts +53 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
commands:
|
|
2
|
+
inspect:
|
|
3
|
+
description: 查看用户、频道或消息的详细信息
|
|
4
|
+
usage: |-
|
|
5
|
+
inspect @user
|
|
6
|
+
inspect #channel
|
|
7
|
+
inspect
|
|
8
|
+
messages:
|
|
9
|
+
invalid: 参数无法解析。
|
|
10
|
+
user: 用户 ID:{id}
|
|
11
|
+
channel: 频道 ID:{id}
|
|
12
|
+
message: |-
|
|
13
|
+
平台名:{platform}
|
|
14
|
+
消息 ID:{messageId}
|
|
15
|
+
频道 ID:{channelId}
|
|
16
|
+
群组 ID:{guildId}
|
|
17
|
+
用户 ID:{userId}
|
|
18
|
+
自身 ID:{selfId}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Context, Schema } from "@koishi-ce/koishi";
|
|
2
|
+
//#region src/index.d.ts
|
|
3
|
+
declare const name = "inspect";
|
|
4
|
+
/** 配置项(当前无可用配置) */
|
|
5
|
+
type Config = Record<never, never>;
|
|
6
|
+
declare const Config: Schema<Config>;
|
|
7
|
+
declare function apply(ctx: Context): void;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { Config, apply, name };
|
package/lib/index.mjs
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Schema, h } from "@koishi-ce/koishi";
|
|
2
|
+
import zhCN from "./assets/zh-CN-Dm2KmiOI.yml";
|
|
3
|
+
//#region src/index.ts
|
|
4
|
+
/**
|
|
5
|
+
* 消息检查插件(inspect)。
|
|
6
|
+
*
|
|
7
|
+
* 提供 `inspect` 指令:查看当前会话或引用消息的平台、消息 ID、
|
|
8
|
+
* 频道 / 群组 / 用户 / 自身 ID 等元信息;
|
|
9
|
+
* 也可以直接检查消息中携带的 `<at>`(用户)或 `<sharp>`(频道)元素。
|
|
10
|
+
*/
|
|
11
|
+
const name = "inspect";
|
|
12
|
+
const Config = Schema.object({});
|
|
13
|
+
function apply(ctx) {
|
|
14
|
+
ctx.i18n.define("zh-CN", zhCN);
|
|
15
|
+
ctx.command("inspect", { captureQuote: false }).action(({ session }, target) => {
|
|
16
|
+
if (!session) return;
|
|
17
|
+
if (session.quote) return session.text(".message", {
|
|
18
|
+
platform: session.platform,
|
|
19
|
+
messageId: session.quote.id,
|
|
20
|
+
guildId: session.guildId,
|
|
21
|
+
selfId: session.selfId,
|
|
22
|
+
userId: session.quote.user?.id,
|
|
23
|
+
channelId: session.quote.channel?.id
|
|
24
|
+
});
|
|
25
|
+
if (target) {
|
|
26
|
+
const element = h.parse(target)[0];
|
|
27
|
+
if (!element) return session.text(".invalid");
|
|
28
|
+
const { type, attrs } = element;
|
|
29
|
+
if (type === "at") return session.text(".user", attrs);
|
|
30
|
+
else if (type === "sharp") return session.text(".channel", attrs);
|
|
31
|
+
else return session.text(".invalid");
|
|
32
|
+
}
|
|
33
|
+
return session.text(".message", session);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
37
|
+
export { Config, apply, name };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
commands:
|
|
2
|
+
inspect:
|
|
3
|
+
description: 查看用户、频道或消息的详细信息
|
|
4
|
+
usage: |-
|
|
5
|
+
inspect @user
|
|
6
|
+
inspect #channel
|
|
7
|
+
inspect
|
|
8
|
+
messages:
|
|
9
|
+
invalid: 参数无法解析。
|
|
10
|
+
user: 用户 ID:{id}
|
|
11
|
+
channel: 频道 ID:{id}
|
|
12
|
+
message: |-
|
|
13
|
+
平台名:{platform}
|
|
14
|
+
消息 ID:{messageId}
|
|
15
|
+
频道 ID:{channelId}
|
|
16
|
+
群组 ID:{guildId}
|
|
17
|
+
用户 ID:{userId}
|
|
18
|
+
自身 ID:{selfId}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
commands:
|
|
2
|
+
inspect:
|
|
3
|
+
description: View details of users, channels or messages
|
|
4
|
+
usage: |-
|
|
5
|
+
inspect @user
|
|
6
|
+
inspect #channel
|
|
7
|
+
inspect
|
|
8
|
+
messages:
|
|
9
|
+
invalid: Could not parse arguments.
|
|
10
|
+
user: 'User ID: {id}'
|
|
11
|
+
channel: 'Channel ID: {id}'
|
|
12
|
+
message: |-
|
|
13
|
+
Platform name: {platform}
|
|
14
|
+
Message ID: {messageId}
|
|
15
|
+
Channel ID: {channelId}
|
|
16
|
+
Guild ID: {guildId}
|
|
17
|
+
User ID: {userId}
|
|
18
|
+
Self ID: {selfId}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
commands:
|
|
2
|
+
inspect:
|
|
3
|
+
description: 查看用户、频道或消息的详细信息
|
|
4
|
+
usage: |-
|
|
5
|
+
inspect @user
|
|
6
|
+
inspect #channel
|
|
7
|
+
inspect
|
|
8
|
+
messages:
|
|
9
|
+
invalid: 参数无法解析。
|
|
10
|
+
user: 用户 ID:{id}
|
|
11
|
+
channel: 频道 ID:{id}
|
|
12
|
+
message: |-
|
|
13
|
+
平台名:{platform}
|
|
14
|
+
消息 ID:{messageId}
|
|
15
|
+
频道 ID:{channelId}
|
|
16
|
+
群组 ID:{guildId}
|
|
17
|
+
用户 ID:{userId}
|
|
18
|
+
自身 ID:{selfId}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
commands:
|
|
2
|
+
inspect:
|
|
3
|
+
description: 查看用户、频道或消息的详细信息
|
|
4
|
+
usage: |-
|
|
5
|
+
inspect @user
|
|
6
|
+
inspect #channel
|
|
7
|
+
inspect
|
|
8
|
+
messages:
|
|
9
|
+
invalid: 参数无法解析。
|
|
10
|
+
user: 用户 ID:{id}
|
|
11
|
+
channel: 频道 ID:{id}
|
|
12
|
+
message: |-
|
|
13
|
+
平台名:{platform}
|
|
14
|
+
消息 ID:{messageId}
|
|
15
|
+
频道 ID:{channelId}
|
|
16
|
+
群组 ID:{guildId}
|
|
17
|
+
用户 ID:{userId}
|
|
18
|
+
自身 ID:{selfId}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
commands:
|
|
2
|
+
inspect:
|
|
3
|
+
description: 查看用户、频道或消息的详细信息
|
|
4
|
+
usage: |-
|
|
5
|
+
inspect @user
|
|
6
|
+
inspect #channel
|
|
7
|
+
inspect
|
|
8
|
+
messages:
|
|
9
|
+
invalid: 参数无法解析。
|
|
10
|
+
user: 'Идентификатор Пользователя: {id}'
|
|
11
|
+
channel: Идентификатор Канала:{id}
|
|
12
|
+
message: |-
|
|
13
|
+
平台名:{platform}
|
|
14
|
+
消息 ID:{messageId}
|
|
15
|
+
频道 ID:{channelId}
|
|
16
|
+
群组 ID:{guildId}
|
|
17
|
+
用户 ID:{userId}
|
|
18
|
+
自身 ID:{selfId}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
commands:
|
|
2
|
+
inspect:
|
|
3
|
+
description: 查看用户、频道或消息的详细信息
|
|
4
|
+
usage: |-
|
|
5
|
+
inspect @user
|
|
6
|
+
inspect #channel
|
|
7
|
+
inspect
|
|
8
|
+
messages:
|
|
9
|
+
invalid: 参数无法解析。
|
|
10
|
+
user: 用户 ID:{id}
|
|
11
|
+
channel: 频道 ID:{id}
|
|
12
|
+
message: |-
|
|
13
|
+
平台名:{platform}
|
|
14
|
+
消息 ID:{messageId}
|
|
15
|
+
频道 ID:{channelId}
|
|
16
|
+
群组 ID:{guildId}
|
|
17
|
+
用户 ID:{userId}
|
|
18
|
+
自身 ID:{selfId}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
commands:
|
|
2
|
+
inspect:
|
|
3
|
+
description: 查看使用者、頻道或消息的詳細信息
|
|
4
|
+
usage: |-
|
|
5
|
+
inspect @user
|
|
6
|
+
inspect #channel
|
|
7
|
+
inspect
|
|
8
|
+
messages:
|
|
9
|
+
invalid: 參數無法解析。
|
|
10
|
+
user: 使用者 ID:{id}
|
|
11
|
+
channel: 頻道 ID:{id}
|
|
12
|
+
message: |-
|
|
13
|
+
平台名:{platform}
|
|
14
|
+
消息 ID:{messageId}
|
|
15
|
+
頻道 ID:{channelId}
|
|
16
|
+
群組 ID:{guildId}
|
|
17
|
+
使用者 ID:{userId}
|
|
18
|
+
自身 ID:{selfId}
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@koishi-ce/plugin-inspect",
|
|
3
|
+
"description": "Inspect on any user, channel or message",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "lib/index.mjs",
|
|
7
|
+
"typings": "lib/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"lib",
|
|
10
|
+
"src",
|
|
11
|
+
"locales"
|
|
12
|
+
],
|
|
13
|
+
"contributors": [
|
|
14
|
+
"Shigma <shigma10826@gmail.com>",
|
|
15
|
+
"Oppenheymu <oppenheymu@gmail.com>"
|
|
16
|
+
],
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/Koishi-CE/koishi.git",
|
|
21
|
+
"directory": "plugins/common/inspect"
|
|
22
|
+
},
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/Koishi-CE/koishi/issues"
|
|
25
|
+
},
|
|
26
|
+
"homepage": "https://koishi.chat/plugins/common/inspect.html",
|
|
27
|
+
"keywords": [
|
|
28
|
+
"bot",
|
|
29
|
+
"chatbot",
|
|
30
|
+
"koishi",
|
|
31
|
+
"plugin",
|
|
32
|
+
"inspect",
|
|
33
|
+
"debug",
|
|
34
|
+
"info",
|
|
35
|
+
"context",
|
|
36
|
+
"channel",
|
|
37
|
+
"user",
|
|
38
|
+
"message",
|
|
39
|
+
"session"
|
|
40
|
+
],
|
|
41
|
+
"koishi": {
|
|
42
|
+
"browser": true,
|
|
43
|
+
"description": {
|
|
44
|
+
"en": "Inspect on any user, channel or message",
|
|
45
|
+
"zh": "查看用户、频道或消息的详细信息"
|
|
46
|
+
},
|
|
47
|
+
"locales": [
|
|
48
|
+
"zh"
|
|
49
|
+
]
|
|
50
|
+
},
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"koishi": "^4.18.11"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@koishi-ce/plugin-mock": "^1.0.0",
|
|
56
|
+
"@koishi-ce/koishi": "^1.0.0"
|
|
57
|
+
},
|
|
58
|
+
"exports": {
|
|
59
|
+
".": {
|
|
60
|
+
"source": "./src/index.ts",
|
|
61
|
+
"types": "./lib/index.d.ts",
|
|
62
|
+
"import": "./lib/index.mjs",
|
|
63
|
+
"default": "./lib/index.mjs"
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* inspect 插件测试:验证当前会话、at / sharp 元素参数、
|
|
3
|
+
* 非法参数与引用消息四类输入的元信息输出。
|
|
4
|
+
*/
|
|
5
|
+
import { afterAll, beforeAll, describe, it } from "bun:test";
|
|
6
|
+
import { Context } from "@koishi-ce/koishi";
|
|
7
|
+
import mock from "@koishi-ce/plugin-mock";
|
|
8
|
+
import * as inspect from "./index.ts";
|
|
9
|
+
|
|
10
|
+
const app = new Context();
|
|
11
|
+
|
|
12
|
+
app.plugin(inspect);
|
|
13
|
+
app.plugin(mock);
|
|
14
|
+
|
|
15
|
+
const client = app.mock.client("123", "456");
|
|
16
|
+
|
|
17
|
+
beforeAll(() => app.start());
|
|
18
|
+
afterAll(() => app.stop());
|
|
19
|
+
|
|
20
|
+
describe("@koishi-ce/plugin-inspect", () => {
|
|
21
|
+
// 裸 inspect 输出会话元信息;at / sharp 参数输出对应 ID;非法参数报错;引用消息输出被引用者信息
|
|
22
|
+
it("basic support", async () => {
|
|
23
|
+
await client.shouldReply(
|
|
24
|
+
"inspect",
|
|
25
|
+
new RegExp(
|
|
26
|
+
[
|
|
27
|
+
"平台名:mock",
|
|
28
|
+
"消息 ID:\\d+",
|
|
29
|
+
"频道 ID:456",
|
|
30
|
+
"群组 ID:456",
|
|
31
|
+
"用户 ID:123",
|
|
32
|
+
"自身 ID:514",
|
|
33
|
+
].join("\n"),
|
|
34
|
+
),
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
await client.shouldReply('inspect <at id="321"/>', "用户 ID:321");
|
|
38
|
+
await client.shouldReply('inspect <sharp id="654"/>', "频道 ID:654");
|
|
39
|
+
await client.shouldReply("inspect foobar", "参数无法解析。");
|
|
40
|
+
|
|
41
|
+
await client.shouldReply(
|
|
42
|
+
'<quote id="114514"/> inspect foobar',
|
|
43
|
+
new RegExp(
|
|
44
|
+
[
|
|
45
|
+
"平台名:mock",
|
|
46
|
+
"消息 ID:114514",
|
|
47
|
+
"频道 ID:.*",
|
|
48
|
+
"群组 ID:456",
|
|
49
|
+
"用户 ID:.*",
|
|
50
|
+
"自身 ID:514",
|
|
51
|
+
].join("\n"),
|
|
52
|
+
),
|
|
53
|
+
);
|
|
54
|
+
});
|
|
55
|
+
});
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 消息检查插件(inspect)。
|
|
3
|
+
*
|
|
4
|
+
* 提供 `inspect` 指令:查看当前会话或引用消息的平台、消息 ID、
|
|
5
|
+
* 频道 / 群组 / 用户 / 自身 ID 等元信息;
|
|
6
|
+
* 也可以直接检查消息中携带的 `<at>`(用户)或 `<sharp>`(频道)元素。
|
|
7
|
+
*/
|
|
8
|
+
import { type Context, h, Schema } from "@koishi-ce/koishi";
|
|
9
|
+
import zhCN from "../locales/zh-CN.yml";
|
|
10
|
+
|
|
11
|
+
export const name = "inspect";
|
|
12
|
+
|
|
13
|
+
/** 配置项(当前无可用配置) */
|
|
14
|
+
export type Config = Record<never, never>;
|
|
15
|
+
|
|
16
|
+
export const Config: Schema<Config> = Schema.object({});
|
|
17
|
+
|
|
18
|
+
export function apply(ctx: Context) {
|
|
19
|
+
ctx.i18n.define("zh-CN", zhCN);
|
|
20
|
+
|
|
21
|
+
ctx
|
|
22
|
+
.command("inspect", { captureQuote: false })
|
|
23
|
+
.action(({ session }, target) => {
|
|
24
|
+
if (!session) return;
|
|
25
|
+
// 优先展示引用消息的信息(captureQuote 已关闭,引用保留在会话对象上)
|
|
26
|
+
if (session.quote) {
|
|
27
|
+
return session.text(".message", {
|
|
28
|
+
platform: session.platform,
|
|
29
|
+
messageId: session.quote.id,
|
|
30
|
+
guildId: session.guildId,
|
|
31
|
+
selfId: session.selfId,
|
|
32
|
+
userId: session.quote.user?.id,
|
|
33
|
+
channelId: session.quote.channel?.id,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// 检查消息参数中携带的元素(@ 用户 / # 频道),其余元素视为无法解析
|
|
38
|
+
if (target) {
|
|
39
|
+
const element = h.parse(target)[0];
|
|
40
|
+
if (!element) return session.text(".invalid");
|
|
41
|
+
const { type, attrs } = element;
|
|
42
|
+
if (type === "at") {
|
|
43
|
+
return session.text(".user", attrs);
|
|
44
|
+
} else if (type === "sharp") {
|
|
45
|
+
return session.text(".channel", attrs);
|
|
46
|
+
} else {
|
|
47
|
+
return session.text(".invalid");
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return session.text(".message", session);
|
|
52
|
+
});
|
|
53
|
+
}
|