koishi-plugin-node-async-bot-all 3.0.0 → 3.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/lib/commands.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Context, Session } from "koishi";
2
2
  import { Installer } from "@koishijs/plugin-market";
3
3
  import Puppeteer from "koishi-plugin-puppeteer";
4
+ import { botDataType } from "./config.ts";
4
5
  declare module "koishi" {
5
6
  interface Context {
6
7
  installer: Installer;
@@ -33,7 +34,7 @@ export declare class CommandHandler {
33
34
  private sendMsg;
34
35
  private sendFailed;
35
36
  server(): Promise<number>;
36
- status(): Promise<object>;
37
+ status(botData: botDataType): Promise<object>;
37
38
  random(min: number, max: number): Promise<object>;
38
39
  info(): Promise<object>;
39
40
  randomWord(): Promise<object>;
package/lib/fun.d.ts CHANGED
@@ -50,7 +50,10 @@ export declare function readInfo(ctx: Context): Promise<{
50
50
  nodeVersion: string;
51
51
  } | string>;
52
52
  export declare function formatTimestampDiff(start: number, end: number): string;
53
- export declare function getMsgCount(ctx: Context): Promise<object>;
53
+ export declare function getMsgCount(ctx: Context): Promise<{
54
+ receive: number;
55
+ send: number;
56
+ }>;
54
57
  export declare function random(type: number | undefined, data: number | number[], data2?: number): number;
55
58
  export declare function request<T = any, E = any>(url: string, ctx: Context, options?: HTTP.RequestConfig, logger?: Logger): Promise<HttpResponse<T, E>>;
56
59
  export declare function queryA2S(host: string, log: Logger): Promise<serverInfo>;
package/lib/index.js CHANGED
@@ -34,7 +34,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
34
34
  // src/locales/zh-CN.yml
35
35
  var require_zh_CN = __commonJS({
36
36
  "src/locales/zh-CN.yml"(exports2, module2) {
37
- module2.exports = { noApi: "未指定 API", noop: "无", unknownError: "未知错误。", failed: "{quote}{time}\n{error}", "failed-md": "**{time}**\n{error}", commands: { na: { description: "NodeAsync Bot" }, cxgame: { description: "查询服务器当前人数。", messages: { msg: "{time}{list}\n进服指南请在群公告中查看。", "msg-md": "*{time}*\n\n---\n{list}\n\n---\n\n进服指南请在群公告中查看。", list: "【{name} 服务器 {count}】\n➣ {version}:{players}\n➣ {ne}:{list}\n➣ 备注:{note}", "list-md": "## {name} 服务器 {count}\n\n- {version}:{players}\n- {ne}:{list}\n- 备注:{note}", listFailed: "【{name} 服务器 {count}】\n➣ 查询失败:{data}\n➣ 请稍后重试。\n➣ 备注:{note}", "listFailed-md": "## {name} 服务器 {count}\n\n- 查询失败:{data}\n- 请稍后重试。\n- 备注:{note}", timeout: "请求超时。", fewData: "服务端返回的数据过少。", close: "服务器已关闭。", host: "没有到主机的路由。", dns: "解析失败。", "ne-a2s": "机器人", "ne-mc": "玩家列表", forbidden: "此指令不允许在本群使用。", failed: "查询失败:" } }, status: { description: "查询机器人状态。", messages: { msg: "{time}\n--- 系统状态 ---\n系统名称:{name}\nCPU使用率:{cpu}\n内存使用率:{memory}\n--- 机器人状态 ---\n昨日收/发消息数量:{msgCount}\n机器人版本:{version}\n运行时间:{online}", "msg-md": "*{time}*\n\n---\n\n## 系统状态\n\n- 系统名称:{name}\n- CPU使用率:{cpu}\n- 内存使用率:{memory}\n\n## 机器人状态\n\n- 昨日收/发消息数量:{msgCount}\n- 机器人版本:{version}\n- 运行时间:{online}", error: "状态获取失败。" } }, random: { description: "随机数生成器。", usage: "缺少参数时默认生成 0-10000 的随机数。\n使用示例:", examples: "random 1 128 生成1到128范围的随机数", messages: { msg: "{time}\n生成了一个随机数:{data}", "msg-md": "*{time}*\n\n---\n\n生成了一个随机数:{data}" } }, info: { description: "查询机器人信息。", messages: { msg: "{time}\n--- NodeAsync {version} ---\n私有机器人,服务器专用。\n--- 开发者 ---\n德二吹风机(3112836258)\n--- 其他 ---\nNode.js 版本:{nodeVersion}\nKoishi 版本:{koishiVersion}\n开源地址:https://github.com/ccd2s/node-async-bot-all\n官网:https://www.tasaed.top", "msg-md": "*{time}*\n\n---\n\n## NodeAsync {version}\n\n私有机器人,服务器专用。\n\n## 开发者\n\n- 德二吹风机(3112836258)\n\n## 其他\n\n- Node.js 版本:{nodeVersion}\n- Koishi 版本:{koishiVersion}\n- 开源地址:https://github.com/ccd2s/node-async-bot-all\n- 官网:https://www.tasaed.top", error: "读取信息失败。" } }, rw: { description: "随机名言名句。", messages: null }, randomba: { description: "随机BA图。", messages: { msg: "{quote}{image}" } }, centerservertest: { description: "查看中心服务器状态。", messages: { msg: "{time}{list}", "msg-md": "*{time}*\n\n---\n{list}", list: "== {name} ==\n状态:{status}\n存活率:{uptime}\n检测时间:{time}", "list-md": "## {name}\n\n- 状态:{status}\n- 存活率:{uptime}\n- 检测时间:{time}", listFailed: "== {name} ==\n查看失败:{data}", "listFailed-md": "## {name}\n\n查看失败:{data}", statusLive: "✅ 正常", statusDie: "❌ 故障", dataFail: "未能获取到此服务器的状态信息。" } }, meme: { description: "群友的怪话!", usage: "不带参数时随机查看\n带参数时为查看指定 meme", examples: "meme\nmeme 1145", messages: { msg: "{quote}{time}\n{image}\n{title}", "msg-qq": "{quote}{image}\n{time}\n{title}" } }, randomcat: { description: "随机猫猫图。", messages: { msg: "{quote}{image}" } }, getqqinfo: { description: "获取 QQ 号的信息。", usage: "获取 QQ 号的信息。", examples: "getqqinfo 10001", messages: { msg: "{quote}{image}", failed: "{quote}{time}\n获取失败:{data}", command: "QQ 号不正确。" } }, msg2img: { description: "引用一个消息并使用此指令,即可将消息转图。", usage: "引用一条消息,/m。(不要带@)", messages: { msg: "{quote}{image}", failed: "{quote}{time}\n获取失败:{data}", null: "未引用任何消息。", matroska: "{quote}禁止套娃!" } }, steamnews: { description: "抓取 Steam 游戏的最新新闻。" }, use: { description: "使用 TA !", usage: "use @用户", examples: "use @用户", messages: { command: "请 @ 一个用户。", msg: "{at} {desc}了 {at2} !" } } } };
37
+ module2.exports = { noApi: "未指定 API", noop: "无", unknownError: "未知错误。", failed: "{quote}{time}\n{error}", "failed-md": "**{time}**\n{error}", cat: "{name}Cat 信息\n版本: {version}\n平台: {platform}\n运行时间: {time}", commands: { na: { description: "NodeAsync Bot" }, cxgame: { description: "查询服务器当前人数。", messages: { msg: "{time}{list}\n进服指南请在群公告中查看。", "msg-md": "*{time}*\n\n---\n{list}\n\n---\n\n进服指南请在群公告中查看。", list: "【{name} 服务器 {count}】\n➣ {version}:{players}\n➣ {ne}:{list}\n➣ 备注:{note}", "list-md": "## {name} 服务器 {count}\n\n- {version}:{players}\n- {ne}:{list}\n- 备注:{note}", listFailed: "【{name} 服务器 {count}】\n➣ 查询失败:{data}\n➣ 请稍后重试。\n➣ 备注:{note}", "listFailed-md": "## {name} 服务器 {count}\n\n- 查询失败:{data}\n- 请稍后重试。\n- 备注:{note}", timeout: "请求超时。", fewData: "服务端返回的数据过少。", close: "服务器已关闭。", host: "没有到主机的路由。", dns: "解析失败。", "ne-a2s": "机器人", "ne-mc": "玩家列表", forbidden: "此指令不允许在本群使用。", failed: "查询失败:" } }, status: { description: "查询机器人状态。", messages: { msg: "{time}\n--- 系统状态 ---\n系统名称:{name}\nCPU使用率:{cpu}\n内存使用率:{memory}\n--- 机器人状态 ---\n昨日收/发消息数量:{msgCount}\n机器人版本:{version}\n运行时间:{online}", "msg-md": "*{time}*\n\n---\n\n## 系统状态\n\n- 系统名称:{name}\n- CPU使用率:{cpu}\n- 内存使用率:{memory}\n\n## 机器人状态\n\n- 昨日收/发消息数量:{msgCount}\n- 机器人版本:{version}\n- 运行时间:{online}", error: "状态获取失败。" } }, random: { description: "随机数生成器。", usage: "缺少参数时默认生成 0-10000 的随机数。\n使用示例:", examples: "random 1 128 生成1到128范围的随机数", messages: { msg: "{time}\n生成了一个随机数:{data}", "msg-md": "*{time}*\n\n---\n\n生成了一个随机数:{data}" } }, info: { description: "查询机器人信息。", messages: { msg: "{time}\n--- NodeAsync {version} ---\n私有机器人,服务器专用。\n--- 开发者 ---\n德二吹风机(3112836258)\n--- 其他 ---\nNode.js 版本:{nodeVersion}\nKoishi 版本:{koishiVersion}\n开源地址:https://github.com/ccd2s/node-async-bot-all\n官网:https://www.tasaed.top", "msg-md": "*{time}*\n\n---\n\n## NodeAsync {version}\n\n私有机器人,服务器专用。\n\n## 开发者\n\n- 德二吹风机(3112836258)\n\n## 其他\n\n- Node.js 版本:{nodeVersion}\n- Koishi 版本:{koishiVersion}\n- 开源地址:https://github.com/ccd2s/node-async-bot-all\n- 官网:https://www.tasaed.top", error: "读取信息失败。" } }, rw: { description: "随机名言名句。", messages: null }, randomba: { description: "随机BA图。", messages: { msg: "{quote}{image}" } }, centerservertest: { description: "查看中心服务器状态。", messages: { msg: "{time}{list}", "msg-md": "*{time}*\n\n---\n{list}", list: "== {name} ==\n状态:{status}\n存活率:{uptime}\n检测时间:{time}", "list-md": "## {name}\n\n- 状态:{status}\n- 存活率:{uptime}\n- 检测时间:{time}", listFailed: "== {name} ==\n查看失败:{data}", "listFailed-md": "## {name}\n\n查看失败:{data}", statusLive: "✅ 正常", statusDie: "❌ 故障", dataFail: "未能获取到此服务器的状态信息。" } }, meme: { description: "群友的怪话!", usage: "不带参数时随机查看\n带参数时为查看指定 meme", examples: "meme\nmeme 1145", messages: { msg: "{quote}{time}\n{image}\n{title}", "msg-qq": "{quote}{image}\n{time}\n{title}" } }, randomcat: { description: "随机猫猫图。", messages: { msg: "{quote}{image}" } }, getqqinfo: { description: "获取 QQ 号的信息。", usage: "获取 QQ 号的信息。", examples: "getqqinfo 10001", messages: { msg: "{quote}{image}", failed: "{quote}{time}\n获取失败:{data}", command: "QQ 号不正确。" } }, msg2img: { description: "引用一个消息并使用此指令,即可将消息转图。", usage: "引用一条消息,/m。(不要带@)", messages: { msg: "{quote}{image}", failed: "{quote}{time}\n获取失败:{data}", null: "未引用任何消息。", matroska: "{quote}禁止套娃!" } }, steamnews: { description: "抓取 Steam 游戏的最新新闻。" }, use: { description: "使用 TA !", usage: "use @用户", examples: "use @用户", messages: { command: "请 @ 一个用户。", msg: "{at} {desc}了 {at2} !" } } } };
38
38
  }
39
39
  });
40
40
 
@@ -470,15 +470,15 @@ var CommandHandler = class {
470
470
  }
471
471
  }
472
472
  // 指令 Status
473
- async status() {
473
+ async status(botData) {
474
474
  const { ctx, session, log, time } = this;
475
475
  let msg;
476
476
  const vMsg = await getSystemUsage();
477
- if (vMsg["success"] == 1) {
477
+ if (vMsg.success == 1) {
478
478
  log.error(vMsg);
479
479
  msg = {
480
480
  time,
481
- data: vMsg["data"],
481
+ data: vMsg.data,
482
482
  error: session.text(".error"),
483
483
  quote: import_koishi2.h.quote(session.messageId),
484
484
  success: 1
@@ -487,15 +487,15 @@ var CommandHandler = class {
487
487
  const msgCount = await getMsgCount(ctx);
488
488
  msg = {
489
489
  time,
490
- name: vMsg["name"],
491
- cpu: vMsg["cpu"],
492
- memory: vMsg["memory"],
490
+ name: vMsg.name,
491
+ cpu: vMsg.cpu,
492
+ memory: vMsg.memory,
493
493
  online: formatTimestampDiff(
494
- Number((await ctx.database.get("botData", "uptime"))[0].data),
494
+ Number(botData.uptime),
495
495
  Number(session.event.timestamp.toString().substring(0, 10))
496
496
  ),
497
- msgCount: `${msgCount["receive"]}/${msgCount["send"]}`,
498
- version: (await ctx.database.get("botData", "version"))[0].data,
497
+ msgCount: `${msgCount.receive}/${msgCount.send}`,
498
+ version: botData.version,
499
499
  success: 0
500
500
  };
501
501
  }
@@ -820,7 +820,7 @@ var CommandHandler = class {
820
820
  };
821
821
 
822
822
  // package.json
823
- var version = "3.0.0";
823
+ var version = "3.1.0";
824
824
 
825
825
  // src/config.ts
826
826
  var import_koishi3 = require("koishi");
@@ -915,10 +915,11 @@ var NodeAsyncBot = class {
915
915
  }
916
916
  async init(ct) {
917
917
  this.ctx = ct;
918
- const date = /* @__PURE__ */ new Date();
918
+ const vUptime = (await this.ctx.database.get("botData", "uptime"))[0];
919
+ const date = vUptime ? vUptime.data : (/* @__PURE__ */ new Date()).getTime().toString().substring(0, 10);
919
920
  this.botData = {
920
921
  version,
921
- uptime: date.getTime().toString().substring(0, 10)
922
+ uptime: date
922
923
  };
923
924
  this.ctx.model.extend("botData", {
924
925
  // 向表中注入字符串
@@ -1011,15 +1012,28 @@ ${import_koishi4.h.image(outMsg.data, "image/png")}`);
1011
1012
  `${outMsg.msg}
1012
1013
  ${import_koishi4.h.image(outMsg.data, "image/png")}`
1013
1014
  );
1014
- } else {
1015
- await this.ctx.broadcast(this.ctx.config.steamNews, outMsg.msg);
1016
1015
  }
1017
1016
  }
1018
1017
  });
1019
1018
  this.ctx.on("message", async (session) => {
1019
+ if (!session.content?.length || session.content?.length > 50) return;
1020
+ const ctt = session.content.toLowerCase();
1021
+ const match = session.content.match(/^#([a-zA-Z0-9]+)cat$/);
1022
+ if (match) {
1023
+ const system = await getSystemUsage();
1024
+ await session.send(session.text("cat", {
1025
+ name: match[1].charAt(0).toUpperCase() + match[1].slice(1),
1026
+ time: formatTimestampDiff(
1027
+ Number(this.botData.uptime),
1028
+ Number(session.event.timestamp.toString().substring(0, 10))
1029
+ ),
1030
+ version: this.botData.version,
1031
+ platform: system.success == 1 ? "未知" : system.name
1032
+ }));
1033
+ }
1020
1034
  if (session.bot.createReaction) {
1021
1035
  for (const content of this.ctx.config.specialMsg) {
1022
- if (session.content === content) {
1036
+ if (ctt === content) {
1023
1037
  await session.bot.createReaction(
1024
1038
  session.channelId,
1025
1039
  session.messageId,
@@ -1038,7 +1052,7 @@ ${import_koishi4.h.image(outMsg.data, "image/png")}`
1038
1052
  });
1039
1053
  this.na.subcommand("status").alias("stats").alias("状态").action(async ({ session }) => {
1040
1054
  await this.execCommand(session, "status", async (handler) => {
1041
- const status2 = await handler.status();
1055
+ const status2 = await handler.status(this.botData);
1042
1056
  await session?.send(
1043
1057
  session?.bot.adapterName == "qq" ? (0, import_koishi4.h)("qq:markdown", {
1044
1058
  content: session?.text(status2["success"] == 0 ? ".msg-md" : "failed-md", status2)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koishi-plugin-node-async-bot-all",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "description": "NodeAsync Bot插件(自用)",
5
5
  "keywords": [
6
6
  "chatbot",