kokkoro-plugin-hitokoto 0.3.0 → 0.3.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/README.md CHANGED
@@ -12,16 +12,16 @@ cd bot
12
12
  npm i kokkoro-plugin-hitokoto
13
13
  ```
14
14
 
15
- 在 [kokkoro](https://github.com/kokkorojs/kokkoro) 成功运行并登录后,发送 `enable hitokoto` 即可为 bot 启用插件
15
+ 在 [kokkoro](https://github.com/kokkorojs/kokkoro) 成功运行并登录后,发送 `mount hitokoto` 即可为 bot 挂载插件
16
16
  使用 `hitokoto update <key> <value>` 可修改当前群聊的插件参数,例如关闭每日自动发送 `hitokoto update auto_send false`
17
17
 
18
18
  ## 参数
19
19
 
20
- ``` typescript
21
- interface HitokotoOption {
20
+ ```typescript
21
+ interface HitokotoSetting {
22
22
  // 在每天凌晨自动发送
23
23
  auto_send: boolean;
24
- // 一言接口 get 请求参数
24
+ // 一言接口 get 请求参数,默认 "?c=a&c=b&c=c"
25
25
  param: string;
26
26
  }
27
27
  ```
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 setting = {
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', setting);
14
13
  plugin
15
- .version(version);
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
+ });
16
30
  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
31
  .command('say')
33
32
  .description('发送一言')
34
33
  .sugar(/^(来|说)(点|句|段)骚话$/)
35
34
  .action(async (ctx) => {
36
- const hitokoto = await (0, service_1.getHitokoto)();
35
+ const param = ctx.setting?.param;
36
+ const hitokoto = await (0, service_1.getHitokoto)(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,6 +1,6 @@
1
1
  {
2
2
  "name": "kokkoro-plugin-hitokoto",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "ヒトコト",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -20,8 +20,8 @@
20
20
  },
21
21
  "homepage": "https://github.com/kokkorojs/kokkoro-plugin-hitokoto#readme",
22
22
  "devDependencies": {
23
- "@types/node": "^17.0.23",
24
- "kokkoro": "^0.3.0"
23
+ "@types/node": "^18.8.5",
24
+ "kokkoro": "^1.0.4"
25
25
  },
26
26
  "files": [
27
27
  "lib"
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
- // }