koishi-plugin-node-async-bot-all 2.1.0 → 2.3.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,6 @@
1
- import { Context } from 'koishi';
2
- export declare function getServer(ctx: Context, session: any): Promise<object>;
3
- export declare function getStatus(ctx: Context, session: any): Promise<object>;
4
- export declare function getRandom(ctx: Context, session: any, min: number, max: number): Promise<object>;
5
- export declare function getInfo(ctx: Context, session: any): Promise<object>;
6
- export declare function getRW(ctx: Context, session: any): Promise<object>;
1
+ import { Context, Session } from 'koishi';
2
+ export declare function getServer(ctx: Context, session: Session): Promise<Object>;
3
+ export declare function getStatus(ctx: Context, session: Session): Promise<Object>;
4
+ export declare function getRandom(ctx: Context, session: Session, min: number, max: number): Promise<Object>;
5
+ export declare function getInfo(ctx: Context, session: Session): Promise<Object>;
6
+ export declare function getRW(ctx: Context, session: Session): Promise<Object>;
package/lib/fun.d.ts CHANGED
@@ -1,6 +1,8 @@
1
- import { Context } from "koishi";
2
- export declare function getSystemUsage(): Promise<object>;
1
+ import { Context, FlatPick } from "koishi";
2
+ import Analytics from "@koishijs/plugin-analytics";
3
+ export declare function getSystemUsage(): Promise<Object>;
3
4
  export declare function getHongKongTime(): string;
4
5
  export declare function fetchWithTimeout(url: string, options: {}, timeout: number, log: any): Promise<Response>;
5
6
  export declare function readInfoFile(ctx: Context): Promise<string>;
6
7
  export declare function formatTimestampDiff(start: number, end: number): string;
8
+ export declare function getMsgCount(array: FlatPick<Analytics.Message, "type" | "count">[]): Object;
package/lib/index.d.ts ADDED
@@ -0,0 +1,21 @@
1
+ import { Context, Schema } from 'koishi';
2
+ export declare const inject: string[];
3
+ declare module 'koishi' {
4
+ interface Tables {
5
+ botData: botDataTables;
6
+ }
7
+ }
8
+ interface botDataTables {
9
+ id: string;
10
+ data: string;
11
+ }
12
+ export declare const name = "node-async-bot-all";
13
+ export declare const usage = "\u8FD9\u662F\u4E00\u4E2A\u79C1\u6709\u63D2\u4EF6\u3002";
14
+ export interface Config {
15
+ cxAPI: string;
16
+ rwAPI: string;
17
+ timeout: number;
18
+ }
19
+ export declare const Config: Schema<Config>;
20
+ export declare function apply(ctx: Context): void;
21
+ export {};
package/lib/index.js CHANGED
@@ -33,7 +33,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
33
33
  // src/locales/zh-CN.yml
34
34
  var require_zh_CN = __commonJS({
35
35
  "src/locales/zh-CN.yml"(exports2, module2) {
36
- module2.exports = { commands: { cx: { description: "查询服务器当前人数。", messages: { msg: "{time}\n【服务器当前人数】\n➣ {version}:{players}\n➣ 玩家列表:{list}\n➣ 协议版本:{protocol}\n进服指南请在群公告中查看。", msgNoPlayer: "{time}\n【服务器当前人数】\n➣ {version}:{players}\n➣ 协议版本:{protocol}\n进服指南请在群公告中查看。", forbidden: "{time}\n此指令不允许在本群使用。", failed: "{time}\n查询失败:{data}\n请稍后重试。", timeout: "请求超时。", timeout2: "响应超时。", fewData: "服务端返回的数据过少。", close: "服务器已关闭。", error: "执行错误。", unknown: "未知错误。", host: "没有到主机的路由。" } }, status: { description: "查询机器人状态。", messages: { msg: "{time}\n系统名称:{name}\nCPU使用率:{cpu}\n内存使用率:{memory}\n运行时间:{online}", failed: "{time}\n状态获取失败。" } }, random: { description: "随机数生成器。", usage: "缺少参数时默认生成 0-10000 的随机数。\n使用示例:", examples: "random 1 128 生成1到128范围的随机数", messages: { msg: "{time}\n生成的随机数:{data}" } }, info: { description: "查询机器人信息。", messages: { msg: "{data}", failed: "{time}\n读取信息失败。" } }, rw: { description: "随机名言名句。", messages: { msg: "{time}\n{data}", failed1: "{time}\n获取失败(1)。", failed2: "{time}\n获取失败(2)。" } } } };
36
+ module2.exports = { commands: { cx: { description: "查询服务器当前人数。", messages: { msg: "{time}\n【MC服务器当前人数】\n➣ {version}:{players}\n➣ 玩家列表:{list}\n➣ 协议版本:{protocol}\n进服指南请在群公告中查看。", msgNoPlayer: "{time}\n【MC服务器当前人数】\n➣ {version}:{players}\n➣ 协议版本:{protocol}\n进服指南请在群公告中查看。", forbidden: "{time}\n此指令不允许在本群使用。", failed: "{time}\n查询失败:{data}\n请稍后重试。", timeout: "请求超时。", timeout2: "响应超时。", fewData: "服务端返回的数据过少。", close: "服务器已关闭。", error: "执行错误。", unknown: "未知错误。", host: "没有到主机的路由。" } }, status: { description: "查询机器人状态。", messages: { msg: "{time}\n--- 系统状态 ---\n系统名称:{name}\nCPU使用率:{cpu}\n内存使用率:{memory}\n--- 机器人状态 ---\n昨日收/发消息数量:{msgCount}\n机器人版本:{version}\n运行时间:{online}", failed: "{time}\n状态获取失败。" } }, random: { description: "随机数生成器。", usage: "缺少参数时默认生成 0-10000 的随机数。\n使用示例:", examples: "random 1 128 生成1到128范围的随机数", messages: { msg: "{time}\n生成的随机数:{data}" } }, info: { description: "查询机器人信息。", messages: { msg: "{data}", failed: "{time}\n读取信息失败。" } }, rw: { description: "随机名言名句。", messages: { msg: "{time}\n{data}", failed1: "{time}\n获取失败(1)。", failed2: "{time}\n获取失败(2)。" } } } };
37
37
  }
38
38
  });
39
39
 
@@ -47,6 +47,9 @@ __export(src_exports, {
47
47
  usage: () => usage
48
48
  });
49
49
  module.exports = __toCommonJS(src_exports);
50
+ var import_koishi2 = require("koishi");
51
+
52
+ // src/commands.ts
50
53
  var import_koishi = require("koishi");
51
54
 
52
55
  // src/fun.ts
@@ -157,19 +160,38 @@ function formatTimestampDiff(start, end) {
157
160
  return `${hours} 时 ${minutes} 分 ${seconds} 秒`;
158
161
  }
159
162
  __name(formatTimestampDiff, "formatTimestampDiff");
163
+ function getMsgCount(array) {
164
+ let receive = 0;
165
+ let send = 0;
166
+ array.forEach((item) => {
167
+ if (item.type == "receive") {
168
+ receive = receive + item.count;
169
+ } else {
170
+ send = send + item.count;
171
+ }
172
+ });
173
+ return { "receive": receive, "send": send };
174
+ }
175
+ __name(getMsgCount, "getMsgCount");
160
176
 
161
177
  // src/commands.ts
162
178
  async function getServer(ctx, session) {
163
179
  const log = ctx.logger("cx");
164
180
  log.info(`Got: {"form":"${session.event.guild.id}","user":"${session.event.user.id}","timestamp":${session.event.timestamp},"messageId":"${session.event.message.id}"}`);
165
181
  let msg;
182
+ let api;
166
183
  let dataError;
167
184
  let data;
168
185
  let error;
169
186
  const time = getHongKongTime();
170
- if (session.event.guild.id == "757729218" || session.event.guild.id == "1047732162") {
187
+ if (session.event.guild.id == "757729218" || session.event.guild.id == "1047732162" || session.event.guild.id == "917260212") {
171
188
  try {
172
- const response = await fetchWithTimeout(ctx.config.cxAPI, {}, ctx.config.timeout, log);
189
+ if (session.event.guild.id == "917260212") {
190
+ api = ctx.config.cxAPI2;
191
+ } else {
192
+ api = ctx.config.cxAPI;
193
+ }
194
+ const response = await fetchWithTimeout(api, {}, ctx.config.timeout, log);
173
195
  if (response.ok) {
174
196
  data = await response.text();
175
197
  log.info("Server data: " + data);
@@ -263,7 +285,7 @@ async function getStatus(ctx, session) {
263
285
  "success": 1
264
286
  };
265
287
  } else {
266
- log.info((await ctx.database.get("botData", "uptime"))[0].data);
288
+ const msgCount = getMsgCount(await ctx.database.get("analytics.message", { date: import_koishi.Time.getDateNumber() - 1 }, ["type", "count"]));
267
289
  msg = {
268
290
  "time": time,
269
291
  "name": vMsg["name"],
@@ -271,8 +293,10 @@ async function getStatus(ctx, session) {
271
293
  "memory": vMsg["memory"],
272
294
  "online": formatTimestampDiff(
273
295
  Number((await ctx.database.get("botData", "uptime"))[0].data),
274
- session.event.timestamp.toString().substring(0, 10)
296
+ Number(session.event.timestamp.toString().substring(0, 10))
275
297
  ),
298
+ "msgCount": `${msgCount["receive"]}/${msgCount["send"]}`,
299
+ "version": (await ctx.database.get("botData", "version"))[0].data,
276
300
  "success": 0
277
301
  };
278
302
  }
@@ -372,21 +396,22 @@ async function getRW(ctx, session) {
372
396
  __name(getRW, "getRW");
373
397
 
374
398
  // package.json
375
- var version = "2.1.0";
399
+ var version = "2.3.0";
376
400
 
377
401
  // src/index.ts
378
- var inject = ["silk", "database"];
402
+ var inject = ["database"];
379
403
  var name = "node-async-bot-all";
380
404
  var usage = "这是一个私有插件。";
381
- var Config = import_koishi.Schema.intersect([
382
- import_koishi.Schema.object({
383
- timeout: import_koishi.Schema.number().default(8e3).description("超时时间(毫秒)")
405
+ var Config = import_koishi2.Schema.intersect([
406
+ import_koishi2.Schema.object({
407
+ timeout: import_koishi2.Schema.number().default(8e3).description("超时时间(毫秒)")
384
408
  }).description("基础"),
385
- import_koishi.Schema.object({
386
- cxAPI: import_koishi.Schema.string().default("https://api.tasaed.top/get/minecraftServer/").description("查询 API")
409
+ import_koishi2.Schema.object({
410
+ cxAPI: import_koishi2.Schema.string().default("https://api.tasaed.top/get/minecraftServer/").description("查询 API"),
411
+ cxAPI2: import_koishi2.Schema.string().default("https://api.tasaed.top/get/minecraftServer/bas.php").description("查询 API 2")
387
412
  }).description("查询"),
388
- import_koishi.Schema.object({
389
- rwAPI: import_koishi.Schema.string().default("https://api.tasaed.top/rw/").description("随机文本 API")
413
+ import_koishi2.Schema.object({
414
+ rwAPI: import_koishi2.Schema.string().default("https://api.tasaed.top/rw/").description("随机文本 API")
390
415
  }).description("随机文本")
391
416
  ]).description("基础设置");
392
417
  function apply(ctx) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-node-async-bot-all",
3
3
  "description": "NodeAsync Bot插件(自用)",
4
- "version": "2.1.0",
4
+ "version": "2.3.0",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "contributors": [
@@ -31,8 +31,8 @@
31
31
  "@koishijs/client": "^5.30.4"
32
32
  },
33
33
  "peerDependencies": {
34
+ "@koishijs/plugin-database-sqlite": "^4.6.0",
34
35
  "@koishijs/plugin-help": "^2.4.5",
35
- "koishi": "^4.18.7",
36
- "koishi-plugin-silk": "^2.0.1"
36
+ "koishi": "^4.18.7"
37
37
  }
38
38
  }