kokkoro-plugin-hitokoto 0.1.0 → 0.2.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 +3 -3
- package/lib/index.js +29 -54
- package/lib/service.js +2 -2
- package/package.json +3 -7
package/README.md
CHANGED
|
@@ -12,8 +12,8 @@ cd bot
|
|
|
12
12
|
npm i kokkoro-plugin-hitokoto
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
在 [kokkoro](https://github.com/kokkorojs/kokkoro) 成功运行并登录后,发送
|
|
16
|
-
使用
|
|
15
|
+
在 [kokkoro](https://github.com/kokkorojs/kokkoro) 成功运行并登录后,发送 `enable hitokoto` 即可为 bot 启用插件
|
|
16
|
+
使用 `hitokoto update <key> <value>` 可修改当前群聊的插件参数,例如关闭每日自动发送 `hitokoto update auto_send false`
|
|
17
17
|
|
|
18
18
|
## 参数
|
|
19
19
|
|
|
@@ -22,7 +22,7 @@ interface HitokotoOption {
|
|
|
22
22
|
// 在每天凌晨自动发送
|
|
23
23
|
auto_send: boolean;
|
|
24
24
|
// 一言接口 get 请求参数
|
|
25
|
-
|
|
25
|
+
param: string;
|
|
26
26
|
}
|
|
27
27
|
```
|
|
28
28
|
|
package/lib/index.js
CHANGED
|
@@ -1,60 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
3
|
+
exports.plugin = void 0;
|
|
4
4
|
const kokkoro_1 = require("kokkoro");
|
|
5
5
|
const service_1 = require("./service");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return (0, node_schedule_1.scheduleJob)('0 0 0 * * ?', async () => {
|
|
27
|
-
const uin = this.bot.uin;
|
|
28
|
-
const gl = this.bot.getGroupList();
|
|
29
|
-
const message = await (0, service_1.getHitokoto)();
|
|
30
|
-
const setting = (0, kokkoro_1.getSetting)(uin);
|
|
31
|
-
// 判断开启服务的群
|
|
32
|
-
gl.forEach(async (group) => {
|
|
33
|
-
const { group_id, group_name } = group;
|
|
34
|
-
const { apply, auto_send } = setting[group_id].plugin.hitokoto;
|
|
35
|
-
if (apply && auto_send) {
|
|
36
|
-
this.bot.sendGroupMsg(group_id, message)
|
|
37
|
-
.catch(error => {
|
|
38
|
-
this.bot.logger.error(`Error: ${group_name}(${group_id}) 消息发送失败,${error.message}`);
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
});
|
|
6
|
+
const option = {
|
|
7
|
+
apply: true,
|
|
8
|
+
lock: false,
|
|
9
|
+
auto_send: true,
|
|
10
|
+
param: '?c=a&c=b&c=c',
|
|
11
|
+
};
|
|
12
|
+
exports.plugin = new kokkoro_1.Plugin('hitokoto', option).version(require('../package.json').version);
|
|
13
|
+
exports.plugin
|
|
14
|
+
.schedule('0 0 0 * * ?', async () => {
|
|
15
|
+
const bot_list = (0, kokkoro_1.getBotList)();
|
|
16
|
+
const hitokoto = await (0, service_1.getHitokoto)(option.param);
|
|
17
|
+
for (const [_, bot] of bot_list) {
|
|
18
|
+
const group_list = bot.getGroupList();
|
|
19
|
+
// 判断开启服务的群
|
|
20
|
+
group_list.forEach(async (group) => {
|
|
21
|
+
const { group_id } = group;
|
|
22
|
+
const { apply, auto_send } = bot.getOption(group_id, 'hitokoto');
|
|
23
|
+
if (apply && auto_send) {
|
|
24
|
+
bot.sendGroupMsg(group_id, hitokoto);
|
|
25
|
+
}
|
|
42
26
|
});
|
|
43
27
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const raw_message = event.raw_message;
|
|
53
|
-
const option = (0, kokkoro_1.getOption)(event);
|
|
54
|
-
const order = (0, kokkoro_1.getOrder)(this.orders, raw_message);
|
|
55
|
-
if (option.apply) {
|
|
56
|
-
order && order.call(this, event, option);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
exports.default = Hitokoto;
|
|
28
|
+
})
|
|
29
|
+
.command('say', 'group')
|
|
30
|
+
.description('发送一言')
|
|
31
|
+
.sugar(/^(来|说)(点|句|段)骚话$/)
|
|
32
|
+
.action(async function () {
|
|
33
|
+
const hitokoto = await (0, service_1.getHitokoto)(this.option.param);
|
|
34
|
+
this.event.reply(hitokoto);
|
|
35
|
+
});
|
package/lib/service.js
CHANGED
|
@@ -7,9 +7,9 @@ exports.getHitokoto = exports.api = void 0;
|
|
|
7
7
|
const axios_1 = __importDefault(require("axios"));
|
|
8
8
|
// 定时发送任务
|
|
9
9
|
exports.api = 'https://v1.hitokoto.cn';
|
|
10
|
-
async function getHitokoto(
|
|
10
|
+
async function getHitokoto(param = '') {
|
|
11
11
|
let message = '';
|
|
12
|
-
await axios_1.default.get(exports.api +
|
|
12
|
+
await axios_1.default.get(exports.api + param)
|
|
13
13
|
.then(response => {
|
|
14
14
|
const { data } = response;
|
|
15
15
|
const { hitokoto, from } = data;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kokkoro-plugin-hitokoto",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "ヒトコト",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -19,13 +19,9 @@
|
|
|
19
19
|
"url": "https://github.com/kokkorojs/kokkoro-plugin-hitokoto/issues"
|
|
20
20
|
},
|
|
21
21
|
"homepage": "https://github.com/kokkorojs/kokkoro-plugin-hitokoto#readme",
|
|
22
|
-
"dependencies": {
|
|
23
|
-
"node-schedule": "^2.1.0"
|
|
24
|
-
},
|
|
25
22
|
"devDependencies": {
|
|
26
|
-
"@types/node": "^17.0.
|
|
27
|
-
"
|
|
28
|
-
"kokkoro": "^0.2.0"
|
|
23
|
+
"@types/node": "^17.0.23",
|
|
24
|
+
"kokkoro": "^0.3.0"
|
|
29
25
|
},
|
|
30
26
|
"files": [
|
|
31
27
|
"lib"
|