kokkoro-plugin-hitokoto 2.0.0 → 3.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/LICENSE +1 -1
- package/README.md +27 -0
- package/package.json +17 -12
- package/src/index.ts +57 -37
- package/lib/index.js +0 -13
- package/tsconfig.json +0 -13
package/LICENSE
CHANGED
package/README.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# kokkoro-plugin-hitokoto
|
|
2
|
+
|
|
3
|
+
ヒトコト
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```shell
|
|
8
|
+
bun add kokkoro-plugin-hitokoto
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 指令
|
|
12
|
+
|
|
13
|
+
发送「/一言」,插件默认会从一言接口随机返回一条动画或漫画语句。
|
|
14
|
+
|
|
15
|
+
## 快捷方式
|
|
16
|
+
|
|
17
|
+
也可以发送「来点骚话」触发,群聊需要开启「获取群内全部消息」权限。
|
|
18
|
+
|
|
19
|
+
## 环境变量
|
|
20
|
+
|
|
21
|
+
如需修改语句类型,请在项目根目录创建 `.env` 文件,并通过 `HITOKOTO_TYPES` 设置一言接口的 `c` 参数。多个类型使用逗号分隔,默认值为 `a,b`。
|
|
22
|
+
|
|
23
|
+
```ini
|
|
24
|
+
HITOKOTO_TYPES=c,d
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
类型取值参阅[一言接口文档](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.0",
|
|
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,62 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useCommand } from '@kokkoro/core';
|
|
2
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
|
-
|
|
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
|
-
const { data } = await bot.request.get<Hitokoto>('https://v1.hitokoto.cn?c=a&c=b');
|
|
37
|
-
const { hitokoto, from } = data;
|
|
38
|
-
const message = `『${hitokoto}』——「${from}」`;
|
|
44
|
+
const { HITOKOTO_TYPES = 'a,b' } = import.meta.env;
|
|
45
|
+
const HITOKOTO_API = new URL('https://v1.hitokoto.cn');
|
|
39
46
|
|
|
40
|
-
|
|
41
|
-
|
|
47
|
+
for (const type of HITOKOTO_TYPES.split(',')) {
|
|
48
|
+
HITOKOTO_API.searchParams.append('c', type);
|
|
42
49
|
}
|
|
50
|
+
|
|
51
|
+
export default () => {
|
|
52
|
+
useCommand('/一言', async () => {
|
|
53
|
+
const response = await fetch(HITOKOTO_API);
|
|
54
|
+
|
|
55
|
+
if (!response.ok) {
|
|
56
|
+
throw new Error(`接口请求失败,状态码 ${response.status}`);
|
|
57
|
+
}
|
|
58
|
+
const { hitokoto, from } = <Sentence>await response.json();
|
|
59
|
+
|
|
60
|
+
return `『${hitokoto}』——「${from}」`;
|
|
61
|
+
}).shortcut('来点骚话');
|
|
62
|
+
};
|
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 (_, bot) => {
|
|
8
|
-
const { data } = await 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
|
-
}
|