karin-plugin-mys-core 1.0.0 → 1.0.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.
@@ -1,15 +1,17 @@
1
1
  import {
2
2
  UserInfo,
3
- common_exports,
4
3
  fetchQRcode,
5
4
  getCookieAccountInfoByGameToken,
6
5
  getTokenByGameToken,
7
6
  getUserFullInfo,
8
7
  queryQRcode
9
- } from "../chunk-4JTLXC2G.js";
10
- import "../chunk-7QISGXVH.js";
8
+ } from "../chunk-MV2UE7C7.js";
9
+ import "../chunk-NHUNEZXM.js";
10
+ import {
11
+ common_exports
12
+ } from "../chunk-WYRIRWT5.js";
13
+ import "../chunk-CQNW7LJI.js";
11
14
  import "../chunk-JML6VYXN.js";
12
- import "../chunk-JIO4GOQA.js";
13
15
  import "../chunk-MLKGABMK.js";
14
16
 
15
17
  // src/apps/MiHoYoLogin.ts
@@ -170,24 +172,17 @@ var bingCookie = async (userId, cookie, Serv = "mihoyo" /* cn */) => {
170
172
  }
171
173
  const userInfo = await UserInfo.create(userId);
172
174
  await userInfo.saveUserInfo({
173
- userId,
174
175
  ...uidList.uids.data,
175
- ltuids: lodash.uniq([...userInfo.ltuids, cookieParams.ltuid]),
176
- stuids: userInfo.stuids,
177
- deviceList: userInfo.deviceList
176
+ ltuids: lodash.uniq([...userInfo.ltuids, cookieParams.ltuid])
178
177
  });
179
- const ltuidInfo = userInfo.getLtuidInfo(cookieParams.ltuid);
180
- await userInfo.saveMysAccountInfo({
181
- ltuid: cookieParams.ltuid,
178
+ await userInfo.saveMysAccountInfo(cookieParams.ltuid, {
182
179
  type: uidList.Serv,
183
- cookie: common_exports.ObjToStr(cookieParams, ";"),
184
- stoken: ltuidInfo?.stoken || "",
185
- deviceId: ltuidInfo?.deviceId || ""
180
+ cookie: common_exports.ObjToStr(cookieParams, ";")
186
181
  });
187
182
  logger.mark(`[${userId}] \u4FDD\u5B58Cookie\u6210\u529F [ltuid:${cookieParams.ltuid}]`);
188
183
  const sendMsg = [];
189
184
  lodash.forEach(uidList.uids.data, (uids, game) => {
190
- sendMsg.push(`\u3010${uidList.uids.names[game]}\u3011\uFF1A${uids.join("\u3001")}`);
185
+ sendMsg.push(`\u3010${uidList.uids.names[game]}\u3011\uFF1A${Object.keys(uids).join("\u3001")}`);
191
186
  });
192
187
  return `Cookie\u7ED1\u5B9A\u6210\u529F\uFF01
193
188
  ${sendMsg.join("\n")}`;
@@ -216,18 +211,11 @@ var bingStoken = async (userId, stoken, option) => {
216
211
  const Stoken = common_exports.ObjToStr(stokenParams, ";");
217
212
  const userInfo = await UserInfo.create(userId);
218
213
  await userInfo.saveUserInfo({
219
- userId,
220
- ltuids: userInfo.ltuids,
221
- stuids: lodash.uniq([...userInfo.stuids, stokenParams.stuid]),
222
- deviceList: userInfo.deviceList
214
+ stuids: lodash.uniq([...userInfo.stuids, stokenParams.stuid])
223
215
  });
224
- const ltuidInfo = userInfo.getLtuidInfo(stokenParams.stuid);
225
- await userInfo.saveMysAccountInfo({
226
- ltuid: stokenParams.stuid,
216
+ await userInfo.saveMysAccountInfo(stokenParams.stuid, {
227
217
  type: updata.Serv,
228
- cookie: ltuidInfo?.cookie || "",
229
- stoken: Stoken,
230
- deviceId: ltuidInfo?.deviceId || ""
218
+ stoken: Stoken
231
219
  });
232
220
  logger.mark(`[${userId}] \u4FDD\u5B58Stoken\u6210\u529F [stuid: ${stokenParams.stuid}]`);
233
221
  const sendMsg = [];
@@ -0,0 +1,5 @@
1
+ import * as node_karin from 'node-karin';
2
+
3
+ declare const BingMysDevice: node_karin.Command<keyof node_karin.MessageEventMap>;
4
+
5
+ export { BingMysDevice };
@@ -0,0 +1,59 @@
1
+ import {
2
+ DeviceInfo,
3
+ UserInfo
4
+ } from "../chunk-MV2UE7C7.js";
5
+ import "../chunk-NHUNEZXM.js";
6
+ import "../chunk-WYRIRWT5.js";
7
+ import "../chunk-CQNW7LJI.js";
8
+ import "../chunk-JML6VYXN.js";
9
+ import "../chunk-MLKGABMK.js";
10
+
11
+ // src/apps/MysDevice.ts
12
+ import karin from "node-karin";
13
+ var BingMysDevice = karin.command(
14
+ /^#绑定(米游社)?设备$/,
15
+ async (e) => {
16
+ const userInfo = await UserInfo.create(e.userId);
17
+ const ltuidInfoList = userInfo.getLtuidInfoList();
18
+ const cnLtuidInfoList = ltuidInfoList.filter((info) => info.type === "mihoyo" /* cn */);
19
+ if (cnLtuidInfoList.length === 0) {
20
+ if (ltuidInfoList.length === 0) {
21
+ e.reply("\u6682\u672A\u7ED1\u5B9A\u56FD\u670D\u7C73\u6E38\u793E\u8D26\u53F7\uFF0C\u8BF7\u5148\u201C#\u626B\u7801\u7ED1\u5B9A\u201D\u7ED1\u5B9A", { at: true });
22
+ } else {
23
+ e.reply("\u56FD\u9645\u670D\u6682\u4E0D\u9700\u8981\u7ED1\u5B9A\u8BBE\u5907\u3002", { at: true });
24
+ }
25
+ return true;
26
+ }
27
+ e.reply("\u8BF7\u53D1\u9001\u8BBE\u5907\u4FE1\u606F(\u5EFA\u8BAE\u79C1\u804A\u53D1\u9001)\uFF0C\u6216\u8005\u53D1\u9001\u201C\u53D6\u6D88\u201D\u53D6\u6D88\u7ED1\u5B9A", { at: true });
28
+ const ctx = await karin.ctx(e);
29
+ if (/^#?取消(绑定)/.test(ctx.msg)) {
30
+ e.reply("\u5DF2\u53D6\u6D88\u7ED1\u5B9A", { at: true });
31
+ return true;
32
+ }
33
+ const device = JSON.parse(ctx.msg);
34
+ if (device.device_id && device.device_fp) {
35
+ await DeviceInfo.create(userInfo, {
36
+ deviceId: device.device_id,
37
+ deviceFp: device.device_fp
38
+ });
39
+ } else if (device.deviceName && device.deviceBoard && device.deviceModel && device.oaid && device.androidVersion && device.deviceFingerprint && device.deviceProduct) {
40
+ await DeviceInfo.create(userInfo, {
41
+ name: device.deviceName,
42
+ board: device.deviceBoard,
43
+ model: device.deviceModel,
44
+ oaid: device.oaid,
45
+ androidVersion: device.androidVersion,
46
+ fingerprint: device.deviceFingerprint,
47
+ product: device.deviceProduct
48
+ });
49
+ } else {
50
+ e.reply("\u8BBE\u5907\u4FE1\u606F\u4E0D\u5B8C\u6574\uFF0C\u8BF7\u63D0\u4F9B\u5B8C\u6574\u7684\u8BBE\u5907\u4FE1\u606F", { at: true });
51
+ return true;
52
+ }
53
+ e.reply("\u8BBE\u5907\u7ED1\u5B9A\u6210\u529F", { at: true });
54
+ return true;
55
+ }
56
+ );
57
+ export {
58
+ BingMysDevice
59
+ };
@@ -5,14 +5,29 @@ interface MysAccountInfoType {
5
5
  type: MysAccountType;
6
6
  cookie: string;
7
7
  stoken: string;
8
- /** 绑定的设备ID */
9
- deviceId: string;
8
+ /** 绑定的设备md5 */
9
+ deviceMd5: string;
10
10
  }
11
11
  declare const enum MysAccountType {
12
12
  cn = "mihoyo",
13
13
  os = "hoyolab"
14
14
  }
15
15
 
16
+ interface MysDeviceInfoItem {
17
+ deviceId: string;
18
+ deviceFp: string;
19
+ name: string;
20
+ board: string;
21
+ model: string;
22
+ oaid: string;
23
+ androidVersion: string;
24
+ fingerprint: string;
25
+ product: string;
26
+ }
27
+ interface MysDeviceInfoType extends MysDeviceInfoItem {
28
+ md5: string;
29
+ }
30
+
16
31
  interface BaseUserInfoType {
17
32
  userId: string;
18
33
  ltuids: string[];
@@ -38,15 +53,23 @@ declare enum DatabaseType {
38
53
  type ModelAttributes<M extends Model = Model, TAttributes = any> = {
39
54
  [name in keyof TAttributes]: ModelAttributeColumnOptions<M>;
40
55
  };
41
- type DatabaseReturn<T> = T & {
42
- _save: (data: T) => Promise<void>;
43
- };
44
- type DatabaseClassInstance<T extends Record<string, any>> = {
56
+ interface DatabaseReturn<T> {
57
+ [DatabaseType.Db]: T & {
58
+ save: (data: Partial<T>) => Promise<DatabaseReturn<T>[DatabaseType.Db]>;
59
+ };
60
+ [DatabaseType.File]: T & {
61
+ save: (data: T) => Promise<DatabaseReturn<T>[DatabaseType.File]>;
62
+ };
63
+ [DatabaseType.Dir]: T & {
64
+ save: (data: T) => Promise<DatabaseReturn<T>[DatabaseType.Dir]>;
65
+ };
66
+ }
67
+ type DatabaseClassInstance<T extends Record<string, any>, D extends DatabaseType> = {
45
68
  /** 数据库标识 */
46
69
  dialect: Dialect;
47
70
  model: ModelStatic<Model>;
48
71
  databasePath: string;
49
- databaseType: DatabaseType;
72
+ databaseType: D;
50
73
  /** 表名 */
51
74
  modelName: string;
52
75
  /** 表定义 */
@@ -60,31 +83,29 @@ type DatabaseClassInstance<T extends Record<string, any>> = {
60
83
  * @param modelSchema 表定义
61
84
  * @param type 数据库类型
62
85
  */
63
- init(DataDir: string, modelName: string, modelSchema: ModelAttributes<Model>, type: DatabaseType): Promise<DatabaseClassInstance<T>>;
86
+ init(DataDir: string, modelName: string, modelSchema: Record<keyof T, ModelAttributeColumnOptions<Model>>, type: D): Promise<DatabaseClassInstance<T, D>>;
64
87
  /** 将表定义转换为 JSON 对象 */
65
88
  schemaToJSON(pk: string): T;
66
89
  /** 获取用户数据文件路径 */
67
90
  userPath(pk: string): string;
68
91
  /** 根据主键读取用户数据文件 */
69
- readSync(path: string, pk: string): DatabaseReturn<T>;
92
+ readSync(path: string, pk: string): DatabaseReturn<T>[DatabaseType.File];
70
93
  /** 根据主键读取用户数据目录 */
71
- readDirSync(pk: string): DatabaseReturn<T>;
72
- /** 写入用户数据文件 */
73
- writeFileSync(pk: string, data: Record<string, any>): boolean;
94
+ readDirSync(pk: string): DatabaseReturn<T>[DatabaseType.Dir];
74
95
  /** 写入用户数据目录 */
75
96
  writeDirSync(pk: string, data: Record<string, any>): boolean;
76
97
  /** 保存用户数据到文件 */
77
- saveFile(pk: string): (data: T) => Promise<void>;
98
+ saveFile(pk: string): (data: T) => Promise<DatabaseReturn<T>[DatabaseType.File]>;
78
99
  /** 保存用户数据到目录 */
79
- saveDir(pk: string): (data: T) => Promise<void>;
100
+ saveDir(pk: string): (data: T) => Promise<DatabaseReturn<T>[DatabaseType.Dir]>;
80
101
  /** 保存用户数据到 SQL 数据库 */
81
- saveSql(model: Model<any, any>, pk: string): (data: T) => Promise<void>;
102
+ saveSql(model: Model<any, any>, pk: string): (data: Partial<T>) => Promise<DatabaseReturn<T>[DatabaseType.Db]>;
82
103
  /** 根据主键查找或创建用户数据 */
83
- findByPk(pk: string, create: true): Promise<DatabaseReturn<T>>;
104
+ findByPk(pk: string, create: true): Promise<DatabaseReturn<T>[D]>;
84
105
  /** 根据主键查找用户数据 */
85
- findByPk(pk: string, create: boolean): Promise<DatabaseReturn<T> | undefined>;
106
+ findByPk(pk: string, create?: boolean): Promise<DatabaseReturn<T>[D] | undefined>;
86
107
  /** 根据主键数组查找用户数据 */
87
- findAllByPks(pks: string[]): Promise<DatabaseReturn<T>[]>;
108
+ findAllByPks(pks: string[]): Promise<DatabaseReturn<T>[D][]>;
88
109
  /** 删除用户数据 */
89
110
  destroy(pk: string): Promise<boolean>;
90
111
  };
@@ -96,4 +117,4 @@ interface DatabaseClassStatic {
96
117
  }): ModelAttributeColumnOptions<Model>;
97
118
  }
98
119
 
99
- export { type BaseUserInfoType as B, Dialect as D, type ModelAttributes as M, DatabaseType as a, type DatabaseReturn as b, type DatabaseClassInstance as c, type DatabaseClassStatic as d, type MysAccountInfoType as e, MysAccountType as f };
120
+ export { type BaseUserInfoType as B, Dialect as D, type ModelAttributes as M, DatabaseType as a, type DatabaseReturn as b, type DatabaseClassInstance as c, type DatabaseClassStatic as d, type MysAccountInfoType as e, MysAccountType as f, type MysDeviceInfoItem as g, type MysDeviceInfoType as h };
@@ -1,3 +1,9 @@
1
+ // src/types/app/command.ts
2
+ var CoreCommand = /* @__PURE__ */ ((CoreCommand2) => {
3
+ CoreCommand2["BingMysDevice"] = "BingMysDevice";
4
+ return CoreCommand2;
5
+ })(CoreCommand || {});
6
+
1
7
  // src/types/database/dbs/base.ts
2
8
  var Dialect = /* @__PURE__ */ ((Dialect2) => {
3
9
  Dialect2["Sqlite"] = "sqlite";
@@ -25,6 +31,7 @@ var MysAccountType = /* @__PURE__ */ ((MysAccountType2) => {
25
31
  })(MysAccountType || {});
26
32
 
27
33
  export {
34
+ CoreCommand,
28
35
  Dialect,
29
36
  DatabaseType,
30
37
  MysAccountType
@@ -1,152 +1,11 @@
1
1
  import {
2
2
  MysAccountInfoDB,
3
+ MysDeviceInfoDB,
3
4
  MysUserInfoDB
4
- } from "./chunk-7QISGXVH.js";
5
+ } from "./chunk-NHUNEZXM.js";
5
6
  import {
6
- dir
7
- } from "./chunk-JML6VYXN.js";
8
- import {
9
- __export
10
- } from "./chunk-MLKGABMK.js";
11
-
12
- // src/utils/common.ts
13
- var common_exports = {};
14
- __export(common_exports, {
15
- ObjToStr: () => ObjToStr,
16
- StrToObj: () => StrToObj,
17
- getDeviceGuid: () => getDeviceGuid,
18
- getEndOfDay: () => getEndOfDay,
19
- random: () => random,
20
- randomString: () => randomString,
21
- sleep: () => sleep,
22
- timef: () => timef
23
- });
24
- import lodash from "node-karin/lodash";
25
- import moment from "node-karin/moment";
26
- var random = (min, max) => lodash.random(min, max);
27
- var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
28
- var timef = (format = "YYYY-MM-DD HH:mm:ss") => moment().format(format);
29
- var getDeviceGuid = () => {
30
- function S4() {
31
- return ((1 + Math.random()) * 65536 | 0).toString(16).substring(1);
32
- }
33
- return S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4();
34
- };
35
- var randomString = (length, type) => {
36
- let str = "0123456789";
37
- if (type === "Lower" || type === "All") {
38
- str += "abcdefghijklmnopqrstuvwxyz";
39
- }
40
- if (type === "Upper" || type === "All") {
41
- str += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
42
- }
43
- return lodash.sampleSize(str, length).join("");
44
- };
45
- var StrToObj = (Str, sep) => {
46
- const strObj = {};
47
- Str.split(sep).forEach((item) => {
48
- const [key, value] = item.split("=");
49
- if (key) {
50
- strObj[key] = value || "";
51
- }
52
- });
53
- return strObj;
54
- };
55
- var ObjToStr = (obj, sep) => {
56
- return Object.entries(obj).filter(([k, v]) => v).map(([k, v]) => `${k}=${v}`).join(sep) + sep;
57
- };
58
- var getEndOfDay = () => Number(moment().endOf("day").format("X")) - Number(moment().format("X"));
59
-
60
- // src/utils/config.ts
61
- import {
62
- copyConfigSync,
63
- logger,
64
- requireFileSync,
65
- watch,
66
- writeJsonSync
67
- } from "node-karin";
68
- import lodash2 from "node-karin/lodash";
69
- var Cfg = new class Cfg2 {
70
- #configCache = null;
71
- constructor() {
72
- copyConfigSync(dir.defConfigDir, dir.ConfigDir, [".json"]);
73
- this.loadConfig();
74
- watch(`${dir.ConfigDir}/config.json`, () => {
75
- logger.info("\u914D\u7F6E\u6587\u4EF6\u5DF2\u4FEE\u6539\uFF0C\u91CD\u65B0\u52A0\u8F7D\u914D\u7F6E");
76
- this.loadConfig();
77
- });
78
- }
79
- loadConfig() {
80
- const cfg = requireFileSync(`${dir.ConfigDir}/config.json`);
81
- const def = requireFileSync(`${dir.defConfigDir}/config.json`);
82
- const mergedConfig = this.mergeWithDefaults(cfg, def);
83
- this.#configCache = mergedConfig;
84
- return mergedConfig;
85
- }
86
- mergeWithDefaults(userConfig, defaultConfig) {
87
- const result = lodash2.merge({}, defaultConfig, userConfig);
88
- if (!lodash2.isEqual(result, userConfig)) {
89
- try {
90
- writeJsonSync(`${dir.ConfigDir}/config.json`, result);
91
- } catch (err) {
92
- logger.error(err);
93
- }
94
- }
95
- return result;
96
- }
97
- get(path, isArray = false) {
98
- const conf = JSON.parse(JSON.stringify(this.#configCache));
99
- const result = lodash2.get(conf, path);
100
- if (isArray) {
101
- if (!Array.isArray(result)) {
102
- logger.error(`\u914D\u7F6E\u8DEF\u5F84 ${path} \u4E0D\u662F\u6570\u7EC4\u7C7B\u578B`);
103
- return new EnhancedArray([], path);
104
- }
105
- return new EnhancedArray(result, path);
106
- }
107
- return result;
108
- }
109
- set(path, value) {
110
- const conf = JSON.parse(JSON.stringify(this.#configCache));
111
- lodash2.set(conf, path, value);
112
- this.#configCache = conf;
113
- try {
114
- writeJsonSync(`${dir.ConfigDir}/config.json`, conf);
115
- } catch (err) {
116
- logger.error(err);
117
- }
118
- }
119
- }();
120
- var EnhancedArray = class extends Array {
121
- #keyPath;
122
- constructor(items, path) {
123
- super(...items);
124
- this.#keyPath = path;
125
- }
126
- add(element) {
127
- this.push(element);
128
- Cfg.set(this.#keyPath, this.slice());
129
- return this;
130
- }
131
- remove(predicate, isIndex = false) {
132
- let newArr = [];
133
- if (isIndex && lodash2.isNumber(predicate)) {
134
- if (predicate < 0 || predicate >= this.length) {
135
- logger.error(`\u7D22\u5F15 ${predicate} \u8D85\u51FA\u8303\u56F4`);
136
- return this;
137
- }
138
- newArr = [...this.slice(0, predicate), ...this.slice(predicate + 1)];
139
- } else if (lodash2.isFunction(predicate)) {
140
- newArr = this.filter((item) => !predicate(item));
141
- } else {
142
- newArr = lodash2.without(this, predicate);
143
- }
144
- this.length = 0;
145
- this.push(...newArr);
146
- Cfg.set(this.#keyPath, this.slice());
147
- return this;
148
- }
149
- };
7
+ common_exports
8
+ } from "./chunk-WYRIRWT5.js";
150
9
 
151
10
  // src/core/api/mysApp.ts
152
11
  var version = { cn: "2.70.1", os: "1.5.0" };
@@ -167,9 +26,9 @@ var MysApp = Object.freeze({
167
26
 
168
27
  // src/core/api/define.ts
169
28
  import md5 from "md5";
170
- import { logger as logger2 } from "node-karin";
29
+ import { logger } from "node-karin";
171
30
  import axios, { AxiosHeaders } from "node-karin/axios";
172
- import lodash3 from "node-karin/lodash";
31
+ import lodash from "node-karin/lodash";
173
32
  var DefineMysApi = class {
174
33
  uidInfo;
175
34
  #apiInfo;
@@ -235,11 +94,11 @@ var DefineMysApi = class {
235
94
  response = axios.request(params);
236
95
  }
237
96
  } catch (err) {
238
- logger2.debug(`mys-core-requst[${logger2.green(`${Date.now() - start}ms`)}]: ${JSON.stringify(params, null, 2)}`);
97
+ logger.debug(`mys-core-requst[${logger.green(`${Date.now() - start}ms`)}]: ${JSON.stringify(params, null, 2)}`);
239
98
  return response;
240
99
  }
241
100
  const res = response.data;
242
- logger2.debug(`mys-core-requst[${logger2.green(`${Date.now() - start}ms`)}]: ${JSON.stringify(params, null, 2)} -> ${JSON.stringify(res, null, 2)}`);
101
+ logger.debug(`mys-core-requst[${logger.green(`${Date.now() - start}ms`)}]: ${JSON.stringify(params, null, 2)} -> ${JSON.stringify(res, null, 2)}`);
243
102
  if (!res) {
244
103
  return void 0;
245
104
  }
@@ -262,7 +121,7 @@ var DefineMysApi = class {
262
121
  return `${t},${r},${md5(DS)}`;
263
122
  }
264
123
  getDS2(saltKey, query = "", body = "") {
265
- const r = lodash3.random(100001, 2e5);
124
+ const r = lodash.random(100001, 2e5);
266
125
  const t = Math.floor(Date.now() / 1e3);
267
126
  return `${t},${r},${md5(`salt=${MysApp.salt[saltKey]}&t=${t}&r=${r}&b=${body}&q=${query}`)}`;
268
127
  }
@@ -400,6 +259,33 @@ var getUserFullInfo = (uidInfo) => new DefineMysApi((self, data) => ({
400
259
  HeaderFn: self.CookieHeaders
401
260
  }), uidInfo);
402
261
 
262
+ // src/core/user/deviceInfo.ts
263
+ import md52 from "md5";
264
+ import lodash2 from "node-karin/lodash";
265
+ var DeviceInfo2 = class {
266
+ static async get(Md5) {
267
+ return await MysDeviceInfoDB.findByPk(Md5);
268
+ }
269
+ static async create(UserInfo2, deviceInfo) {
270
+ const deviceMd5 = md52([
271
+ UserInfo2.userId,
272
+ deviceInfo.deviceId || "",
273
+ deviceInfo.name || "",
274
+ deviceInfo.board || "",
275
+ deviceInfo.model || "",
276
+ deviceInfo.oaid || "",
277
+ deviceInfo.androidVersion || "",
278
+ deviceInfo.fingerprint || "",
279
+ deviceInfo.product || ""
280
+ ].join("_"));
281
+ const MysDeviceInfo = await MysDeviceInfoDB.findByPk(deviceMd5, true);
282
+ await MysDeviceInfo.save(deviceInfo);
283
+ await UserInfo2.saveUserInfo({
284
+ deviceList: lodash2.uniq([...UserInfo2.deviceList, deviceMd5])
285
+ });
286
+ }
287
+ };
288
+
403
289
  // src/core/user/userInfo.ts
404
290
  var BaseUserInfo = class {
405
291
  userId;
@@ -434,16 +320,22 @@ var BaseUserInfo = class {
434
320
  getLtuidInfo(ltuid) {
435
321
  return Object.freeze(this.#ltuidMap.get(ltuid));
436
322
  }
323
+ getLtuidInfoList() {
324
+ return Array.from(this.#ltuidMap.values()).map((info) => Object.freeze(info));
325
+ }
326
+ async getDeviceList() {
327
+ return await MysDeviceInfoDB.findAllByPks(this.#deviceList);
328
+ }
437
329
  async saveUserInfo(data) {
438
- await this.UserInfo._save(data);
330
+ await this.UserInfo.save(data);
439
331
  }
440
- async saveMysAccountInfo(data) {
441
- let MysAccountInfo = this.#ltuidMap.get(data.ltuid);
332
+ async saveMysAccountInfo(ltuid, data) {
333
+ let MysAccountInfo = this.#ltuidMap.get(ltuid);
442
334
  if (!MysAccountInfo) {
443
- MysAccountInfo = await MysAccountInfoDB.findByPk(data.ltuid, true);
335
+ MysAccountInfo = await MysAccountInfoDB.findByPk(ltuid, true);
444
336
  }
445
- await MysAccountInfo._save(data);
446
- this.#ltuidMap.set(data.ltuid, { ...MysAccountInfo, ...data });
337
+ await MysAccountInfo.save(data);
338
+ this.#ltuidMap.set(ltuid, { ...MysAccountInfo, ...data });
447
339
  }
448
340
  };
449
341
  var refreshUidFnMap = /* @__PURE__ */ new Map();
@@ -502,8 +394,6 @@ var UserInfo = class extends BaseUserInfo {
502
394
  };
503
395
 
504
396
  export {
505
- common_exports,
506
- Cfg,
507
397
  MysApp,
508
398
  DefineMysApi,
509
399
  fetchQRcode,
@@ -514,6 +404,7 @@ export {
514
404
  getUserGameRolesByCookie,
515
405
  getUserFullInfo,
516
406
  MysHosts,
407
+ DeviceInfo2 as DeviceInfo,
517
408
  BaseUserInfo,
518
409
  UserInfo
519
410
  };
@@ -1,3 +1,6 @@
1
+ import {
2
+ common_exports
3
+ } from "./chunk-WYRIRWT5.js";
1
4
  import {
2
5
  dir
3
6
  } from "./chunk-JML6VYXN.js";
@@ -27,14 +30,14 @@ var DbBase = class {
27
30
  }
28
31
  readSync(path3, pk) {
29
32
  const result = json.readSync(path3);
30
- result._save = this.saveFile(pk);
33
+ result.save = this.saveFile(pk);
31
34
  return result;
32
35
  }
33
36
  readDirSync(pk) {
34
37
  const path3 = this.userPath(pk);
35
38
  const files = fs.readdirSync(path3);
36
39
  const result = {
37
- _save: this.saveDir(pk),
40
+ save: this.saveDir(pk),
38
41
  [this.model.primaryKeyAttribute]: pk
39
42
  };
40
43
  const filePromises = files.map(async (file) => {
@@ -46,14 +49,6 @@ var DbBase = class {
46
49
  });
47
50
  return result;
48
51
  }
49
- writeFileSync(pk, data) {
50
- const defData = this.schemaToJSON(pk);
51
- for (const key in data) {
52
- !(key in defData) && delete data[key];
53
- }
54
- json.writeSync(this.userPath(pk), lodash.merge({}, defData, data));
55
- return true;
56
- }
57
52
  writeDirSync(pk, data) {
58
53
  const path3 = this.userPath(pk);
59
54
  lodash.forEach(this.modelSchema, (value, key) => {
@@ -71,23 +66,27 @@ var DbBase = class {
71
66
  saveFile(pk) {
72
67
  return async (data) => {
73
68
  delete data[this.model.primaryKeyAttribute];
74
- this.writeFileSync(pk, data);
69
+ const defData = this.schemaToJSON(pk);
70
+ const userPath = this.userPath(pk);
71
+ json.writeSync(userPath, lodash.merge({}, defData, data));
72
+ return this.readSync(userPath, pk);
75
73
  };
76
74
  }
77
75
  saveDir(pk) {
78
76
  return async (data) => {
79
77
  delete data[this.model.primaryKeyAttribute];
80
78
  this.writeDirSync(pk, data);
79
+ return this.readDirSync(pk);
81
80
  };
82
81
  }
83
82
  saveSql(model, pk) {
84
83
  return async (data) => {
85
84
  delete data[this.model.primaryKeyAttribute];
86
- const Attributes = this.schemaToJSON(pk);
87
- for (const key in data) {
88
- !(key in Attributes) && delete data[key];
89
- }
90
- await model.update(data);
85
+ const result = await model.update(data);
86
+ return {
87
+ ...result.toJSON(),
88
+ save: this.saveSql(result, pk)
89
+ };
91
90
  };
92
91
  }
93
92
  };
@@ -155,13 +154,17 @@ var Sqlite3 = class extends DbBase {
155
154
  if (this.databaseType === "dir" /* Dir */) {
156
155
  fs2.mkdirSync(path3);
157
156
  this.writeDirSync(pk, data);
157
+ return {
158
+ ...data,
159
+ save: this.saveDir(pk)
160
+ };
158
161
  } else {
159
162
  json2.writeSync(path3, data);
163
+ return {
164
+ ...data,
165
+ save: this.saveFile(pk)
166
+ };
160
167
  }
161
- return {
162
- ...data,
163
- _save: this.saveFile(pk)
164
- };
165
168
  }
166
169
  return void 0;
167
170
  }
@@ -178,7 +181,7 @@ var Sqlite3 = class extends DbBase {
178
181
  if (!result) return void 0;
179
182
  return {
180
183
  ...result.toJSON(),
181
- _save: this.saveSql(result, pk)
184
+ save: this.saveSql(result, pk)
182
185
  };
183
186
  }
184
187
  }
@@ -204,7 +207,7 @@ var Sqlite3 = class extends DbBase {
204
207
  });
205
208
  return result.map((item) => ({
206
209
  ...item.toJSON(),
207
- _save: this.saveSql(item, item[this.model.primaryKeyAttribute])
210
+ save: this.saveSql(item, item[this.model.primaryKeyAttribute])
208
211
  }));
209
212
  }
210
213
  }
@@ -323,15 +326,35 @@ var MysAccountInfoDB = await DB.init(
323
326
  "db" /* Db */
324
327
  );
325
328
 
326
- // src/database/tables/mysUserInfo.ts
329
+ // src/database/tables/mysDeviceInfo.ts
327
330
  var DB2 = Database.get();
331
+ var MysDeviceInfoDB = await DB2.init(
332
+ dir.DataDir,
333
+ "mysDeviceInfoData",
334
+ {
335
+ md5: Database.PkColumn("STRING"),
336
+ deviceId: Database.Column("STRING", common_exports.getDeviceGuid),
337
+ deviceFp: Database.Column("STRING", ""),
338
+ name: Database.Column("STRING", ""),
339
+ board: Database.Column("STRING", ""),
340
+ model: Database.Column("STRING", ""),
341
+ oaid: Database.Column("STRING", ""),
342
+ androidVersion: Database.Column("STRING", ""),
343
+ fingerprint: Database.Column("STRING", ""),
344
+ product: Database.Column("STRING", "")
345
+ },
346
+ "db" /* Db */
347
+ );
348
+
349
+ // src/database/tables/mysUserInfo.ts
350
+ var DB3 = Database.get();
328
351
  var BaseMysUserInfoSchema = {
329
352
  userId: Database.PkColumn("STRING"),
330
353
  ltuids: Database.ArrayColumn("ltuids"),
331
354
  stuids: Database.ArrayColumn("stuids"),
332
355
  deviceList: Database.ArrayColumn("deviceList")
333
356
  };
334
- var MysUserInfoDB = await DB2.init(
357
+ var MysUserInfoDB = await DB3.init(
335
358
  dir.DataDir,
336
359
  "mysUserInfoData",
337
360
  BaseMysUserInfoSchema,
@@ -342,6 +365,7 @@ export {
342
365
  DbBase,
343
366
  Database,
344
367
  MysAccountInfoDB,
368
+ MysDeviceInfoDB,
345
369
  BaseMysUserInfoSchema,
346
370
  MysUserInfoDB
347
371
  };
@@ -0,0 +1,213 @@
1
+ import {
2
+ dir
3
+ } from "./chunk-JML6VYXN.js";
4
+ import {
5
+ __export
6
+ } from "./chunk-MLKGABMK.js";
7
+
8
+ // src/utils/common.ts
9
+ var common_exports = {};
10
+ __export(common_exports, {
11
+ ObjToStr: () => ObjToStr,
12
+ StrToObj: () => StrToObj,
13
+ getDeviceGuid: () => getDeviceGuid,
14
+ getEndOfDay: () => getEndOfDay,
15
+ random: () => random,
16
+ randomString: () => randomString,
17
+ sleep: () => sleep,
18
+ timef: () => timef
19
+ });
20
+ import lodash from "node-karin/lodash";
21
+ import moment from "node-karin/moment";
22
+ var random = (min, max) => lodash.random(min, max);
23
+ var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
24
+ var timef = (format = "YYYY-MM-DD HH:mm:ss") => moment().format(format);
25
+ var getDeviceGuid = () => {
26
+ function S4() {
27
+ return ((1 + Math.random()) * 65536 | 0).toString(16).substring(1);
28
+ }
29
+ return S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4();
30
+ };
31
+ var randomString = (length, type) => {
32
+ let str = "0123456789";
33
+ if (type === "Lower" || type === "All") {
34
+ str += "abcdefghijklmnopqrstuvwxyz";
35
+ }
36
+ if (type === "Upper" || type === "All") {
37
+ str += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
38
+ }
39
+ return lodash.sampleSize(str, length).join("");
40
+ };
41
+ var StrToObj = (Str, sep) => {
42
+ const strObj = {};
43
+ Str.split(sep).forEach((item) => {
44
+ const [key, value] = item.split("=");
45
+ if (key) {
46
+ strObj[key] = value || "";
47
+ }
48
+ });
49
+ return strObj;
50
+ };
51
+ var ObjToStr = (obj, sep) => {
52
+ return Object.entries(obj).filter(([k, v]) => v).map(([k, v]) => `${k}=${v}`).join(sep) + sep;
53
+ };
54
+ var getEndOfDay = () => Number(moment().endOf("day").format("X")) - Number(moment().format("X"));
55
+
56
+ // src/utils/config.ts
57
+ import {
58
+ existsSync,
59
+ logger,
60
+ requireFileSync,
61
+ watch,
62
+ writeJsonSync
63
+ } from "node-karin";
64
+ import lodash2 from "node-karin/lodash";
65
+ import path from "path";
66
+ var DefaultConfig = {
67
+ device: {
68
+ deviceName: "",
69
+ deviceBoard: "",
70
+ deviceModel: "",
71
+ androidVersion: "",
72
+ deviceFingerprint: "",
73
+ deviceProduct: ""
74
+ },
75
+ commands: {
76
+ ["BingMysDevice" /* BingMysDevice */]: {
77
+ cmds: [],
78
+ end: true,
79
+ flags: ""
80
+ }
81
+ }
82
+ };
83
+ var ConfigPath = path.join(dir.ConfigDir, "config.json");
84
+ var Config = class {
85
+ /**
86
+ * @description 配置文件路径
87
+ */
88
+ #ConfigPath;
89
+ /**
90
+ * @description 默认配置(只读)
91
+ */
92
+ #DefaultConfig;
93
+ /**
94
+ * @description 配置缓存
95
+ */
96
+ #configCache = null;
97
+ constructor(ConfigPath2, DefaultConfig2) {
98
+ this.#ConfigPath = ConfigPath2;
99
+ this.#DefaultConfig = Object.freeze(DefaultConfig2);
100
+ !existsSync(this.#ConfigPath) && writeJsonSync(this.#ConfigPath, this.#DefaultConfig);
101
+ this.loadConfig();
102
+ watch(this.#ConfigPath, () => {
103
+ logger.info("\u914D\u7F6E\u6587\u4EF6\u5DF2\u4FEE\u6539\uFF0C\u91CD\u65B0\u52A0\u8F7D\u914D\u7F6E");
104
+ this.loadConfig();
105
+ });
106
+ }
107
+ loadConfig() {
108
+ const config = requireFileSync(this.#ConfigPath);
109
+ const mergedConfig = this.mergeWithDefaults(config, this.#DefaultConfig);
110
+ this.#configCache = mergedConfig;
111
+ return mergedConfig;
112
+ }
113
+ mergeWithDefaults(userConfig, defaultConfig) {
114
+ const filterUserConfig = (user, defaults) => {
115
+ if (lodash2.isPlainObject(user) && lodash2.isPlainObject(defaults)) {
116
+ const filtered = {};
117
+ for (const key in defaults) {
118
+ if (Object.prototype.hasOwnProperty.call(user, key)) {
119
+ filtered[key] = filterUserConfig(user[key], defaults[key]);
120
+ }
121
+ }
122
+ return filtered;
123
+ }
124
+ return user;
125
+ };
126
+ const filteredUserConfig = filterUserConfig(userConfig, defaultConfig);
127
+ const result = lodash2.merge({}, defaultConfig, filteredUserConfig);
128
+ if (!lodash2.isEqual(result, userConfig)) {
129
+ try {
130
+ writeJsonSync(this.#ConfigPath, result);
131
+ } catch (err) {
132
+ logger.error(err);
133
+ }
134
+ }
135
+ return result;
136
+ }
137
+ /**
138
+ * @description 获取配置路径对应的默认配置
139
+ */
140
+ getDef(path2) {
141
+ const defConfig = JSON.parse(JSON.stringify(this.#DefaultConfig));
142
+ return lodash2.get(defConfig, path2);
143
+ }
144
+ get(path2, isArray = false) {
145
+ const conf = JSON.parse(JSON.stringify(this.#configCache));
146
+ const result = lodash2.get(conf, path2);
147
+ if (isArray) {
148
+ if (!Array.isArray(result)) {
149
+ logger.error(`\u914D\u7F6E\u8DEF\u5F84 ${path2} \u4E0D\u662F\u6570\u7EC4\u7C7B\u578B`);
150
+ return new EnhancedArray([], path2);
151
+ }
152
+ return new EnhancedArray(result, path2);
153
+ }
154
+ return result;
155
+ }
156
+ set(path2, value) {
157
+ const conf = JSON.parse(JSON.stringify(this.#configCache));
158
+ lodash2.set(conf, path2, value);
159
+ this.#configCache = conf;
160
+ try {
161
+ writeJsonSync(`${dir.ConfigDir}/config.json`, conf);
162
+ } catch (err) {
163
+ logger.error(err);
164
+ }
165
+ }
166
+ /**
167
+ * @description 获取触发指令正则表达式
168
+ */
169
+ getCommand(cmd) {
170
+ const command = this.get(`commands.${cmd}`);
171
+ return new RegExp(`^(${command.cmds.join("|")})${command.end ? "$" : ""}`, command.flags);
172
+ }
173
+ };
174
+ var Cfg = new Config(ConfigPath, DefaultConfig);
175
+ var EnhancedArray = class extends Array {
176
+ #keyPath;
177
+ constructor(items, path2) {
178
+ super(...items);
179
+ this.#keyPath = path2;
180
+ }
181
+ add(element) {
182
+ if (this.some((item) => lodash2.isEqual(item, element))) {
183
+ return this;
184
+ }
185
+ this.push(element);
186
+ Cfg.set(this.#keyPath, this.slice());
187
+ return this;
188
+ }
189
+ remove(predicate, isIndex = false) {
190
+ let newArr = [];
191
+ if (isIndex && lodash2.isNumber(predicate)) {
192
+ if (predicate < 0 || predicate >= this.length) {
193
+ logger.error(`\u7D22\u5F15 ${predicate} \u8D85\u51FA\u8303\u56F4`);
194
+ return this;
195
+ }
196
+ newArr = [...this.slice(0, predicate), ...this.slice(predicate + 1)];
197
+ } else if (lodash2.isFunction(predicate)) {
198
+ newArr = this.filter((item) => !predicate(item));
199
+ } else {
200
+ newArr = lodash2.without(this, predicate);
201
+ }
202
+ this.length = 0;
203
+ this.push(...newArr);
204
+ Cfg.set(this.#keyPath, this.slice());
205
+ return this;
206
+ }
207
+ };
208
+
209
+ export {
210
+ common_exports,
211
+ Config,
212
+ Cfg
213
+ };
@@ -0,0 +1,5 @@
1
+ import { a as DatabaseType, c as DatabaseClassInstance } from './base-BJv9XnQP.js';
2
+
3
+ type DatabaseFn = <T extends Record<string, any>, D extends DatabaseType>() => DatabaseClassInstance<T, D>;
4
+
5
+ export type { DatabaseFn as D };
@@ -1,5 +1,9 @@
1
1
  import { AxiosHeaders } from 'node-karin/axios';
2
- import { f as MysAccountType } from './base-B1BvQ4ol.js';
2
+ import { f as MysAccountType } from './base-BJv9XnQP.js';
3
+
4
+ declare const enum CoreCommand {
5
+ BingMysDevice = "BingMysDevice"
6
+ }
3
7
 
4
8
  interface BaseltuidInfo {
5
9
  ltuid: string;
@@ -41,7 +45,7 @@ interface UserGameRoleItem {
41
45
 
42
46
  interface RefreshUidData {
43
47
  data: {
44
- [key: string]: string[];
48
+ [key: string]: {};
45
49
  };
46
50
  names: {
47
51
  [key: string]: string;
@@ -53,7 +57,22 @@ interface StokenParms {
53
57
  mid: string;
54
58
  }
55
59
 
56
- interface Config {
60
+ interface ConfigType {
61
+ device: DeviceConfig;
62
+ commands: Record<CoreCommand, CommandItem>;
63
+ }
64
+ interface CommandItem {
65
+ cmds: string[];
66
+ end: boolean;
67
+ flags: string;
68
+ }
69
+ interface DeviceConfig {
70
+ deviceName: string;
71
+ deviceBoard: string;
72
+ deviceModel: string;
73
+ androidVersion: string;
74
+ deviceFingerprint: string;
75
+ deviceProduct: string;
57
76
  }
58
77
 
59
78
  declare const MysApp: Readonly<{
@@ -82,7 +101,7 @@ declare class DefineMysApi<R extends BaseMysRes & Record<string, any> | undefine
82
101
  });
83
102
  get isHoyolab(): boolean;
84
103
  getApi(data: D): Promise<{
85
- Method: "POST" | "GET";
104
+ Method: "GET" | "POST";
86
105
  Url: URL;
87
106
  Body: any;
88
107
  Headers: AxiosHeaders;
@@ -123,11 +142,6 @@ declare class DefineMysApi<R extends BaseMysRes & Record<string, any> | undefine
123
142
  query?: string;
124
143
  body?: any;
125
144
  }) => {
126
- 'x-rpc-app_version': string;
127
- 'x-rpc-client_type': string;
128
- 'x-rpc-language': string;
129
- Cookie: string;
130
- } | {
131
145
  then<TResult1 = {
132
146
  'x-rpc-app_version': string;
133
147
  'x-rpc-client_type': string;
@@ -157,7 +171,12 @@ declare class DefineMysApi<R extends BaseMysRes & Record<string, any> | undefine
157
171
  }>;
158
172
  [Symbol.toStringTag]: string;
159
173
  Cookie: string;
174
+ } | {
175
+ 'x-rpc-app_version': string;
176
+ 'x-rpc-client_type': string;
177
+ 'x-rpc-language': string;
178
+ Cookie: string;
160
179
  };
161
180
  }
162
181
 
163
- export { type BaseltuidInfo as B, type Config as C, type DeviceInfo as D, type MysApiInfoFn as M, type RefreshUidData as R, type StokenParms as S, type UidInfo as U, type BaseMysRes as a, type UserGameRoleItem as b, DefineMysApi as c, MysApp as d };
182
+ export { type BaseltuidInfo as B, CoreCommand as C, type DeviceInfo as D, type MysApiInfoFn as M, type RefreshUidData as R, type StokenParms as S, type UidInfo as U, type BaseMysRes as a, type UserGameRoleItem as b, type ConfigType as c, type CommandItem as d, type DeviceConfig as e, DefineMysApi as f, MysApp as g };
@@ -1,6 +1,6 @@
1
- import { c as DefineMysApi, a as BaseMysRes, B as BaseltuidInfo, b as UserGameRoleItem, S as StokenParms, R as RefreshUidData, C as Config } from '../define-CrfHwHnK.js';
2
- export { d as MysApp } from '../define-CrfHwHnK.js';
3
- import { B as BaseUserInfoType, b as DatabaseReturn, e as MysAccountInfoType, f as MysAccountType } from '../base-B1BvQ4ol.js';
1
+ import { f as DefineMysApi, a as BaseMysRes, B as BaseltuidInfo, b as UserGameRoleItem, S as StokenParms, R as RefreshUidData, C as CoreCommand, c as ConfigType } from '../define-pa_pWNWT.js';
2
+ export { g as MysApp } from '../define-pa_pWNWT.js';
3
+ import { B as BaseUserInfoType, b as DatabaseReturn, a as DatabaseType, e as MysAccountInfoType, h as MysDeviceInfoType, f as MysAccountType, g as MysDeviceInfoItem } from '../base-BJv9XnQP.js';
4
4
  export { dir as CoreDir } from '../dir.js';
5
5
  import 'node-karin/axios';
6
6
  import 'sequelize';
@@ -116,16 +116,24 @@ declare const MysHosts: Readonly<{
116
116
  declare class BaseUserInfo<U extends BaseUserInfoType> {
117
117
  #private;
118
118
  userId: BaseUserInfoType['userId'];
119
- UserInfo: DatabaseReturn<BaseUserInfoType>;
119
+ UserInfo: DatabaseReturn<BaseUserInfoType>[DatabaseType.Db];
120
120
  refresh: () => Promise<this>;
121
121
  constructor(userId: string);
122
122
  get ltuids(): string[];
123
123
  get stuids(): string[];
124
124
  get deviceList(): string[];
125
- initMysAccountInfo(UserInfo: DatabaseReturn<BaseUserInfoType>): Promise<void>;
126
- getLtuidInfo(ltuid: string): Readonly<DatabaseReturn<MysAccountInfoType> | undefined>;
127
- saveUserInfo(data: U): Promise<void>;
128
- saveMysAccountInfo(data: MysAccountInfoType): Promise<void>;
125
+ initMysAccountInfo(UserInfo: DatabaseReturn<BaseUserInfoType>[DatabaseType.Db]): Promise<void>;
126
+ getLtuidInfo(ltuid: string): Readonly<(MysAccountInfoType & {
127
+ save: (data: Partial<MysAccountInfoType>) => Promise<MysAccountInfoType & /*elided*/ any>;
128
+ }) | undefined>;
129
+ getLtuidInfoList(): Readonly<MysAccountInfoType & {
130
+ save: (data: Partial<MysAccountInfoType>) => Promise<MysAccountInfoType & /*elided*/ any>;
131
+ }>[];
132
+ getDeviceList(): Promise<(MysDeviceInfoType & {
133
+ save: (data: Partial<MysDeviceInfoType>) => Promise<MysDeviceInfoType & /*elided*/ any>;
134
+ })[]>;
135
+ saveUserInfo(data: Partial<U>): Promise<void>;
136
+ saveMysAccountInfo(ltuid: string, data: Partial<MysAccountInfoType>): Promise<void>;
129
137
  }
130
138
  declare class UserInfo extends BaseUserInfo<BaseUserInfoType> {
131
139
  static create(userId: string): Promise<BaseUserInfo<BaseUserInfoType>>;
@@ -144,6 +152,13 @@ declare class UserInfo extends BaseUserInfo<BaseUserInfoType> {
144
152
  }>;
145
153
  }
146
154
 
155
+ declare class DeviceInfo {
156
+ static get(Md5: string): Promise<(MysDeviceInfoType & {
157
+ save: (data: Partial<MysDeviceInfoType>) => Promise<MysDeviceInfoType & /*elided*/ any>;
158
+ }) | undefined>;
159
+ static create(UserInfo: BaseUserInfo<BaseUserInfoType>, deviceInfo: Partial<MysDeviceInfoItem>): Promise<void>;
160
+ }
161
+
147
162
  /**
148
163
  * 生成随机数
149
164
  * @param min - 最小值
@@ -203,21 +218,27 @@ declare namespace common {
203
218
  export { common_ObjToStr as ObjToStr, common_StrToObj as StrToObj, common_getDeviceGuid as getDeviceGuid, common_getEndOfDay as getEndOfDay, common_random as random, common_randomString as randomString, common_sleep as sleep, common_timef as timef };
204
219
  }
205
220
 
206
- declare const Cfg: {
207
- "__#1173@#configCache": Config | null;
208
- loadConfig(): Config;
209
- mergeWithDefaults(userConfig: Record<string, any>, defaultConfig: Record<string, any>): Config;
221
+ declare class Config<C extends Record<string, any>> {
222
+ #private;
223
+ constructor(ConfigPath: string, DefaultConfig: C);
224
+ loadConfig(): C;
225
+ mergeWithDefaults(userConfig: Record<string, any>, defaultConfig: Record<string, any>): C;
226
+ /**
227
+ * @description 获取配置路径对应的默认配置
228
+ */
229
+ getDef<T>(path: string): T;
210
230
  /**
211
- *
212
- * @param path 配置路径
213
- * @template T 配置类型
214
231
  * @description 获取配置路径对应的配置
215
- * @returns
216
232
  */
217
- get<T>(path: string, isArray: false): T;
233
+ get<T>(path: string, isArray?: false): T;
218
234
  get<T>(path: string, isArray: true): EnhancedArray<T>;
219
235
  set<T>(path: string, value: T): void;
220
- };
236
+ /**
237
+ * @description 获取触发指令正则表达式
238
+ */
239
+ getCommand(cmd: CoreCommand): RegExp;
240
+ }
241
+ declare const Cfg: Config<ConfigType>;
221
242
  declare class EnhancedArray<T> extends Array<T> {
222
243
  #private;
223
244
  constructor(items: T[], path: string);
@@ -225,4 +246,4 @@ declare class EnhancedArray<T> extends Array<T> {
225
246
  remove(predicate: T | ((item: T) => boolean), isIndex?: boolean): this;
226
247
  }
227
248
 
228
- export { BaseUserInfo, Cfg, DefineMysApi, MysHosts, UserInfo, common, fetchQRcode, getCookieAccountInfoByGameToken, getCookieTokenBySToken, getTokenByGameToken, getUserFullInfo, getUserGameRolesByCookie, queryQRcode };
249
+ export { BaseUserInfo, Cfg, Config, DefineMysApi, DeviceInfo, MysHosts, UserInfo, common, fetchQRcode, getCookieAccountInfoByGameToken, getCookieTokenBySToken, getTokenByGameToken, getUserFullInfo, getUserGameRolesByCookie, queryQRcode };
@@ -1,11 +1,10 @@
1
1
  import {
2
2
  BaseUserInfo,
3
- Cfg,
4
3
  DefineMysApi,
4
+ DeviceInfo,
5
5
  MysApp,
6
6
  MysHosts,
7
7
  UserInfo,
8
- common_exports,
9
8
  fetchQRcode,
10
9
  getCookieAccountInfoByGameToken,
11
10
  getCookieTokenBySToken,
@@ -13,18 +12,25 @@ import {
13
12
  getUserFullInfo,
14
13
  getUserGameRolesByCookie,
15
14
  queryQRcode
16
- } from "../chunk-4JTLXC2G.js";
17
- import "../chunk-7QISGXVH.js";
15
+ } from "../chunk-MV2UE7C7.js";
16
+ import "../chunk-NHUNEZXM.js";
17
+ import {
18
+ Cfg,
19
+ Config,
20
+ common_exports
21
+ } from "../chunk-WYRIRWT5.js";
22
+ import "../chunk-CQNW7LJI.js";
18
23
  import {
19
24
  dir
20
25
  } from "../chunk-JML6VYXN.js";
21
- import "../chunk-JIO4GOQA.js";
22
26
  import "../chunk-MLKGABMK.js";
23
27
  export {
24
28
  BaseUserInfo,
25
29
  Cfg,
30
+ Config,
26
31
  dir as CoreDir,
27
32
  DefineMysApi,
33
+ DeviceInfo,
28
34
  MysApp,
29
35
  MysHosts,
30
36
  UserInfo,
@@ -1,5 +1,5 @@
1
- import { D as DatabaseFn } from '../database-BDHrI6Vm.js';
2
- import { d as DatabaseClassStatic, c as DatabaseClassInstance, a as DatabaseType, M as ModelAttributes, b as DatabaseReturn, e as MysAccountInfoType, B as BaseUserInfoType } from '../base-B1BvQ4ol.js';
1
+ import { D as DatabaseFn } from '../database-byVXw91u.js';
2
+ import { d as DatabaseClassStatic, a as DatabaseType, c as DatabaseClassInstance, M as ModelAttributes, b as DatabaseReturn, e as MysAccountInfoType, h as MysDeviceInfoType, B as BaseUserInfoType } from '../base-BJv9XnQP.js';
3
3
  import * as sequelize from 'sequelize';
4
4
  import { DataTypes, ModelAttributeColumnOptions, Model, ModelStatic } from 'sequelize';
5
5
 
@@ -9,7 +9,7 @@ declare class DatabaseClass {
9
9
  /** 设置默认数据库 */
10
10
  default(Database: DatabaseFn, Static: DatabaseClassStatic): Promise<void>;
11
11
  /** 获取当前使用的数据库 */
12
- get<T extends Record<string, any>>(): DatabaseClassInstance<T>;
12
+ get<T extends Record<string, any>, D extends DatabaseType>(): DatabaseClassInstance<T, D>;
13
13
  get PkColumn(): (type: keyof typeof DataTypes, option?: Partial<ModelAttributeColumnOptions<Model>>) => ModelAttributeColumnOptions<Model>;
14
14
  get Column(): DatabaseClassStatic['Column'];
15
15
  get ArrayColumn(): DatabaseClassStatic['ArrayColumn'];
@@ -17,24 +17,25 @@ declare class DatabaseClass {
17
17
  }
18
18
  declare const Database: DatabaseClass;
19
19
 
20
- declare class DbBase<T extends Record<string, any>> {
20
+ declare class DbBase<T extends Record<string, any>, D extends DatabaseType> {
21
21
  model: ModelStatic<Model>;
22
22
  databasePath: string;
23
- databaseType: DatabaseType;
23
+ databaseType: D;
24
24
  modelName: string;
25
25
  modelSchema: ModelAttributes<Model>;
26
26
  schemaToJSON(pk: string): T;
27
27
  userPath(pk: string): string;
28
- readSync(path: string, pk: string): DatabaseReturn<T>;
29
- readDirSync(pk: string): DatabaseReturn<T>;
30
- writeFileSync(pk: string, data: Record<string, any>): boolean;
28
+ readSync(path: string, pk: string): DatabaseReturn<T>[DatabaseType.File];
29
+ readDirSync(pk: string): DatabaseReturn<T>[DatabaseType.Dir];
31
30
  writeDirSync(pk: string, data: Record<string, any>): boolean;
32
- saveFile(pk: string): (data: T) => Promise<void>;
33
- saveDir(pk: string): (data: T) => Promise<void>;
34
- saveSql(model: Model<any, any>, pk: string): (data: T) => Promise<void>;
31
+ saveFile(pk: string): (data: T) => Promise<DatabaseReturn<T>[DatabaseType.File]>;
32
+ saveDir(pk: string): (data: T) => Promise<DatabaseReturn<T>[DatabaseType.Dir]>;
33
+ saveSql(model: Model<any, any>, pk: string): (data: Partial<T>) => Promise<DatabaseReturn<T>[DatabaseType.Db]>;
35
34
  }
36
35
 
37
- declare const MysAccountInfoDB: DatabaseClassInstance<MysAccountInfoType>;
36
+ declare const MysAccountInfoDB: DatabaseClassInstance<MysAccountInfoType, DatabaseType.Db>;
37
+
38
+ declare const MysDeviceInfoDB: DatabaseClassInstance<MysDeviceInfoType, DatabaseType.Db>;
38
39
 
39
40
  declare const BaseMysUserInfoSchema: {
40
41
  userId: sequelize.ModelAttributeColumnOptions<sequelize.Model<any, any>>;
@@ -42,6 +43,6 @@ declare const BaseMysUserInfoSchema: {
42
43
  stuids: sequelize.ModelAttributeColumnOptions<sequelize.Model<any, any>>;
43
44
  deviceList: sequelize.ModelAttributeColumnOptions<sequelize.Model<any, any>>;
44
45
  };
45
- declare const MysUserInfoDB: DatabaseClassInstance<BaseUserInfoType>;
46
+ declare const MysUserInfoDB: DatabaseClassInstance<BaseUserInfoType, DatabaseType.Db>;
46
47
 
47
- export { BaseMysUserInfoSchema, Database, DbBase, MysAccountInfoDB, MysUserInfoDB };
48
+ export { BaseMysUserInfoSchema, Database, DbBase, MysAccountInfoDB, MysDeviceInfoDB, MysUserInfoDB };
@@ -3,15 +3,18 @@ import {
3
3
  Database,
4
4
  DbBase,
5
5
  MysAccountInfoDB,
6
+ MysDeviceInfoDB,
6
7
  MysUserInfoDB
7
- } from "../chunk-7QISGXVH.js";
8
+ } from "../chunk-NHUNEZXM.js";
9
+ import "../chunk-WYRIRWT5.js";
10
+ import "../chunk-CQNW7LJI.js";
8
11
  import "../chunk-JML6VYXN.js";
9
- import "../chunk-JIO4GOQA.js";
10
12
  import "../chunk-MLKGABMK.js";
11
13
  export {
12
14
  BaseMysUserInfoSchema,
13
15
  Database,
14
16
  DbBase,
15
17
  MysAccountInfoDB,
18
+ MysDeviceInfoDB,
16
19
  MysUserInfoDB
17
20
  };
@@ -1,10 +1,5 @@
1
- export { a as BaseMysRes, B as BaseltuidInfo, C as Config, D as DeviceInfo, M as MysApiInfoFn, R as RefreshUidData, S as StokenParms, U as UidInfo, b as UserGameRoleItem } from '../define-CrfHwHnK.js';
2
- export { D as DatabaseFn } from '../database-BDHrI6Vm.js';
3
- export { B as BaseUserInfoType, c as DatabaseClassInstance, d as DatabaseClassStatic, b as DatabaseReturn, a as DatabaseType, D as Dialect, M as ModelAttributes, e as MysAccountInfoType, f as MysAccountType } from '../base-B1BvQ4ol.js';
1
+ export { a as BaseMysRes, B as BaseltuidInfo, d as CommandItem, c as ConfigType, C as CoreCommand, e as DeviceConfig, D as DeviceInfo, M as MysApiInfoFn, R as RefreshUidData, S as StokenParms, U as UidInfo, b as UserGameRoleItem } from '../define-pa_pWNWT.js';
2
+ export { D as DatabaseFn } from '../database-byVXw91u.js';
3
+ export { B as BaseUserInfoType, c as DatabaseClassInstance, d as DatabaseClassStatic, b as DatabaseReturn, a as DatabaseType, D as Dialect, M as ModelAttributes, e as MysAccountInfoType, f as MysAccountType, g as MysDeviceInfoItem, h as MysDeviceInfoType } from '../base-BJv9XnQP.js';
4
4
  import 'node-karin/axios';
5
5
  import 'sequelize';
6
-
7
- interface MysDeviceInfoType {
8
- }
9
-
10
- export type { MysDeviceInfoType };
@@ -1,10 +1,12 @@
1
1
  import {
2
+ CoreCommand,
2
3
  DatabaseType,
3
4
  Dialect,
4
5
  MysAccountType
5
- } from "../chunk-JIO4GOQA.js";
6
+ } from "../chunk-CQNW7LJI.js";
6
7
  import "../chunk-MLKGABMK.js";
7
8
  export {
9
+ CoreCommand,
8
10
  DatabaseType,
9
11
  Dialect,
10
12
  MysAccountType
package/lib/web.config.js CHANGED
@@ -1,20 +1,45 @@
1
+ import {
2
+ Cfg
3
+ } from "./chunk-WYRIRWT5.js";
4
+ import "./chunk-CQNW7LJI.js";
1
5
  import {
2
6
  dir
3
7
  } from "./chunk-JML6VYXN.js";
4
8
  import "./chunk-MLKGABMK.js";
5
9
 
6
10
  // src/web.config.ts
7
- import { defineConfig } from "node-karin";
11
+ import { components, defineConfig } from "node-karin";
8
12
  var web_config_default = defineConfig({
9
13
  /** 插件信息配置 */
10
14
  info: {
11
15
  id: dir.name,
12
- name: dir.name,
13
- version: dir.version
16
+ name: "Mihoyo",
17
+ version: dir.version,
18
+ description: dir.pkg.description,
19
+ author: [
20
+ {
21
+ name: dir.pkg.author,
22
+ avatar: "https://github.com/babanbang.png"
23
+ }
24
+ ]
14
25
  },
15
26
  /** 动态渲染的组件 */
16
27
  components: () => [
17
- // 在这里面 添加各种子组件
28
+ // 基本调用方法
29
+ components.accordion.create("accordion-device-key", {
30
+ label: "\u9ED8\u8BA4\u8BBE\u5907\u4FE1\u606F",
31
+ children: [
32
+ components.accordion.createItem("accordion-device-item-key", {
33
+ title: "\u9ED8\u8BA4\u8BBE\u5907\u4FE1\u606F",
34
+ subtitle: "\u5982\u679C\u4E0D\u77E5\u9053\u8FD9\u662F\u4EC0\u4E48\u8BF7\u52FF\u4FEE\u6539",
35
+ children: Object.keys(Cfg.getDef("device")).map((key) => components.input.string(`device-${key}`, {
36
+ defaultValue: Cfg.get(`device.${key}`),
37
+ label: key,
38
+ isRequired: true
39
+ }))
40
+ })
41
+ ]
42
+ })
18
43
  ],
19
44
  /** 前端点击保存之后调用的方法 */
20
45
  save: (config) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "karin-plugin-mys-core",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "author": "babanbang",
5
5
  "type": "module",
6
6
  "description": "karin-plugin-mys-core",
@@ -60,7 +60,6 @@
60
60
  "files": [
61
61
  "/lib/**/*.js",
62
62
  "/lib/**/*.d.ts",
63
- "/config/*.json",
64
63
  "!lib/app.js"
65
64
  ],
66
65
  "publishConfig": {
@@ -1,3 +0,0 @@
1
- {
2
- "yiyanApi": "https://api.yujn.cn/api/sjyy.php"
3
- }
@@ -1,5 +0,0 @@
1
- import { c as DatabaseClassInstance } from './base-B1BvQ4ol.js';
2
-
3
- type DatabaseFn = <T extends Record<string, any>>() => DatabaseClassInstance<T>;
4
-
5
- export type { DatabaseFn as D };