koishi-plugin-tmp-bot 1.19.4 → 1.20.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.
@@ -117,7 +117,7 @@ module.exports = {
117
117
  async mapPlayerHistory(http, tmpId, serverId, startTime, endTime) {
118
118
  let result = null;
119
119
  try {
120
- result = await http.get(`${BASE_API}/map/playerHistory?tmpId=${tmpId}&serverId=${serverId}&startTime=${startTime}&endTime=${endTime}`);
120
+ result = await http.get(`${BASE_API}/map/playerHistory?tmpId=${tmpId || ''}&serverId=${serverId || ''}&startTime=${startTime || ''}&endTime=${endTime || ''}`);
121
121
  }
122
122
  catch {
123
123
  return {
@@ -1,3 +1,3 @@
1
- declare function _exports(ctx: any, session: any, serverName: any): Promise<string | segment>;
1
+ declare function _exports(ctx: any, session: any, serverType: any, tmpId: any): Promise<string | segment>;
2
2
  export = _exports;
3
3
  import { segment } from "@koishijs/core";
@@ -2,24 +2,24 @@ const { segment } = require('koishi');
2
2
  const dayjs = require('dayjs');
3
3
  const { resolve } = require('path');
4
4
  const common = require('../util/common');
5
- const { ServerAliasToId, PromodsIds } = require('../util/constant');
5
+ const { PromodsIds, ServerType } = require('../util/constant');
6
6
  const evmOpenApi = require('../api/evmOpenApi');
7
7
  const guildBind = require('../database/guildBind');
8
- module.exports = async (ctx, session, serverName) => {
8
+ module.exports = async (ctx, session, serverType, tmpId) => {
9
9
  if (!ctx.puppeteer) {
10
10
  return '未启用 puppeteer 服务';
11
11
  }
12
- // 转换服务器别名到ID
13
- let serverId = ServerAliasToId[serverName];
14
- if (!serverId) {
15
- return '请输入正确的服务器名称 (s1, s2, p, a)';
12
+ if (tmpId && isNaN(tmpId)) {
13
+ return `请输入正确的玩家编号,或绑定玩家编号`;
16
14
  }
17
- // 尝试从数据库查询绑定信息
18
- let guildBindData = await guildBind.get(ctx.database, session.platform, session.userId);
19
- if (!guildBindData) {
20
- return `请先绑定玩家编号`;
15
+ // 如果没有传入tmpId,尝试从数据库查询绑定信息
16
+ if (!tmpId) {
17
+ let guildBindData = await guildBind.get(ctx.database, session.platform, session.userId);
18
+ if (!guildBindData) {
19
+ return `请输入正确的玩家编号,或绑定玩家编号`;
20
+ }
21
+ tmpId = guildBindData.tmp_id;
21
22
  }
22
- let tmpId = guildBindData.tmp_id;
23
23
  // 查询玩家信息
24
24
  let playerInfo = await evmOpenApi.playerInfo(ctx.http, tmpId);
25
25
  if (playerInfo.error && playerInfo.code === 10001) {
@@ -31,13 +31,27 @@ module.exports = async (ctx, session, serverName) => {
31
31
  // 查询当日历史位置数据
32
32
  const startTime = dayjs().startOf('day').format('YYYY-MM-DD HH:mm:ss');
33
33
  const endTime = dayjs().endOf('day').format('YYYY-MM-DD HH:mm:ss');
34
- let mapPlayerHistory = await evmOpenApi.mapPlayerHistory(ctx.http, tmpId, serverId, startTime, endTime);
35
- if (mapPlayerHistory.data.length === 0) {
34
+ let mapPlayerHistory = await evmOpenApi.mapPlayerHistory(ctx.http, tmpId, null, startTime, endTime);
35
+ if (mapPlayerHistory.error) {
36
+ return '查询玩家历史位置数据失败,请稍后重试';
37
+ }
38
+ // 过滤非对应服务器数据
39
+ const promodsIdSet = new Set(PromodsIds);
40
+ const mapPlayerHistoryArr = mapPlayerHistory.data.filter(item => {
41
+ if (ServerType.ets === serverType) {
42
+ return !promodsIdSet.has(item.serverId);
43
+ }
44
+ else if (ServerType.promods === serverType) {
45
+ return promodsIdSet.has(item.serverId);
46
+ }
47
+ return false;
48
+ });
49
+ if (mapPlayerHistoryArr.length === 0) {
36
50
  return `当日暂无数据`;
37
51
  }
38
52
  // 拼接数据
39
53
  let data = {
40
- mapType: PromodsIds.indexOf(serverId) !== -1 ? 'promods' : 'ets',
54
+ mapType: ServerType.promods === serverType ? 'promods' : 'ets',
41
55
  name: playerInfo.data.name,
42
56
  smallAvatarUrl: playerInfo.data.smallAvatarUrl,
43
57
  todayMileage: playerInfo.data.todayMileage,
@@ -1,3 +1,3 @@
1
- declare function _exports(ctx: any, cfg: any, session: any, tmpId: any): Promise<segment | "请输入正确的玩家编号" | "渲染异常,请重试" | "未启用 puppeteer 服务" | "查询玩家信息失败,请重试" | "玩家离线">;
1
+ declare function _exports(ctx: any, cfg: any, session: any, tmpId: any): Promise<segment | "渲染异常,请重试" | "未启用 puppeteer 服务" | "请输入正确的玩家编号,或绑定玩家编号" | "查询玩家信息失败,请重试" | "玩家离线">;
2
2
  export = _exports;
3
3
  import { segment } from "@koishijs/core";
@@ -12,13 +12,13 @@ const common = require('../util/common');
12
12
  module.exports = async (ctx, cfg, session, tmpId) => {
13
13
  if (ctx.puppeteer) {
14
14
  if (tmpId && isNaN(tmpId)) {
15
- return `请输入正确的玩家编号`;
15
+ return `请输入正确的玩家编号,或绑定玩家编号`;
16
16
  }
17
17
  // 如果没有传入tmpId,尝试从数据库查询绑定信息
18
18
  if (!tmpId) {
19
19
  let guildBindData = await guildBind.get(ctx.database, session.platform, session.userId);
20
20
  if (!guildBindData) {
21
- return `请输入正确的玩家编号`;
21
+ return `请输入正确的玩家编号,或绑定玩家编号`;
22
22
  }
23
23
  tmpId = guildBindData.tmp_id;
24
24
  }
@@ -1,3 +1,3 @@
1
- declare function _exports(ctx: any, cfg: any, session: any, tmpId: any): Promise<segment | "请输入正确的玩家编号" | "渲染异常,请重试" | "未启用 puppeteer 服务" | "玩家不存在" | "查询玩家信息失败,请重试">;
1
+ declare function _exports(ctx: any, cfg: any, session: any, tmpId: any): Promise<segment | "渲染异常,请重试" | "未启用 puppeteer 服务" | "请输入正确的玩家编号,或绑定玩家编号" | "玩家不存在" | "查询玩家信息失败,请重试">;
2
2
  export = _exports;
3
3
  import { segment } from "@koishijs/core";
@@ -25,13 +25,13 @@ module.exports = async (ctx, cfg, session, tmpId) => {
25
25
  return '未启用 puppeteer 服务';
26
26
  }
27
27
  if (tmpId && isNaN(tmpId)) {
28
- return `请输入正确的玩家编号`;
28
+ return `请输入正确的玩家编号,或绑定玩家编号`;
29
29
  }
30
30
  // 如果没有传入tmpId,尝试从数据库查询绑定信息
31
31
  if (!tmpId) {
32
32
  let guildBindData = await guildBind.get(ctx.database, session.platform, session.userId);
33
33
  if (!guildBindData) {
34
- return `请输入正确的玩家编号`;
34
+ return `请输入正确的玩家编号,或绑定玩家编号`;
35
35
  }
36
36
  tmpId = guildBindData.tmp_id;
37
37
  }
@@ -23,13 +23,13 @@ const userGroup = {
23
23
  */
24
24
  module.exports = async (ctx, cfg, session, tmpId) => {
25
25
  if (tmpId && isNaN(tmpId)) {
26
- return `请输入正确的玩家编号`;
26
+ return `请输入正确的玩家编号,或绑定玩家编号`;
27
27
  }
28
28
  // 如果没有传入tmpId,尝试从数据库查询绑定信息
29
29
  if (!tmpId) {
30
30
  let guildBindData = await guildBind.get(ctx.database, session.platform, session.userId);
31
31
  if (!guildBindData) {
32
- return `请输入正确的玩家编号`;
32
+ return `请输入正确的玩家编号,或绑定玩家编号`;
33
33
  }
34
34
  tmpId = guildBindData.tmp_id;
35
35
  }
package/lib/index.js CHANGED
@@ -14,6 +14,7 @@ const tmpVersion = require('./command/tmpVersion');
14
14
  const tmpDlcMap = require('./command/tmpDlcMap');
15
15
  const tmpMileageRanking = require('./command/tmpMileageRanking');
16
16
  const tmpFootprint = require('./command/tmpFootprint');
17
+ const { ServerType } = require('./util/constant');
17
18
  exports.name = 'tmp-bot';
18
19
  exports.inject = {
19
20
  required: ['database'],
@@ -51,5 +52,6 @@ function apply(ctx, cfg) {
51
52
  ctx.command('tmpdlcmap').action(async ({ session }) => await tmpDlcMap(ctx, session));
52
53
  ctx.command('tmpmileageranking').action(async ({ session }) => await tmpMileageRanking(ctx, session, MileageRankingType.total));
53
54
  ctx.command('tmptodaymileageranking').action(async ({ session }) => await tmpMileageRanking(ctx, session, MileageRankingType.today));
54
- ctx.command('tmpfootprint').action(async ({ session }, serverName) => await tmpFootprint(ctx, session, serverName));
55
+ ctx.command('tmpfootprints').action(async ({ session }, tmpId) => await tmpFootprint(ctx, session, ServerType.ets, tmpId));
56
+ ctx.command('tmpfootprintp').action(async ({ session }, tmpId) => await tmpFootprint(ctx, session, ServerType.promods, tmpId));
55
57
  }
@@ -13,3 +13,7 @@ export namespace ServerAliasToId {
13
13
  let a: number;
14
14
  }
15
15
  export let PromodsIds: number[];
16
+ export namespace ServerType {
17
+ let ets: number;
18
+ let promods: number;
19
+ }
@@ -25,5 +25,12 @@ module.exports = {
25
25
  /**
26
26
  * P服务器ID集合
27
27
  */
28
- PromodsIds: [50, 51]
28
+ PromodsIds: [50, 51],
29
+ /**
30
+ * 服务器类型
31
+ */
32
+ ServerType: {
33
+ ets: 1,
34
+ promods: 2
35
+ }
29
36
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-tmp-bot",
3
3
  "description": "欧洲卡车模拟2 TMP查询插件,不会部署的可以直接使用此机器人->QQ:3523283907",
4
- "version": "1.19.4",
4
+ "version": "1.20.1",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "homepage": "https://github.com/79887143/koishi-plugin-tmp-bot",