Jelajahi Sumber

feat(module): save team flow

runhey 3 tahun lalu
induk
melakukan
13d5242b94

+ 1 - 1
module/logger.py

@@ -360,7 +360,7 @@ def hr(title, level=3):
         logger.info(f"[bold]<<< {title} >>>[/bold]", extra={"markup": True})
     if level == 0:
         logger.rule(characters='═')
-        logger.rule(title, characters='-')
+        logger.rule(title, characters='─')
         logger.rule(characters='═')
 
 

+ 43 - 6
module/team_flow/host.py

@@ -1,7 +1,7 @@
 # This Python file uses the following encoding: utf-8
 # @author runhey
 # github https://github.com/runhey
-
+from datetime import datetime, time
 from cached_property import cached_property
 
 from tasks.GlobalGame.config import TeamFlow, Transport
@@ -10,6 +10,7 @@ from module.team_flow.mqtt import Mqtt
 from module.config.config import Config
 from module.team_flow.player import Player
 from module.team_flow.task import Task
+from module.logger import logger
 
 def on_message(client, userdata, msg):
     userdata.match_topic[msg.topic](msg.payload)
@@ -52,18 +53,54 @@ class Host(Mqtt, Player):
         """
         for key, value in self.config.model.items():
             task_name: str = key
+            limit_time: time = None
+            limit_count: int = None
+            role: str = None
             if key == 'orochi':
-                continue
+                limit_time = value.orochi_config.limit_time
+                limit_count = value.orochi_config.limit_count
+                role = str(value.orochi_config.user_status)
             elif key == 'fallen_sun':
-                continue
+                limit_time = value.fallen_sun_config.limit_time
+                limit_count = value.fallen_sun_config.limit_count
+                role = str(value.fallen_sun_config.user_status)
             elif key == 'eternity_sea':
-                continue
+                limit_time = value.eternity_sea_config.limit_time
+                limit_count = value.eternity_sea_config.limit_count
+                role = str(value.eternity_sea_config.user_status)
             elif key == 'evo_zone':
-                continue
-            elif key == 'soul':
+                limit_time = value.evo_zone_config.limit_time
+                limit_count = value.evo_zone_config.limit_count
+                role = str(value.evo_zone_config.user_status)
+            elif key == 'exploration':
+                # TODO 等待探索完成
+                limit_time = time(minute=30)
+                limit_count = 50
+                role = str(value.evo_zone_config.user_status)
                 continue
             else:
                 continue
+            if not value.scheduler.enable:
+                continue
+            if task_name not in self.multi_tasks:
+                # 第一次
+                logger.info(f'First time to add {task_name} to multi_tasks')
+                self.multi_tasks[task_name] = Task(
+                    next_run=value.scheduler.next_run,
+                    target_run=value.scheduler.target_run,
+                    limit_time=limit_time,
+                    team_task=True,
+                    role=role,
+                    limit_count=limit_count,
+                )
+            else:
+                # 更新
+                logger.info(f'Update {task_name} to multi_tasks')
+                self.multi_tasks[task_name].next_run = value.scheduler.next_run
+                self.multi_tasks[task_name].limit_time = limit_time
+                self.multi_tasks[task_name].role = role
+                self.multi_tasks[task_name].limit_count = limit_count
+
 
 
 

+ 6 - 6
module/team_flow/player.py

@@ -7,27 +7,27 @@ from random import randint
 
 
 from module.config.config import Config
+from module.team_flow.task import Task
 
 class Player:
     def __init__(self, username: str):
         self.username = username
-        self.multi_tasks: list = []  # 缓存多人任务的列表
+        self.multi_tasks: dict[str: Task] = {}  # 缓存多人任务的列表
 
 
-    def publish_data(self) -> list:
+    def publish_data(self) -> dict:
         """
         提取要 发布的数据
         :return:
         """
-        result = []
-        for task in self.multi_tasks:
+        result = {}
+        for name, task in self.multi_tasks.items():
             item = {}
             if not task.team_task:
                 continue
-            item['task_name'] = task.task_name
             item['next_run'] = task.next_run
             item['role'] = task.role
             item['limit_time'] = task.limit_time
             item['limit_count'] = task.limit_count
-            result.append(item)
+            result[name] = item
         return result

+ 0 - 2
module/team_flow/task.py

@@ -11,7 +11,6 @@ from module.config.config import Config
 
 class Task:
     def __init__(self,
-                 task_name: str,  # 任务名称,必须是大写的
                  next_run: datetime,
                  limit_time: time,
                  target_run: datetime = None,
@@ -19,7 +18,6 @@ class Task:
                  role: str = 'leader',
                  limit_count: int = 0,
                  ):
-        self.task_name = task_name
         self.next_run = next_run
         self.target_run = target_run
         self.limit_time = limit_time

+ 22 - 1
tasks/EternitySea/config.py

@@ -2,10 +2,31 @@
 # @author runhey
 # github https://github.com/runhey
 from pydantic import BaseModel, Field
+from enum import Enum
+from datetime import datetime, time
 
 from tasks.Component.config_scheduler import Scheduler
 from tasks.Component.config_base import ConfigBase
+from tasks.Orochi.config import UserStatus
 
 
+class Layer(str, Enum):
+    ONE = '壹层'
+    TWO = '贰层'
+    THREE = '叁层'
+    FOUR = '肆层'
+
+class EternitySeaConfig(ConfigBase):
+    # 身份
+    user_status: UserStatus = Field(default=UserStatus.LEADER, description='user_status_help')
+    # 层数
+    layer: Layer = Field(default=Layer.FOUR, description='layer_help')
+    # 限制时间
+    limit_time: time = Field(default=time(minute=30), description='limit_time_help')
+    # 限制次数
+    limit_count: int = Field(default=50, description='limit_count_help')
+
 class EternitySea(ConfigBase):
-    scheduler: Scheduler = Field(default_factory=Scheduler)
+    scheduler: Scheduler = Field(default_factory=Scheduler)
+    eternity_sea_config: EternitySeaConfig = Field(default_factory=EternitySeaConfig)
+