kokkoro-plugin-hitokoto 0.3.0 → 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/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  ## 安装
6
6
 
7
- ``` shell
7
+ ```shell
8
8
  # 切换至 bot 目录
9
9
  cd bot
10
10
 
@@ -12,16 +12,13 @@ cd bot
12
12
  npm i kokkoro-plugin-hitokoto
13
13
  ```
14
14
 
15
- 在 [kokkoro](https://github.com/kokkorojs/kokkoro) 成功运行并登录后,发送 `enable hitokoto` 即可为 bot 启用插件
16
- 使用 `hitokoto update <key> <value>` 可修改当前群聊的插件参数,例如关闭每日自动发送 `hitokoto update auto_send false`
17
-
18
15
  ## 参数
19
16
 
20
- ``` typescript
21
- interface HitokotoOption {
22
- // 在每天凌晨自动发送
17
+ ```typescript
18
+ interface HitokotoOption extends Option {
19
+ /** 在每天凌晨自动发送 */
23
20
  auto_send: boolean;
24
- // 一言接口 get 请求参数
21
+ /** 一言接口 get 请求参数,默认 "?c=a&c=b&c=c" */
25
22
  param: string;
26
23
  }
27
24
  ```
package/lib/indaex.js ADDED
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const kokkoro_1 = require("kokkoro");
4
+ const service_1 = require("./service");
5
+ const setting = {
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', setting);
13
+ plugin
14
+ .version(version)
15
+ .schedule('0 0 0 * * *', async () => {
16
+ const hitokoto = await (0, service_1.getHitokoto)(setting.param);
17
+ const uins = plugin.getBotUins();
18
+ uins.forEach(async (uin) => {
19
+ const gl = await plugin.botApi(uin, 'gl');
20
+ gl.forEach(async (info) => {
21
+ const { group_id } = info;
22
+ const { apply } = await plugin.botApi(uin, 'getSetting', group_id, 'hitokoto');
23
+ if (!apply) {
24
+ return;
25
+ }
26
+ plugin.botApi(uin, 'sendGroupMsg', group_id, hitokoto);
27
+ });
28
+ });
29
+ });
30
+ plugin
31
+ .command('say')
32
+ .description('发送一言')
33
+ .sugar(/^(来|说)(点|句|段)骚话$/)
34
+ .action(async (ctx) => {
35
+ const param = ctx.setting?.param;
36
+ const hitokoto = await (0, service_1.getHitokoto)(param);
37
+ ctx.reply(hitokoto);
38
+ });
package/lib/index.js CHANGED
@@ -2,37 +2,37 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const kokkoro_1 = require("kokkoro");
4
4
  const service_1 = require("./service");
5
- // import { HitokotoOption } from './type';
6
- // const option: HitokotoOption = {
7
- // apply: true,
8
- // lock: false,
9
- // auto_send: true,
10
- // param: '?c=a&c=b&c=c',
11
- // };
5
+ const option = {
6
+ apply: true,
7
+ lock: false,
8
+ auto_send: true,
9
+ param: '?c=a&c=b&c=c',
10
+ };
12
11
  const { version } = require('../package.json');
13
- const plugin = new kokkoro_1.Plugin('hitokoto');
12
+ const plugin = new kokkoro_1.Plugin('hitokoto', option);
14
13
  plugin
15
- .version(version);
14
+ .version(version)
15
+ .schedule('0 0 0 * * *', async () => {
16
+ const hitokoto = await (0, service_1.getHitokoto)(option.param);
17
+ const uins = Object.keys((0, kokkoro_1.getConfig)('bots')).map(Number);
18
+ const uins_length = uins.length;
19
+ for (let i = 0; i < uins_length; i++) {
20
+ const uin = uins[i];
21
+ const gl = await plugin.botApi(uin, 'gl');
22
+ gl.forEach(async (info) => {
23
+ const { group_id } = info;
24
+ const { apply, auto_send } = await plugin.botApi(uin, 'getOption', group_id, 'hitokoto');
25
+ if (apply && auto_send) {
26
+ plugin.botApi(uin, 'sendGroupMsg', group_id, hitokoto);
27
+ }
28
+ });
29
+ }
30
+ });
16
31
  plugin
17
- // .schedule('0 0 0 * * ?', async () => {
18
- // const bot_list = getBotList();
19
- // const hitokoto = await getHitokoto(option.param);
20
- // for (const [_, bot] of bot_list) {
21
- // const group_list = bot.getGroupList();
22
- // // 判断开启服务的群
23
- // group_list.forEach(async group => {
24
- // const { group_id } = group;
25
- // const { apply, auto_send } = bot.getOption(group_id, 'hitokoto');
26
- // if (apply && auto_send) {
27
- // bot.sendGroupMsg(group_id, hitokoto);
28
- // }
29
- // })
30
- // }
31
- // })
32
32
  .command('say')
33
33
  .description('发送一言')
34
34
  .sugar(/^(来|说)(点|句|段)骚话$/)
35
35
  .action(async (ctx) => {
36
- const hitokoto = await (0, service_1.getHitokoto)();
36
+ const hitokoto = await (0, service_1.getHitokoto)(ctx.option?.param);
37
37
  ctx.reply(hitokoto);
38
38
  });
package/lib/service.js CHANGED
@@ -3,22 +3,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getHitokoto = exports.api = void 0;
6
+ exports.getHitokoto = void 0;
7
7
  const axios_1 = __importDefault(require("axios"));
8
- // import { Hitokoto } from './type';
9
- // 定时发送任务
10
- exports.api = 'https://v1.hitokoto.cn';
8
+ const api = 'https://v1.hitokoto.cn';
11
9
  async function getHitokoto(param = '') {
12
- let message = '';
13
- await axios_1.default.get(exports.api + param)
14
- .then(response => {
15
- const { data } = response;
10
+ let message;
11
+ try {
12
+ const { data } = await axios_1.default.get(api + param);
16
13
  const { hitokoto, from } = data;
17
14
  message = `${hitokoto}\n\t\t\t\t———— 「${from}」`;
18
- })
19
- .catch(error => {
15
+ }
16
+ catch (error) {
20
17
  message = error.message;
21
- });
18
+ }
22
19
  return message;
23
20
  }
24
21
  exports.getHitokoto = getHitokoto;
package/package.json CHANGED
@@ -1,29 +1,31 @@
1
- {
2
- "name": "kokkoro-plugin-hitokoto",
3
- "version": "0.3.0",
4
- "description": "ヒトコト",
5
- "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
- },
13
- "keywords": [
14
- "kokkoro"
15
- ],
16
- "author": "yuki",
17
- "license": "MIT",
18
- "bugs": {
19
- "url": "https://github.com/kokkorojs/kokkoro-plugin-hitokoto/issues"
20
- },
21
- "homepage": "https://github.com/kokkorojs/kokkoro-plugin-hitokoto#readme",
22
- "devDependencies": {
23
- "@types/node": "^17.0.23",
24
- "kokkoro": "^0.3.0"
25
- },
26
- "files": [
27
- "lib"
28
- ]
29
- }
1
+ {
2
+ "name": "kokkoro-plugin-hitokoto",
3
+ "version": "1.0.0",
4
+ "description": "ヒトコト",
5
+ "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
+ },
13
+ "keywords": [
14
+ "kokkoro",
15
+ "hitokoto"
16
+ ],
17
+ "author": "yuki <mail@yuki.sh>",
18
+ "license": "MIT",
19
+ "bugs": {
20
+ "url": "https://github.com/kokkorojs/kokkoro-plugin-hitokoto/issues"
21
+ },
22
+ "homepage": "https://github.com/kokkorojs/kokkoro-plugin-hitokoto#readme",
23
+ "devDependencies": {
24
+ "@types/node": "^18.11.9",
25
+ "axios": "^1.1.3",
26
+ "kokkoro": "^1.1.0"
27
+ },
28
+ "files": [
29
+ "lib"
30
+ ]
31
+ }
package/lib/type.js DELETED
@@ -1,48 +0,0 @@
1
- "use strict";
2
- // import { Option } from 'kokkoro';
3
- // export interface HitokotoOption extends Option {
4
- // auto_send: boolean;
5
- // param: string;
6
- // }
7
- // export interface Hitokoto {
8
- // // 一言标识
9
- // id: string;
10
- // // 一言正文 编码方式 unicode 使用 utf-8
11
- // hitokoto: string;
12
- // // 类型
13
- // type: string;
14
- // // 一言的出处
15
- // from: string;
16
- // // 一言的作者
17
- // from_who: string;
18
- // // 添加者
19
- // creator: string;
20
- // // 添加者用户标识
21
- // creator_uid: string;
22
- // // 审核员标识
23
- // reviewer: string;
24
- // // 一言唯一标识;可以链接到 https://hitokoto.cn?uuid=[uuid] (opens new window)查看这个一言的完整信息
25
- // uuid: string;
26
- // // 提交方式
27
- // commit_from: string;
28
- // // 添加时间
29
- // created_at: string;
30
- // // 句子长度
31
- // length: number;
32
- // }
33
- // export interface HitokotoParam {
34
- // // 句子类型
35
- // c: string;
36
- // // 返回编码
37
- // encode: 'text' | 'json' | 'js' | string;
38
- // // 字符集
39
- // charset: 'utf-8' | 'gbk ' | string;
40
- // // 调用的异步函数
41
- // callback: string;
42
- // // 选择器。配合 encode=js 使用
43
- // select: string;
44
- // // 返回句子的最小长度(包含)
45
- // min_length: number;
46
- // // 返回句子的最大长度(包含)
47
- // max_length: number;
48
- // }