kokkoro-plugin-hitokoto 0.2.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 +4 -4
- package/lib/index.js +24 -21
- package/lib/service.js +8 -10
- package/package.json +4 -4
- package/lib/type.js +0 -2
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) 成功运行并登录后,发送 `
|
|
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
|
-
```
|
|
21
|
-
interface
|
|
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
|
@@ -1,35 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.plugin = void 0;
|
|
4
3
|
const kokkoro_1 = require("kokkoro");
|
|
5
4
|
const service_1 = require("./service");
|
|
6
|
-
const
|
|
5
|
+
const setting = {
|
|
7
6
|
apply: true,
|
|
8
7
|
lock: false,
|
|
9
8
|
auto_send: true,
|
|
10
9
|
param: '?c=a&c=b&c=c',
|
|
11
10
|
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const {
|
|
23
|
-
|
|
24
|
-
|
|
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
25
|
}
|
|
26
|
+
plugin.botApi(uin, 'sendGroupMsg', group_id, hitokoto);
|
|
26
27
|
});
|
|
27
|
-
}
|
|
28
|
-
})
|
|
29
|
-
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
plugin
|
|
31
|
+
.command('say')
|
|
30
32
|
.description('发送一言')
|
|
31
33
|
.sugar(/^(来|说)(点|句|段)骚话$/)
|
|
32
|
-
.action(async
|
|
33
|
-
const
|
|
34
|
-
|
|
34
|
+
.action(async (ctx) => {
|
|
35
|
+
const param = ctx.setting?.param;
|
|
36
|
+
const hitokoto = await (0, service_1.getHitokoto)(param);
|
|
37
|
+
ctx.reply(hitokoto);
|
|
35
38
|
});
|
package/lib/service.js
CHANGED
|
@@ -3,21 +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 =
|
|
6
|
+
exports.getHitokoto = void 0;
|
|
7
7
|
const axios_1 = __importDefault(require("axios"));
|
|
8
|
-
|
|
9
|
-
exports.api = 'https://v1.hitokoto.cn';
|
|
8
|
+
const api = 'https://v1.hitokoto.cn';
|
|
10
9
|
async function getHitokoto(param = '') {
|
|
11
|
-
let message
|
|
12
|
-
|
|
13
|
-
.
|
|
14
|
-
const { data } = response;
|
|
10
|
+
let message;
|
|
11
|
+
try {
|
|
12
|
+
const { data } = await axios_1.default.get(api + param);
|
|
15
13
|
const { hitokoto, from } = data;
|
|
16
14
|
message = `${hitokoto}\n\t\t\t\t———— 「${from}」`;
|
|
17
|
-
}
|
|
18
|
-
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
19
17
|
message = error.message;
|
|
20
|
-
}
|
|
18
|
+
}
|
|
21
19
|
return message;
|
|
22
20
|
}
|
|
23
21
|
exports.getHitokoto = getHitokoto;
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kokkoro-plugin-hitokoto",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "ヒトコト",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
8
|
},
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
},
|
|
21
21
|
"homepage": "https://github.com/kokkorojs/kokkoro-plugin-hitokoto#readme",
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@types/node": "^
|
|
24
|
-
"kokkoro": "^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