kokkoro-plugin-hitokoto 1.2.0 → 1.3.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/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const kokkoro_1 = require("kokkoro");
3
+ const core_1 = require("@kokkoro/core");
4
4
  const service_1 = require("./service");
5
5
  const option = {
6
6
  apply: true,
@@ -8,28 +8,13 @@ const option = {
8
8
  auto_send: true,
9
9
  param: '?c=a&c=b&c=c',
10
10
  };
11
- const { version } = require('../package.json');
12
- const plugin = new kokkoro_1.Plugin('hitokoto', option);
13
- const service = new service_1.HitokotoService();
11
+ const pkg = require('../package.json');
12
+ const plugin = new core_1.Plugin('hitokoto', option);
13
+ const service = new service_1.Service(plugin);
14
14
  plugin
15
- .version(version)
15
+ .version(pkg.version)
16
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
- });
17
+ await service.autoSend();
33
18
  });
34
19
  plugin
35
20
  .command('say')
package/lib/service.js CHANGED
@@ -3,12 +3,16 @@ 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.HitokotoService = void 0;
6
+ exports.Service = void 0;
7
7
  const axios_1 = __importDefault(require("axios"));
8
- class HitokotoService {
8
+ class Service {
9
+ plugin;
9
10
  /** API */
10
11
  api;
11
- constructor() {
12
+ constructor(
13
+ /** 插件 */
14
+ plugin) {
15
+ this.plugin = plugin;
12
16
  this.api = 'https://v1.hitokoto.cn';
13
17
  }
14
18
  async getHitokoto(param = '') {
@@ -23,5 +27,23 @@ class HitokotoService {
23
27
  }
24
28
  return message;
25
29
  }
30
+ async autoSend() {
31
+ const hitokoto = await this.getHitokoto();
32
+ this.plugin.bl.forEach((bot) => {
33
+ const sendQueue = [];
34
+ const uins = [...bot.gl.keys()];
35
+ const uins_length = uins.length;
36
+ for (let i = 0; i < uins_length; i++) {
37
+ const uin = uins[i];
38
+ const info = bot.gl.get(uin);
39
+ const { group_id } = info;
40
+ const { apply, auto_send } = bot.profile.getOption(group_id, 'hitokoto');
41
+ if (apply && auto_send) {
42
+ sendQueue.push(bot.sendGroupMsg(group_id, hitokoto));
43
+ }
44
+ }
45
+ Promise.allSettled(sendQueue);
46
+ });
47
+ }
26
48
  }
27
- exports.HitokotoService = HitokotoService;
49
+ exports.Service = Service;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kokkoro-plugin-hitokoto",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "ヒトコト",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -21,9 +21,9 @@
21
21
  },
22
22
  "homepage": "https://github.com/kokkorojs/kokkoro-plugin-hitokoto#readme",
23
23
  "devDependencies": {
24
- "@types/node": "^18.11.19",
25
- "axios": "^1.3.2",
26
- "kokkoro": "^2.0.0-alpha.1"
24
+ "@kokkoro/core": "^2.0.1",
25
+ "@types/node": "^18.14.0",
26
+ "axios": "^1.3.3"
27
27
  },
28
28
  "files": [
29
29
  "lib"