kokkoro-plugin-hitokoto 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 yuki
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # kokkoro-hitokoto
2
+
3
+ > ヒトコト
4
+
5
+ ## 安装
6
+
7
+ ``` shell
8
+ # 切换至 bot 目录
9
+ cd bot
10
+
11
+ # 安装 npm 包
12
+ npm i kokkoro-plugin-hitokoto
13
+ ```
14
+
15
+ 在 [kokkoro](https://github.com/kokkorojs/kokkoro) 成功运行并登录后,发送 `>enable hitokoto` 即可启用插件
16
+ 使用 `>hitokoto <key> <value>` 可修改当前群聊的插件参数,例如关闭每日自动发送 `>hitokoto auto_send false`
17
+
18
+ ## 参数
19
+
20
+ ``` typescript
21
+ interface HitokotoOption {
22
+ // 在每天凌晨自动发送
23
+ auto_send: boolean;
24
+ // 一言接口 get 请求参数
25
+ get_param: string;
26
+ }
27
+ ```
28
+
29
+ 更多参数可查看 [hitokoto](https://developer.hitokoto.cn/sentence/#%E8%AF%B7%E6%B1%82%E5%8F%82%E6%95%B0) 官方文档
package/lib/index.js ADDED
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const node_schedule_1 = require("node-schedule");
4
+ const kokkoro_1 = require("kokkoro");
5
+ const service_1 = require("./service");
6
+ class Hitokoto {
7
+ constructor(bot) {
8
+ this.option = {
9
+ auto_send: true,
10
+ get_param: '?c=a&c=b&c=c',
11
+ };
12
+ this.orders = [
13
+ {
14
+ func: this.sendHitokoto,
15
+ regular: /^(来|说)(点|句|段)骚话$/,
16
+ },
17
+ ];
18
+ this.bot = bot;
19
+ this.send_job = this.autoSend();
20
+ }
21
+ async sendHitokoto(event, option) {
22
+ const message = await (0, service_1.getHitokoto)(option.get_param);
23
+ event.reply(message);
24
+ }
25
+ autoSend() {
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
+ });
42
+ });
43
+ }
44
+ // 销毁定时任务
45
+ cancelSchedule() {
46
+ this.send_job.cancel();
47
+ }
48
+ onDestroy() {
49
+ this.cancelSchedule();
50
+ }
51
+ onGroupMessage(event) {
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;
package/lib/service.js ADDED
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getHitokoto = exports.api = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ // 定时发送任务
9
+ exports.api = 'https://v1.hitokoto.cn';
10
+ async function getHitokoto(get_param = '') {
11
+ let message = '';
12
+ await axios_1.default.get(exports.api + get_param)
13
+ .then(response => {
14
+ const { data } = response;
15
+ const { hitokoto, from } = data;
16
+ message = `${hitokoto}\n\t\t\t\t———— 「${from}」`;
17
+ })
18
+ .catch(error => {
19
+ message = error.message;
20
+ });
21
+ return message;
22
+ }
23
+ exports.getHitokoto = getHitokoto;
package/lib/type.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "kokkoro-plugin-hitokoto",
3
+ "version": "0.1.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
+ ],
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
+ "dependencies": {
23
+ "node-schedule": "^2.1.0"
24
+ },
25
+ "devDependencies": {
26
+ "@types/node": "^17.0.21",
27
+ "@types/node-schedule": "^1.3.2",
28
+ "kokkoro": "^0.2.0"
29
+ },
30
+ "files": [
31
+ "lib"
32
+ ]
33
+ }