From 9e72d2b1231e6c5fec530f228af56039b66e9373 Mon Sep 17 00:00:00 2001 From: yuki Date: Wed, 22 Feb 2023 15:12:47 +0800 Subject: [PATCH] feat: add core --- package.json | 9 +- pnpm-lock.yaml | 141 +++++++++++++++++++------------ src/controller/bot.controller.ts | 6 +- src/service/bot.service.ts | 26 +++--- src/service/plugin.service.ts | 2 +- 5 files changed, 108 insertions(+), 76 deletions(-) diff --git a/package.json b/package.json index 177900a..ff7ec83 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kokkoro/web", - "version": "0.1.3", + "version": "0.1.4", "description": "Create web serve for kokkoro.", "main": "lib/index.js", "types": "lib/index.d.ts", @@ -30,15 +30,16 @@ "uuid": "^9.0.0" }, "devDependencies": { + "@kokkoro/core": "^2.0.1", "@kokkoro/database": "^1.0.1", "@kokkoro/utils": "^0.6.0", "@types/jsonwebtoken": "^9.0.1", "@types/koa": "^2.13.5", "@types/koa-static": "^4.0.2", - "@types/koa__cors": "^3.3.0", + "@types/koa__cors": "^3.3.1", "@types/koa__router": "^12.0.0", - "@types/uuid": "^9.0.0", - "kokkoro": "^2.0.0-alpha.7" + "@types/uuid": "^9.0.1", + "kokkoro": "^2.0.0-alpha.9" }, "files": [ "lib" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e5df994..24c108d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3,19 +3,20 @@ lockfileVersion: 5.4 specifiers: '@koa/cors': ^4.0.0 '@koa/router': ^12.0.0 + '@kokkoro/core': ^2.0.1 '@kokkoro/database': ^1.0.1 '@kokkoro/utils': ^0.6.0 '@types/jsonwebtoken': ^9.0.1 '@types/koa': ^2.13.5 '@types/koa-static': ^4.0.2 - '@types/koa__cors': ^3.3.0 + '@types/koa__cors': ^3.3.1 '@types/koa__router': ^12.0.0 - '@types/uuid': ^9.0.0 + '@types/uuid': ^9.0.1 jsonwebtoken: ^9.0.0 koa: ^2.14.1 koa-body: ^6.0.1 koa-static: ^5.0.0 - kokkoro: ^2.0.0-alpha.7 + kokkoro: ^2.0.0-alpha.9 uuid: ^9.0.0 dependencies: @@ -28,15 +29,16 @@ dependencies: uuid: 9.0.0 devDependencies: + '@kokkoro/core': 2.0.1 '@kokkoro/database': 1.0.1 '@kokkoro/utils': 0.6.0 '@types/jsonwebtoken': 9.0.1 '@types/koa': 2.13.5 '@types/koa-static': 4.0.2 - '@types/koa__cors': 3.3.0 + '@types/koa__cors': 3.3.1 '@types/koa__router': 12.0.0 - '@types/uuid': 9.0.0 - kokkoro: 2.0.0-alpha.7 + '@types/uuid': 9.0.1 + kokkoro: 2.0.0-alpha.9 packages: @@ -60,6 +62,19 @@ packages: engines: {node: '>=16.0.0', npm: '>= 7.0.0'} dev: true + /@kokkoro/core/2.0.1: + resolution: {integrity: sha512-/yC0pP7hxDuH3ceupwrZm66FU0iEMixwTXXoHnYwbBa8MvdOSju0jnOLVAcCYbxnHAVRjsmrfpmopKTorIrfvw==} + engines: {node: '>= v15'} + dependencies: + '@kokkoro/utils': 0.7.1 + amesu: 1.3.0 + cron: 2.2.0 + jsqr: 1.4.0 + transitivePeerDependencies: + - debug + - supports-color + dev: true + /@kokkoro/database/1.0.1: resolution: {integrity: sha512-XYqRXWaZmSbWAwTWxv9cXyQAsdzMVr8Q1FyRy+1rfKFHqYb5Qtu11ImMdTzKtu2DTcXTzpNAWxtC1HV0xhpUFQ==} dependencies: @@ -77,8 +92,8 @@ packages: public-ip: 4.0.4 dev: true - /@kokkoro/web/0.1.2: - resolution: {integrity: sha512-vn/WhAHYFko5L6EpSzhE1eakGXc5PD6qNuoafapmwOoqmzWfriJi+6d6/eo4B4eijzjgIqirHjF/dnBTfq/FBw==} + /@kokkoro/web/0.1.3: + resolution: {integrity: sha512-295i6Tn+aW69nCrSdJBZ5EKXltGgE0vWfydjIvNPjUSHVgDq4FG4e0A8q64jNZjYO3fosQGINkuu/6L7eOCoqA==} dependencies: '@koa/cors': 4.0.0 '@koa/router': 12.0.0 @@ -110,24 +125,24 @@ packages: /@types/accepts/1.3.5: resolution: {integrity: sha512-jOdnI/3qTpHABjM5cx1Hc0sKsPoYCp+DP/GJRGtDlPd7fiV9oXGGIcjW/ZOxLIvjGz8MA+uMZI9metHlgqbgwQ==} dependencies: - '@types/node': 18.13.0 + '@types/node': 18.14.0 /@types/body-parser/1.19.2: resolution: {integrity: sha512-ALYone6pm6QmwZoAgeyNksccT9Q4AWZQ6PvfwR37GT6r6FWUPguq6sUmNGSMV2Wr761oQoBxwGGa6DR5o1DC9g==} dependencies: '@types/connect': 3.4.35 - '@types/node': 18.13.0 + '@types/node': 18.14.0 /@types/co-body/6.1.0: resolution: {integrity: sha512-3e0q2jyDAnx/DSZi0z2H0yoZ2wt5yRDZ+P7ymcMObvq0ufWRT4tsajyO+Q1VwVWiv9PRR4W3YEjEzBjeZlhF+w==} dependencies: - '@types/node': 18.13.0 + '@types/node': 18.14.0 '@types/qs': 6.9.7 /@types/connect/3.4.35: resolution: {integrity: sha512-cdeYyv4KWoEgpBISTxWvqYsVy444DOqehiF3fM3ne10AmJ62RSyNkUnxMJXHQWRQQX2eR94m5y1IZyDwBjV9FQ==} dependencies: - '@types/node': 18.13.0 + '@types/node': 18.14.0 /@types/content-disposition/0.5.5: resolution: {integrity: sha512-v6LCdKfK6BwcqMo+wYW05rLS12S0ZO0Fl4w1h4aaZMD7bqT3gVUns6FvLJKGZHQmYn3SX55JWGpziwJRwVgutA==} @@ -138,12 +153,12 @@ packages: '@types/connect': 3.4.35 '@types/express': 4.17.17 '@types/keygrip': 1.0.2 - '@types/node': 18.13.0 + '@types/node': 18.14.0 /@types/express-serve-static-core/4.17.33: resolution: {integrity: sha512-TPBqmR/HRYI3eC2E5hmiivIzv+bidAfXofM+sbonAGvyDhySGw9/PQZFt2BLOrjUUR++4eJVpx6KnLQK1Fk9tA==} dependencies: - '@types/node': 18.13.0 + '@types/node': 18.14.0 '@types/qs': 6.9.7 '@types/range-parser': 1.2.4 @@ -158,7 +173,7 @@ packages: /@types/formidable/2.0.5: resolution: {integrity: sha512-uvMcdn/KK3maPOaVUAc3HEYbCEhjaGFwww4EsX6IJfWIJ1tzHtDHczuImH3GKdusPnAAmzB07St90uabZeCKPA==} dependencies: - '@types/node': 18.13.0 + '@types/node': 18.14.0 /@types/http-assert/1.5.3: resolution: {integrity: sha512-FyAOrDuQmBi8/or3ns4rwPno7/9tJTijVW6aQQjK02+kOQ8zmoNg2XJtAuQhvQcy1ASJq38wirX5//9J1EqoUA==} @@ -169,7 +184,7 @@ packages: /@types/jsonwebtoken/9.0.1: resolution: {integrity: sha512-c5ltxazpWabia/4UzhIoaDcIza4KViOQhdbjRlfcIGVnsE3c3brkz9Z+F/EeJIECOQP7W7US2hNE930cWWkPiw==} dependencies: - '@types/node': 18.13.0 + '@types/node': 18.14.0 dev: true /@types/keygrip/1.0.2: @@ -178,7 +193,7 @@ packages: /@types/keyv/3.1.4: resolution: {integrity: sha512-BQ5aZNSCpj7D6K2ksrRCTmKRLEpnPvWDiLPfoGyhZ++8YtiK9d/3DBKPJgry359X/P1PfruyYwvnvwFjuEiEIg==} dependencies: - '@types/node': 18.13.0 + '@types/node': 18.14.0 dev: true /@types/koa-compose/3.2.5: @@ -209,10 +224,10 @@ packages: '@types/http-errors': 2.0.1 '@types/keygrip': 1.0.2 '@types/koa-compose': 3.2.5 - '@types/node': 18.13.0 + '@types/node': 18.14.0 - /@types/koa__cors/3.3.0: - resolution: {integrity: sha512-FUN8YxcBakIs+walVe3+HcNP+Bxd0SB8BJHBWkglZ5C1XQWljlKcEFDG/dPiCIqwVCUbc5X0nYDlH62uEhdHMA==} + /@types/koa__cors/3.3.1: + resolution: {integrity: sha512-aFGYhTFW7651KhmZZ05VG0QZJre7QxBxDj2LF1lf6GA/wSXEfKVAJxiQQWzRV4ZoMzQIO8vJBXKsUcRuvYK9qw==} dependencies: '@types/koa': 2.13.5 dev: true @@ -226,8 +241,8 @@ packages: /@types/mime/3.0.1: resolution: {integrity: sha512-Y4XFY5VJAuw0FgAqPNd6NNoV44jbq9Bz2L7Rh/J6jLTiHBSBJa9fxqQIvkIld4GsoDOcCbvzOUAbLPsSKKg+uA==} - /@types/node/18.13.0: - resolution: {integrity: sha512-gC3TazRzGoOnoKAhUx+Q0t8S9Tzs74z7m0ipwGpSqQrleP14hKxP4/JUeEQcD3W1/aIpnWl8pHowI7WokuZpXg==} + /@types/node/18.14.0: + resolution: {integrity: sha512-5EWrvLmglK+imbCJY0+INViFWUHg1AHel1sq4ZVSfdcNqGy9Edv3UB9IIzzg+xPaUcAgZYcfVs2fBcwDeZzU0A==} /@types/qs/6.9.7: resolution: {integrity: sha512-FGa1F62FT09qcrueBA6qYTrJPVDzah9a+493+o2PCXsesWHIn27G98TsSMs3WPNbZIEj4+VJf6saSFpvD+3Zsw==} @@ -238,17 +253,17 @@ packages: /@types/responselike/1.0.0: resolution: {integrity: sha512-85Y2BjiufFzaMIlvJDvTTB8Fxl2xfLo4HgmHzVBz08w4wDePCTjYw66PdrolO0kzli3yam/YCgRufyo1DdQVTA==} dependencies: - '@types/node': 18.13.0 + '@types/node': 18.14.0 dev: true /@types/serve-static/1.15.0: resolution: {integrity: sha512-z5xyF6uh8CbjAu9760KDKsH2FcDxZ2tFCsA4HIMWE6IkiYMXfVoa+4f9KX+FN0ZLsaMw1WNG2ETLA6N+/YA+cg==} dependencies: '@types/mime': 3.0.1 - '@types/node': 18.13.0 + '@types/node': 18.14.0 - /@types/uuid/9.0.0: - resolution: {integrity: sha512-kr90f+ERiQtKWMz5rP32ltJ/BtULDI5RVO0uavn1HQUOwjx0R1h0rnDYNL0CepF1zL5bSY6FISAfd9tOdDhU5Q==} + /@types/uuid/9.0.1: + resolution: {integrity: sha512-rFT3ak0/2trgvp4yYZo5iKFEPsET7vKydKF+VRCxlQ9bpheehyAJH89dAkaLEq/j/RZXJIqcgsmPJKUP1Z28HA==} dev: true /abstract-level/1.0.3: @@ -271,6 +286,21 @@ packages: mime-types: 2.1.35 negotiator: 0.6.3 + /amesu/1.3.0: + resolution: {integrity: sha512-gK1nv5VE5ttvDC0XLHZTvI9qtBVdIpQSOkDmilB88WE9u+fmhU78Fo1b00FUgwokAfL6AjWgE6FZIGmdnAPfpA==} + engines: {node: '>= v14'} + dependencies: + axios: 1.3.3 + log4js: 6.8.0 + long: 4.0.0 + pngjs: 6.0.0 + probe-image-size: 7.2.3 + rxjs: 7.8.0 + transitivePeerDependencies: + - debug + - supports-color + dev: true + /asap/2.0.6: resolution: {integrity: sha512-BSHWgDSAiKs50o2Re8ppvp3seVHXSRM44cdSsT9FfNEUUZLOGWVCsiWaRPWM1Znn+mqZ1OfVZ3z3DWEzSp7hRA==} @@ -278,11 +308,12 @@ packages: resolution: {integrity: sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==} dev: true - /axios/0.27.2: - resolution: {integrity: sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==} + /axios/1.3.3: + resolution: {integrity: sha512-eYq77dYIFS77AQlhzEL937yUBSepBfPIe8FcgEDN35vMNZKMrs81pgnyrQpwfy4NF4b4XWX1Zgx7yX+25w8QJA==} dependencies: follow-redirects: 1.15.2 form-data: 4.0.0 + proxy-from-env: 1.1.0 transitivePeerDependencies: - debug dev: true @@ -359,7 +390,7 @@ packages: dependencies: inflation: 2.0.0 qs: 6.11.0 - raw-body: 2.5.1 + raw-body: 2.5.2 type-is: 1.6.18 /co/4.6.0: @@ -893,18 +924,16 @@ packages: transitivePeerDependencies: - supports-color - /kokkoro/2.0.0-alpha.7: - resolution: {integrity: sha512-FXc39SQ9HBZZZP99PG92FqSC9cIUgK2C5+lswwLSr6ofz5g6hbzkcsU6sWrQYAnlWyMEPsODiOqyZ2KvmC3WeQ==} + /kokkoro/2.0.0-alpha.9: + resolution: {integrity: sha512-aTuMhdRFQOGkiI6k+Ix3xlKf0MwWf/ooGJmetP8cjoMhO2EfVUh+tl3ZPCDK9+VJCKRTBQuNZwiUjhjlMYjhCA==} engines: {node: '>= v15'} dependencies: '@kokkoro/admin': 0.2.0 + '@kokkoro/core': 2.0.1 '@kokkoro/database': 1.0.1 '@kokkoro/utils': 0.7.1 - '@kokkoro/web': 0.1.2 - cron: 2.2.0 + '@kokkoro/web': 0.1.3 dotenv: 16.0.3 - jsqr: 1.4.0 - oicq: 2.3.1 transitivePeerDependencies: - debug - supports-color @@ -930,15 +959,15 @@ packages: /lodash/4.17.21: resolution: {integrity: sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==} - /log4js/6.7.1: - resolution: {integrity: sha512-lzbd0Eq1HRdWM2abSD7mk6YIVY0AogGJzb/z+lqzRk+8+XJP+M6L1MS5FUSc3jjGru4dbKjEMJmqlsoYYpuivQ==} + /log4js/6.8.0: + resolution: {integrity: sha512-g+V8gZyurIexrOvWQ+AcZsIvuK/lBnx2argejZxL4gVZ4Hq02kUYH6WZOnqxgBml+zzQZYdaEoTN84B6Hzm8Fg==} engines: {node: '>=8.0'} dependencies: date-format: 4.0.14 debug: 4.3.4 flatted: 3.2.7 rfdc: 1.3.0 - streamroller: 3.1.4 + streamroller: 3.1.5 transitivePeerDependencies: - supports-color dev: true @@ -1055,20 +1084,6 @@ packages: /object-inspect/1.12.3: resolution: {integrity: sha512-geUvdk7c+eizMNUDkRpW1wJwgfOiOeHbxBR/hLXK1aT6zmVSO0jsQcs7fj6MGw89jC/cjGfLcNOrtMYtGqm81g==} - /oicq/2.3.1: - resolution: {integrity: sha512-mRw/GgdRKFMylnrlnnywzCIwvad6fF5E4WZfIlval070wEc3w9yMV49i9epFltWkU/JGNMDS4t5wWdZEYzW0EQ==} - engines: {node: '>= v14'} - dependencies: - axios: 0.27.2 - log4js: 6.7.1 - long: 4.0.0 - pngjs: 6.0.0 - probe-image-size: 7.2.3 - transitivePeerDependencies: - - debug - - supports-color - dev: true - /on-finished/2.4.1: resolution: {integrity: sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==} engines: {node: '>= 0.8'} @@ -1150,6 +1165,10 @@ packages: - supports-color dev: true + /proxy-from-env/1.1.0: + resolution: {integrity: sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==} + dev: true + /public-ip/4.0.4: resolution: {integrity: sha512-EJ0VMV2vF6Cu7BIPo3IMW1Maq6ME+fbR0NcPmqDfpfNGIRPue1X8QrGjrg/rfjDkOsIkKHIf2S5FlEa48hFMTA==} engines: {node: '>=8'} @@ -1176,8 +1195,8 @@ packages: resolution: {integrity: sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==} dev: true - /raw-body/2.5.1: - resolution: {integrity: sha512-qqJBtEyVgS0ZmPGdCFPWJ3FreoqvG4MVQln/kCgF7Olq95IbOp0/BWyMwbdtn4VTvkM8Y7khCQ2Xgk/tcrCXig==} + /raw-body/2.5.2: + resolution: {integrity: sha512-8zGqypfENjCIqGhgXToC8aB2r7YrBX+AQAfIPs/Mlk+BtPTztOvTS01NRW/3Eh60J+a48lt8qsCzirQ6loCVfA==} engines: {node: '>= 0.8'} dependencies: bytes: 3.1.2 @@ -1202,6 +1221,12 @@ packages: resolution: {integrity: sha512-V2hovdzFbOi77/WajaSMXk2OLm+xNIeQdMMuB7icj7bk6zi2F8GGAxigcnDFpJHbNyNcgyJDiP+8nOrY5cZGrA==} dev: true + /rxjs/7.8.0: + resolution: {integrity: sha512-F2+gxDshqmIub1KdvZkaEfGDwLNpPvk9Fs6LD/MyQxNgMds/WH9OdDDXOmxUZpME+iSK3rQCctkL0DYyytUqMg==} + dependencies: + tslib: 2.5.0 + dev: true + /safe-buffer/5.2.1: resolution: {integrity: sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==} @@ -1264,8 +1289,8 @@ packages: - supports-color dev: true - /streamroller/3.1.4: - resolution: {integrity: sha512-Ha1Ccw2/N5C/IF8Do6zgNe8F3jQo8MPBnMBGvX0QjNv/I97BcNRzK6/mzOpZHHK7DjMLTI3c7Xw7Y1KvdChkvw==} + /streamroller/3.1.5: + resolution: {integrity: sha512-KFxaM7XT+irxvdqSP1LGLgNWbYN7ay5owZ3r/8t77p+EtSUAfUgtl7be3xtqtOmGUl9K9YPO2ca8133RlTjvKw==} engines: {node: '>=8.0'} dependencies: date-format: 4.0.14 @@ -1289,6 +1314,10 @@ packages: resolution: {integrity: sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==} engines: {node: '>=0.6'} + /tslib/2.5.0: + resolution: {integrity: sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg==} + dev: true + /tsscmp/1.0.6: resolution: {integrity: sha512-LxhtAkPDTkVCMQjt2h6eBVY28KCjikZqZfMcC15YBeNjkgUpdCfBu5HoiOTDu86v6smE8yOjyEktJ8hlbANHQA==} engines: {node: '>=0.6.x'} diff --git a/src/controller/bot.controller.ts b/src/controller/bot.controller.ts index 36c5d84..8c8fc88 100644 --- a/src/controller/bot.controller.ts +++ b/src/controller/bot.controller.ts @@ -19,8 +19,10 @@ class BotController { const { uin } = ctx.request.body; const result = await botService.loginBot(uin); - if (result.data.status) { - ctx.result = result; + if (result.status) { + ctx.result = { + data: result, + }; } else { ctx.result = { data: { diff --git a/src/service/bot.service.ts b/src/service/bot.service.ts index 2594337..c7069b4 100644 --- a/src/service/bot.service.ts +++ b/src/service/bot.service.ts @@ -1,20 +1,20 @@ -import { getBotList, Client } from 'kokkoro'; +import { getBotList, Bot } from '@kokkoro/core'; import { SourceError } from '../app'; -interface Bot { - uin: Client['uin']; +interface BotInfo { + uin: Bot['uin']; online: boolean; - nickname: Client['nickname']; - sex: Client['sex']; - age: Client['age']; - tiny_id: Client['tiny_id']; - config: Client['config']; + nickname: Bot['nickname']; + sex: Bot['sex']; + age: Bot['age']; + tiny_id: Bot['tiny_id']; + config: Bot['config']; } class BotService { getBotList() { const botList = getBotList(); - const bots: Bot[] = []; + const infos: BotInfo[] = []; botList.forEach((bot) => { const { config, uin, nickname, sex, age, tiny_id, password } = bot; @@ -23,9 +23,9 @@ class BotService { uin, nickname, sex, age, tiny_id, config, password, }; - bots.push(element); + infos.push(element); }); - return bots; + return infos; } getBot(uin: number) { @@ -71,14 +71,14 @@ class BotService { }; } - async sendPrivateMsg(uin: number, ...params: Parameters) { + async sendPrivateMsg(uin: number, ...params: Parameters) { const bot = this.getBot(uin); const result = await bot.sendPrivateMsg(...params); return result; } - async sendGroupMsg(uin: number, ...params: Parameters) { + async sendGroupMsg(uin: number, ...params: Parameters) { const bot = this.getBot(uin); const result = await bot.sendGroupMsg(...params); diff --git a/src/service/plugin.service.ts b/src/service/plugin.service.ts index 6779ec0..3d72683 100644 --- a/src/service/plugin.service.ts +++ b/src/service/plugin.service.ts @@ -1,5 +1,5 @@ import { deepClone } from '@kokkoro/utils'; -import { getPluginList } from 'kokkoro'; +import { getPluginList } from '@kokkoro/core'; class PluginService { getPluginList() {