kokkoro-plugin-hitokoto 1.2.0 → 2.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 CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2020 yuki
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.
1
+ MIT License
2
+
3
+ Copyright (c) 2020-2023 Yuki
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/index.js CHANGED
@@ -1,41 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const kokkoro_1 = require("kokkoro");
4
- const service_1 = require("./service");
5
- const option = {
6
- apply: true,
7
- lock: false,
8
- auto_send: true,
9
- param: '?c=a&c=b&c=c',
10
- };
11
- const { version } = require('../package.json');
12
- const plugin = new kokkoro_1.Plugin('hitokoto', option);
13
- const service = new service_1.HitokotoService();
14
- plugin
15
- .version(version)
16
- .schedule(process.env.HITOKOTO_DATE ?? '0 0 0 * * *', async () => {
17
- const hitokoto = await service.getHitokoto(option.param);
18
- plugin.bl.forEach((bot) => {
19
- const sendQueue = [];
20
- const uins = [...bot.gl.keys()];
21
- const uins_length = uins.length;
22
- for (let i = 0; i < uins_length; i++) {
23
- const uin = uins[i];
24
- const info = bot.gl.get(uin);
25
- const { group_id } = info;
26
- const { apply, auto_send } = bot.profile.getOption(group_id, 'hitokoto');
27
- if (apply && auto_send) {
28
- sendQueue.push(bot.sendGroupMsg(group_id, hitokoto));
29
- }
30
- }
31
- Promise.allSettled(sendQueue);
32
- });
33
- });
34
- plugin
35
- .command('say')
36
- .description('发送一言')
37
- .sugar(/^(来|说)(点|句|段)骚话$/)
38
- .action(async (ctx) => {
39
- const hitokoto = await service.getHitokoto(ctx.option?.param ?? option.param);
40
- await ctx.reply(hitokoto);
41
- });
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
+ }
package/package.json CHANGED
@@ -1,31 +1,23 @@
1
1
  {
2
2
  "name": "kokkoro-plugin-hitokoto",
3
- "version": "1.2.0",
3
+ "version": "2.0.0",
4
4
  "description": "ヒトコト",
5
+ "type": "module",
5
6
  "main": "lib/index.js",
6
- "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
8
- },
9
- "repository": {
10
- "type": "git",
11
- "url": "git+https://github.com/kokkorojs/kokkoro-plugin-hitokoto.git"
12
- },
7
+ "typings": "lib/index.d.ts",
13
8
  "keywords": [
9
+ "bot",
14
10
  "kokkoro",
15
- "hitokoto"
11
+ "hitokoto",
12
+ "qq"
16
13
  ],
17
- "author": "yuki <mail@yuki.sh>",
14
+ "author": "Yuki <admin@yuki.sh>",
18
15
  "license": "MIT",
19
- "bugs": {
20
- "url": "https://github.com/kokkorojs/kokkoro-plugin-hitokoto/issues"
16
+ "dependencies": {
17
+ "@kokkoro/core": "^3.0.1"
21
18
  },
22
- "homepage": "https://github.com/kokkorojs/kokkoro-plugin-hitokoto#readme",
23
- "devDependencies": {
24
- "@types/node": "^18.11.19",
25
- "axios": "^1.3.2",
26
- "kokkoro": "^2.0.0-alpha.1"
27
- },
28
- "files": [
29
- "lib"
30
- ]
19
+ "scripts": {
20
+ "build": "tsc && tsc-alias",
21
+ "build:watch": "tsc && (concurrently \"tsc -w\" \"tsc-alias -w\")"
22
+ }
31
23
  }
package/src/index.ts ADDED
@@ -0,0 +1,42 @@
1
+ import { Metadata, useCommand } from '@kokkoro/core';
2
+
3
+ interface Hitokoto {
4
+ // 一言标识
5
+ id: string;
6
+ // 一言正文 编码方式 unicode 使用 utf-8
7
+ hitokoto: string;
8
+ // 类型
9
+ type: string;
10
+ // 一言的出处
11
+ from: string;
12
+ // 一言的作者
13
+ from_who: string;
14
+ // 添加者
15
+ creator: string;
16
+ // 添加者用户标识
17
+ creator_uid: string;
18
+ // 审核员标识
19
+ reviewer: string;
20
+ // 一言唯一标识;可以链接到 https://hitokoto.cn?uuid=[uuid] (opens new window)查看这个一言的完整信息
21
+ uuid: string;
22
+ // 提交方式
23
+ commit_from: string;
24
+ // 添加时间
25
+ created_at: string;
26
+ // 句子长度
27
+ length: number;
28
+ }
29
+ export const metadata: Metadata = {
30
+ name: 'hitokoto',
31
+ description: '一言语句',
32
+ };
33
+
34
+ export default function Hitokoto() {
35
+ useCommand('/来点骚话', async (_, bot) => {
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}」`;
39
+
40
+ return message;
41
+ });
42
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "extends": "../../tsconfig.base",
3
+ "compilerOptions": {
4
+ "rootDir": "src",
5
+ "baseUrl": ".",
6
+ "paths": {
7
+ "@/*": ["src/*"]
8
+ },
9
+ "outDir": "lib",
10
+ "declaration": false
11
+ },
12
+ "include": ["src"]
13
+ }
package/README.md DELETED
@@ -1,37 +0,0 @@
1
- # kokkoro-hitokoto
2
-
3
- > ヒトコト
4
-
5
- ## 安装
6
-
7
- ```shell
8
- # 切换至 bot 目录
9
- cd bot
10
-
11
- # 安装 npm 包
12
- npm i kokkoro-plugin-hitokoto
13
- ```
14
-
15
- ## 配置项
16
-
17
- ```typescript
18
- interface HitokotoOption extends Option {
19
- /** 在特定时间段自动发送,默认凌晨 */
20
- auto_send: boolean;
21
- /** 一言接口 get 请求参数,默认 "?c=a&c=b&c=c" */
22
- param: string;
23
- }
24
- ```
25
-
26
- 更多参数可查看 [hitokoto](https://developer.hitokoto.cn/sentence/#%E8%AF%B7%E6%B1%82%E5%8F%82%E6%95%B0) 官方文档
27
-
28
- ## 环境变量
29
-
30
- 你可以在项目根目录下创建 `.env` 文件
31
-
32
- ```ini
33
- # 网抑云时间
34
- HITOKOTO_DATE=0 0 0 * * *
35
- ```
36
-
37
- 因为插件的定时任务是在初始化时创建的,所以如果你修改了 `HITOKOTO_DATE` 变量,需要使用 `reload` 指令将其重新挂载才能生效。
package/lib/service.js DELETED
@@ -1,27 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.HitokotoService = void 0;
7
- const axios_1 = __importDefault(require("axios"));
8
- class HitokotoService {
9
- /** API */
10
- api;
11
- constructor() {
12
- this.api = 'https://v1.hitokoto.cn';
13
- }
14
- async getHitokoto(param = '') {
15
- let message;
16
- try {
17
- const { data } = await axios_1.default.get(this.api + param);
18
- const { hitokoto, from } = data;
19
- message = `${hitokoto}\n\t\t\t\t———— 「${from}」`;
20
- }
21
- catch (error) {
22
- message = error.message;
23
- }
24
- return message;
25
- }
26
- }
27
- exports.HitokotoService = HitokotoService;