kokkoro-plugin-hitokoto 0.3.1 → 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) 成功运行并登录后,发送 `mount hitokoto` 即可为 bot 挂载插件
16
- 使用 `hitokoto update <key> <value>` 可修改当前群聊的插件参数,例如关闭每日自动发送 `hitokoto update auto_send false`
17
-
18
15
  ## 参数
19
16
 
20
17
  ```typescript
21
- interface HitokotoSetting {
22
- // 在每天凌晨自动发送
18
+ interface HitokotoOption extends Option {
19
+ /** 在每天凌晨自动发送 */
23
20
  auto_send: boolean;
24
- // 一言接口 get 请求参数,默认 "?c=a&c=b&c=c"
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
- const setting = {
5
+ const option = {
6
6
  apply: true,
7
7
  lock: false,
8
8
  auto_send: true,
9
9
  param: '?c=a&c=b&c=c',
10
10
  };
11
11
  const { version } = require('../package.json');
12
- const plugin = new kokkoro_1.Plugin('hitokoto', setting);
12
+ const plugin = new kokkoro_1.Plugin('hitokoto', option);
13
13
  plugin
14
14
  .version(version)
15
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) => {
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];
19
21
  const gl = await plugin.botApi(uin, 'gl');
20
22
  gl.forEach(async (info) => {
21
23
  const { group_id } = info;
22
- const { apply } = await plugin.botApi(uin, 'getSetting', group_id, 'hitokoto');
23
- if (!apply) {
24
- return;
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);
25
27
  }
26
- plugin.botApi(uin, 'sendGroupMsg', group_id, hitokoto);
27
28
  });
28
- });
29
+ }
29
30
  });
30
31
  plugin
31
32
  .command('say')
32
33
  .description('发送一言')
33
34
  .sugar(/^(来|说)(点|句|段)骚话$/)
34
35
  .action(async (ctx) => {
35
- const param = ctx.setting?.param;
36
- const hitokoto = await (0, service_1.getHitokoto)(param);
36
+ const hitokoto = await (0, service_1.getHitokoto)(ctx.option?.param);
37
37
  ctx.reply(hitokoto);
38
38
  });
package/package.json CHANGED
@@ -1,29 +1,31 @@
1
- {
2
- "name": "kokkoro-plugin-hitokoto",
3
- "version": "0.3.1",
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": "^18.8.5",
24
- "kokkoro": "^1.0.4"
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
+ }