Explorar o código

perf(task): update MysteryShop next_run

runhey %!s(int64=3) %!d(string=hai) anos
pai
achega
837e9d2599

BIN=BIN
module/config/i18n/zh_CN.qm


+ 2 - 0
module/config/i18n/zh_CN.ts

@@ -727,5 +727,7 @@ Refresh:直接刷新,如果刷新操作进入CD,将标记为失败并退
 	<message><source>WantedQuestsConfig</source><translation>悬赏</translation></message>
 	<message><source>Before End</source><translation>强制设定悬赏刷新前 X 分钟执行</translation></message>
 	<message><source>before_end_help</source><translation>默认'00:00:00'表示不使用这个功能,不可取负值,建议最后一小时才执行悬赏'01:00:00'</translation></message>
+	<message><source>Time Of Mystery</source><translation>强制设定出现神秘商店当天的执行时间</translation></message>
+	<message><source>time_of_mystery_help</source><translation>限定[00:00:01-23:30:00],这将使你无视掉调度器的Interval。保持默认'00:00:00'表示不使用</translation></message>
 </context>
 </TS>

+ 2 - 1
tasks/MysteryShop/config.py

@@ -1,13 +1,14 @@
 # This Python file uses the following encoding: utf-8
 # @author runhey
 # github https://github.com/runhey
-from datetime import timedelta
+from datetime import timedelta, datetime, time
 from pydantic import BaseModel, Field
 
 from tasks.Component.config_scheduler import Scheduler
 from tasks.Component.config_base import ConfigBase
 
 class ShopConfig(BaseModel):
+    time_of_mystery: time = Field(default=time(hour=0, minute=0, second=0), description='time_of_mystery_help')
     mystery_amulet: bool = Field(default=False)
     black_daruma_scrap: bool = Field(default=False)
     shop_kaiko_3: bool = Field(default=False)

+ 29 - 5
tasks/MysteryShop/script_task.py

@@ -24,8 +24,7 @@ class ScriptTask(FriendshipPoints, MysteryShopAssets, GeneralInvite):
         day_of_week = self.start_time.weekday()
         if day_of_week != 2 and day_of_week != 5:
             logger.warning('Today is not MysteryShop day')
-            self.set_next_run(task='MysteryShop', success=False, finish=True)
-            return
+            self.next_time(False)
         self.ui_get_current_page()
         self.ui_goto(page_mall)
         self.ui_click(self.I_ME_ENTER, self.I_MS_SHARE)
@@ -41,8 +40,7 @@ class ScriptTask(FriendshipPoints, MysteryShopAssets, GeneralInvite):
         self.back_mall()
 
 
-        self.set_next_run(task='MysteryShop', success=True, finish=True)
-        raise TaskEnd('MysteryShop')
+        self.next_time(True)
 
     def next_one(self):
         """
@@ -195,6 +193,33 @@ class ScriptTask(FriendshipPoints, MysteryShopAssets, GeneralInvite):
             sleep(0.5)
         logger.info('Shop reward done')
 
+    def next_time(self, success: bool = True):
+        """
+        重写
+        """
+        target_time: time = self.config.mystery_shop.shop_config.time_of_mystery
+        target_time: timedelta = timedelta(hours=target_time.hour, minutes=target_time.minute,
+                                           seconds=target_time.second)
+        if target_time == time(hour=0, minute=0, second=0):
+            if success:
+                self.set_next_run(task='MysteryShop', success=True, finish=True)
+            else:
+                self.set_next_run(task='MysteryShop', success=False, finish=True)
+            raise TaskEnd('MysteryShop')
+        now = datetime.now()
+        day_of_week = now.weekday()
+        now_datetime = now.replace(hour=0, minute=0, second=0, microsecond=0)
+        if 2 <= day_of_week <= 4:
+            # 如果现在是周三和周五之间,那就设定下一次为这周六(hour=0, minute=0, second=0)+ target_time
+            next_time = now_datetime + timedelta(days=5 - day_of_week) + target_time
+        elif 5 <= day_of_week <= 6 or 0 <= day_of_week <= 1:
+            # 如果现在是周六和周一之间,那就设定下一次为下周三(hour=0, minute=0, second=0)+ target_time
+            next_time = now_datetime + timedelta(days=6 - day_of_week + 3) + target_time
+        else:
+            next_time = now_datetime + timedelta(days=2 - day_of_week) + target_time
+            logger.warning('Now is not in the time of mystery shop')
+        self.set_next_run(task='MysteryShop', target=next_time)
+        raise TaskEnd('MysteryShop')
 
 
 if __name__ == '__main__':
@@ -208,4 +233,3 @@ if __name__ == '__main__':
     # t.run_shop(t.config.mystery_shop.shop_config)
     t.shop_reward()
 
-