kokkoro-plugin-kfc 0.0.2 → 1.0.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 +11 -0
- package/lib/index.js +9 -5
- package/lib/service.js +26 -4
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -14,6 +14,17 @@ npm i kokkoro-plugin-kfc
|
|
|
14
14
|
|
|
15
15
|
有关键字 `v50` 就会自动发送段子
|
|
16
16
|
|
|
17
|
+
## 环境变量
|
|
18
|
+
|
|
19
|
+
你可以在项目根目录下创建 `.env` 文件,修改 `KFC_DATE` 变量来自定义自动发送的时间,默认 `0 0 12 * * 4`(每周四中午十二点)
|
|
20
|
+
|
|
21
|
+
```ini
|
|
22
|
+
# KFC 时间
|
|
23
|
+
KFC_DATE=0 0 12 * * 4
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
因为插件的定时任务是在初始化时创建的,所以如果你修改了 `KFC_DATE` 变量,需要使用 `reload` 指令将其重新挂载才能生效。
|
|
27
|
+
|
|
17
28
|
## 鸣谢
|
|
18
29
|
|
|
19
30
|
https://github.com/whitescent/KFC-Crazy-Thursday
|
package/lib/index.js
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
3
|
+
const core_1 = require("@kokkoro/core");
|
|
4
4
|
const service_1 = require("./service");
|
|
5
5
|
const option = {
|
|
6
6
|
apply: true,
|
|
7
7
|
lock: false,
|
|
8
|
+
auto_send: true,
|
|
8
9
|
};
|
|
9
|
-
const
|
|
10
|
-
const plugin = new
|
|
11
|
-
const service = new service_1.
|
|
10
|
+
const pkg = require('../package.json');
|
|
11
|
+
const plugin = new core_1.Plugin('kfc', option);
|
|
12
|
+
const service = new service_1.Service(plugin);
|
|
12
13
|
plugin
|
|
13
|
-
.version(version)
|
|
14
|
+
.version(pkg.version)
|
|
15
|
+
.schedule(process.env.KFC_DATE ?? '0 0 12 * * 4', async () => {
|
|
16
|
+
await service.autoSend();
|
|
17
|
+
});
|
|
14
18
|
plugin
|
|
15
19
|
.command('say')
|
|
16
20
|
.description('v50 看看实力')
|
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.
|
|
6
|
+
exports.Service = void 0;
|
|
7
7
|
const axios_1 = __importDefault(require("axios"));
|
|
8
|
-
class
|
|
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://kfc.yuki.sh/api/index';
|
|
13
17
|
}
|
|
14
18
|
async getMessage() {
|
|
@@ -22,5 +26,23 @@ class KFCService {
|
|
|
22
26
|
}
|
|
23
27
|
return message;
|
|
24
28
|
}
|
|
29
|
+
async autoSend() {
|
|
30
|
+
const message = await this.getMessage();
|
|
31
|
+
this.plugin.bl.forEach((bot) => {
|
|
32
|
+
const sendQueue = [];
|
|
33
|
+
const uins = [...bot.gl.keys()];
|
|
34
|
+
const uins_length = uins.length;
|
|
35
|
+
for (let i = 0; i < uins_length; i++) {
|
|
36
|
+
const uin = uins[i];
|
|
37
|
+
const info = bot.gl.get(uin);
|
|
38
|
+
const { group_id } = info;
|
|
39
|
+
const { apply, auto_send } = bot.profile.getOption(group_id, 'message');
|
|
40
|
+
if (apply && auto_send) {
|
|
41
|
+
sendQueue.push(bot.sendGroupMsg(group_id, message));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
Promise.allSettled(sendQueue);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
25
47
|
}
|
|
26
|
-
exports.
|
|
48
|
+
exports.Service = Service;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kokkoro-plugin-kfc",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "肯德基疯狂星期四段子",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
},
|
|
21
21
|
"homepage": "https://github.com/kokkorojs/kokkoro-plugin-kfc#readme",
|
|
22
22
|
"devDependencies": {
|
|
23
|
+
"@kokkoro/core": "^2.0.1",
|
|
23
24
|
"@types/node": "^18.11.19",
|
|
24
|
-
"axios": "^1.3.2"
|
|
25
|
-
"kokkoro": "^2.0.0-alpha.1"
|
|
25
|
+
"axios": "^1.3.2"
|
|
26
26
|
},
|
|
27
27
|
"files": [
|
|
28
28
|
"lib"
|