kokkoro-plugin-hitokoto 2.0.1 → 3.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/LICENSE +1 -1
- package/README.md +47 -23
- package/package.json +17 -12
- package/src/index.ts +89 -37
- package/lib/index.js +0 -13
- package/tsconfig.json +0 -13
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,23 +1,47 @@
|
|
|
1
|
-
# kokkoro-plugin-hitokoto
|
|
2
|
-
|
|
3
|
-
ヒトコト
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
```shell
|
|
8
|
-
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
1
|
+
# kokkoro-plugin-hitokoto
|
|
2
|
+
|
|
3
|
+
ヒトコト
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```shell
|
|
8
|
+
bun add kokkoro-plugin-hitokoto
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 指令
|
|
12
|
+
|
|
13
|
+
```text
|
|
14
|
+
/一言 [types]...
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
`types` 是可选的一言类型。不填写时,插件默认会从一言接口随机返回一条动画或漫画语句。
|
|
18
|
+
|
|
19
|
+
```text
|
|
20
|
+
/一言
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
填写类型可以限定本次返回的语句,多个类型使用空格分隔。
|
|
24
|
+
|
|
25
|
+
```text
|
|
26
|
+
/一言 诗词 文学
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
支持动画、漫画、游戏、文学、原创、来自网络、其他、影视、诗词、网易云、哲学和抖机灵。
|
|
30
|
+
|
|
31
|
+
## 快捷方式
|
|
32
|
+
|
|
33
|
+
发送「来点骚话」也会随机返回一条语句,群聊需要开启「获取群内全部消息」权限。
|
|
34
|
+
|
|
35
|
+
```text
|
|
36
|
+
来点骚话
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## 环境变量
|
|
40
|
+
|
|
41
|
+
如需修改默认语句类型,请在项目根目录创建 `.env` 文件,并通过 `HITOKOTO_TYPES` 设置一言接口的 `c` 参数。多个类型使用逗号分隔,默认值为 `a,b`。
|
|
42
|
+
|
|
43
|
+
```ini
|
|
44
|
+
HITOKOTO_TYPES=c,d
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
类型取值参阅[一言接口文档](https://developer.hitokoto.cn/sentence/#请求参数)。修改 `.env` 后需要重新启动项目。
|
package/package.json
CHANGED
|
@@ -1,23 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kokkoro-plugin-hitokoto",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "ヒトコト",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"main": "lib/index.js",
|
|
7
|
-
"typings": "lib/index.d.ts",
|
|
8
5
|
"keywords": [
|
|
9
6
|
"bot",
|
|
10
7
|
"kokkoro",
|
|
11
8
|
"hitokoto",
|
|
12
9
|
"qq"
|
|
13
10
|
],
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
"
|
|
11
|
+
"bugs": "https://github.com/kokkorojs/kokkoro/issues",
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/kokkorojs/kokkoro.git",
|
|
15
|
+
"directory": "plugins/hitokoto"
|
|
18
16
|
},
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"author": "Yuki <admin@yuki.sh>",
|
|
19
|
+
"type": "module",
|
|
20
|
+
"exports": "./src/index.ts",
|
|
21
|
+
"files": [
|
|
22
|
+
"src"
|
|
23
|
+
],
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"@kokkoro/core": "^3.1.3",
|
|
26
|
+
"typescript": "^6.0.3"
|
|
22
27
|
}
|
|
23
|
-
}
|
|
28
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,42 +1,94 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
//
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
-
//
|
|
11
|
-
|
|
12
|
-
//
|
|
13
|
-
|
|
14
|
-
//
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
1
|
+
import { useCommand } from '@kokkoro/core';
|
|
2
|
+
|
|
3
|
+
type SentenceType =
|
|
4
|
+
| 'a' // 动画
|
|
5
|
+
| 'b' // 漫画
|
|
6
|
+
| 'c' // 游戏
|
|
7
|
+
| 'd' // 文学
|
|
8
|
+
| 'e' // 原创
|
|
9
|
+
| 'f' // 来自网络
|
|
10
|
+
| 'g' // 其他
|
|
11
|
+
| 'h' // 影视
|
|
12
|
+
| 'i' // 诗词
|
|
13
|
+
| 'j' // 网易云
|
|
14
|
+
| 'k' // 哲学
|
|
15
|
+
| 'l'; // 抖机灵
|
|
16
|
+
|
|
17
|
+
interface Sentence {
|
|
18
|
+
/** 一言标识 */
|
|
19
|
+
readonly id: number;
|
|
20
|
+
/** 一言正文。编码方式 unicode。使用 utf-8。 */
|
|
21
|
+
readonly hitokoto: string;
|
|
22
|
+
/** 类型。请参考第三节参数的表格 */
|
|
23
|
+
readonly type: SentenceType;
|
|
24
|
+
/** 一言的出处 */
|
|
25
|
+
readonly from: string;
|
|
26
|
+
/** 一言的作者 */
|
|
27
|
+
readonly from_who: string | null;
|
|
28
|
+
/** 添加者 */
|
|
29
|
+
readonly creator: string;
|
|
30
|
+
/** 添加者用户标识 */
|
|
31
|
+
readonly creator_uid: number;
|
|
32
|
+
/** 审核员标识 */
|
|
33
|
+
readonly reviewer: number;
|
|
34
|
+
/** 一言唯一标识,可以链接到 https://hitokoto.cn?uuid=[uuid] 查看这个一言的完整信息 */
|
|
35
|
+
readonly uuid: string;
|
|
36
|
+
/** 提交方式 */
|
|
37
|
+
readonly commit_from: string;
|
|
38
|
+
/** 添加时间 */
|
|
39
|
+
readonly created_at: string;
|
|
40
|
+
/** 句子长度 */
|
|
41
|
+
readonly length: number;
|
|
28
42
|
}
|
|
29
|
-
export const metadata: Metadata = {
|
|
30
|
-
name: 'hitokoto',
|
|
31
|
-
description: '一言语句',
|
|
32
|
-
};
|
|
33
43
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
44
|
+
const { HITOKOTO_TYPES = 'a,b' } = import.meta.env;
|
|
45
|
+
const HITOKOTO_API = new URL('https://v1.hitokoto.cn');
|
|
46
|
+
const TYPE_CODES = {
|
|
47
|
+
动画: 'a',
|
|
48
|
+
漫画: 'b',
|
|
49
|
+
游戏: 'c',
|
|
50
|
+
文学: 'd',
|
|
51
|
+
原创: 'e',
|
|
52
|
+
来自网络: 'f',
|
|
53
|
+
其他: 'g',
|
|
54
|
+
影视: 'h',
|
|
55
|
+
诗词: 'i',
|
|
56
|
+
网易云: 'j',
|
|
57
|
+
哲学: 'k',
|
|
58
|
+
抖机灵: 'l',
|
|
59
|
+
} as const satisfies Record<string, SentenceType>;
|
|
60
|
+
const TYPE_NAMES = Object.keys(TYPE_CODES).join('、');
|
|
39
61
|
|
|
40
|
-
|
|
62
|
+
function resolveTypes(names: string[]) {
|
|
63
|
+
if (names.length === 0) {
|
|
64
|
+
return HITOKOTO_TYPES.split(',');
|
|
65
|
+
}
|
|
66
|
+
return names.map(name => {
|
|
67
|
+
const type = TYPE_CODES[<keyof typeof TYPE_CODES>name];
|
|
68
|
+
|
|
69
|
+
if (!type) {
|
|
70
|
+
throw new Error(`不支持的一言类型「${name}」,可用类型为${TYPE_NAMES}`);
|
|
71
|
+
}
|
|
72
|
+
return type;
|
|
41
73
|
});
|
|
42
74
|
}
|
|
75
|
+
|
|
76
|
+
async function getHitokoto(names: string[]) {
|
|
77
|
+
const url = new URL(HITOKOTO_API);
|
|
78
|
+
|
|
79
|
+
for (const type of resolveTypes(names)) {
|
|
80
|
+
url.searchParams.append('c', type);
|
|
81
|
+
}
|
|
82
|
+
const response = await fetch(url);
|
|
83
|
+
|
|
84
|
+
if (!response.ok) {
|
|
85
|
+
throw new Error(`接口请求失败,状态码 ${response.status}`);
|
|
86
|
+
}
|
|
87
|
+
const { hitokoto, from } = <Sentence>await response.json();
|
|
88
|
+
|
|
89
|
+
return `『${hitokoto}』——「${from}」`;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export default () => {
|
|
93
|
+
useCommand('/一言 [types]...', context => getHitokoto(context.args.types)).shortcut('来点骚话');
|
|
94
|
+
};
|
package/lib/index.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { useCommand } from '@kokkoro/core';
|
|
2
|
-
export const metadata = {
|
|
3
|
-
name: 'hitokoto',
|
|
4
|
-
description: '一言语句',
|
|
5
|
-
};
|
|
6
|
-
export default function Hitokoto() {
|
|
7
|
-
useCommand('/来点骚话', async (ctx) => {
|
|
8
|
-
const { data } = await ctx.bot.request.get('https://v1.hitokoto.cn?c=a&c=b');
|
|
9
|
-
const { hitokoto, from } = data;
|
|
10
|
-
const message = `『${hitokoto}』——「${from}」`;
|
|
11
|
-
return message;
|
|
12
|
-
});
|
|
13
|
-
}
|