@bettergi/utils 0.1.1 → 0.1.2

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/README.md CHANGED
@@ -149,3 +149,12 @@ const body2 = await postForBody("https://example.com/", undefined, { "User-Agent
149
149
  log.info(`GET 请求响应体内容${body1}`);
150
150
  log.info(`POST 请求响应体内容${body2}`);
151
151
  ```
152
+
153
+ ### 日期时间
154
+
155
+ ```ts
156
+ // 获取下一个(含当日)凌晨4点的时间
157
+ const d1 = getNextDay4AM();
158
+ // 获取下一个(含当日)周一凌晨4点的时间
159
+ const d2 = getNextMonday4AM();
160
+ ```
package/dist/game.js CHANGED
@@ -101,10 +101,11 @@ export const setTimeTo = async (hour, minute, options) => {
101
101
  .map(rad => ({ x: radius * Math.cos(rad), y: radius * Math.sin(rad) }))
102
102
  // 计算绝对坐标
103
103
  .map(p => ({ x: Math.round(p.x + centerX), y: Math.round(p.y + centerY) })));
104
- // 3.拨动指针
104
+ // 3.调整时间
105
105
  await withGameMetrics(1920, 1080, 1.5, async () => {
106
+ // 拨动指针
106
107
  await mouseMoveAlongWaypoints(waypoints, { shouldDrag: true });
107
- // 3.点击确认按钮,等待调整结束
108
+ // 点击确认按钮,等待调整结束
108
109
  await assertRegionAppearing(() => findTextInDirection("时间少于", "south-east", { contains: true }), "调整时间超时", () => {
109
110
  findTextInDirection("确认", "south-east")?.click();
110
111
  }, { maxAttempts: 20, retryInterval: 1000 });
@@ -120,12 +121,12 @@ export const setTimeTo = async (hour, minute, options) => {
120
121
  export const setTime = async (period, options) => {
121
122
  switch (period) {
122
123
  case "night":
123
- return setTimeTo(0, 0, options);
124
+ return setTimeTo(0, 5, options);
124
125
  case "morning":
125
- return setTimeTo(6, 0, options);
126
+ return setTimeTo(6, 5, options);
126
127
  case "noon":
127
- return setTimeTo(12, 0, options);
128
+ return setTimeTo(12, 5, options);
128
129
  case "evening":
129
- return setTimeTo(18, 0, options);
130
+ return setTimeTo(18, 5, options);
130
131
  }
131
132
  };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,16 @@
1
+ /** 断言 */
1
2
  export * from "./asserts";
2
- export * from "./workflow";
3
+ /** 游戏操作 */
3
4
  export * from "./game";
5
+ /** HTTP 请求 */
4
6
  export * from "./http";
7
+ /** 鼠标操作 */
5
8
  export * from "./mouse";
9
+ /** 图像识别 */
6
10
  export * from "./ocr";
11
+ /** 数据存储 */
7
12
  export * from "./store";
13
+ /** 日期时间 */
14
+ export * from "./time";
15
+ /** 流程控制 */
16
+ export * from "./workflow";
package/dist/index.js CHANGED
@@ -1,7 +1,16 @@
1
+ /** 断言 */
1
2
  export * from "./asserts";
2
- export * from "./workflow";
3
+ /** 游戏操作 */
3
4
  export * from "./game";
5
+ /** HTTP 请求 */
4
6
  export * from "./http";
7
+ /** 鼠标操作 */
5
8
  export * from "./mouse";
9
+ /** 图像识别 */
6
10
  export * from "./ocr";
11
+ /** 数据存储 */
7
12
  export * from "./store";
13
+ /** 日期时间 */
14
+ export * from "./time";
15
+ /** 流程控制 */
16
+ export * from "./workflow";
package/dist/time.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * 获取下一个(含当日)凌晨4点的时间
3
+ */
4
+ export declare const getNextDay4AM: () => Date;
5
+ /**
6
+ * 获取下一个(含当日)周一凌晨4点的时间
7
+ */
8
+ export declare const getNextMonday4AM: () => Date;
package/dist/time.js ADDED
@@ -0,0 +1,25 @@
1
+ /**
2
+ * 获取下一个(含当日)凌晨4点的时间
3
+ */
4
+ export const getNextDay4AM = () => {
5
+ const now = new Date();
6
+ const result = new Date(now);
7
+ result.setHours(4, 0, 0, 0);
8
+ // 如果当前时间在4点前,则返回今天4点,否则返回明天4点
9
+ const daysUntilNextDay = now.getHours() < 4 ? 0 : 1;
10
+ result.setDate(now.getDate() + daysUntilNextDay);
11
+ return result;
12
+ };
13
+ /**
14
+ * 获取下一个(含当日)周一凌晨4点的时间
15
+ */
16
+ export const getNextMonday4AM = () => {
17
+ const now = new Date();
18
+ const result = new Date(now);
19
+ result.setHours(4, 0, 0, 0);
20
+ // 如果当前为周一且时间在4点前,则返回今天4点,否则返回下一个周一的4点
21
+ const currentDay = now.getDay();
22
+ const daysUntilNextMonday = currentDay === 1 && now.getHours() < 4 ? 0 : (8 - currentDay) % 7;
23
+ result.setDate(now.getDate() + daysUntilNextMonday);
24
+ return result;
25
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bettergi/utils",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "开发 BetterGI 脚本常用工具集",
5
5
  "type": "module",
6
6
  "author": "Bread Grocery<https://github.com/breadgrocery>",