|
@@ -1,65 +1,72 @@
|
|
|
-import json
|
|
|
|
|
from datetime import datetime, timedelta
|
|
from datetime import datetime, timedelta
|
|
|
-from enum import IntEnum
|
|
|
|
|
-from pydantic import Field, BaseModel
|
|
|
|
|
|
|
+from typing import Any, Dict
|
|
|
|
|
+
|
|
|
|
|
+from pydantic import Field, BaseModel, model_validator, model_serializer, ValidationError
|
|
|
|
|
+
|
|
|
|
|
+from deploy.logger import logger
|
|
|
from tasks.Component.SwitchAccount.switch_account_config import AccountInfo
|
|
from tasks.Component.SwitchAccount.switch_account_config import AccountInfo
|
|
|
-from tasks.Component.config_base import ConfigBase
|
|
|
|
|
|
|
+from tasks.Component.config_base import ConfigBase, DateTime
|
|
|
from tasks.Component.config_scheduler import Scheduler
|
|
from tasks.Component.config_scheduler import Scheduler
|
|
|
-from module.config.utils import write_file
|
|
|
|
|
from tasks.WantedQuests.config import CooperationSelectMaskDescription, CooperationSelectMask, CooperationType
|
|
from tasks.WantedQuests.config import CooperationSelectMaskDescription, CooperationSelectMask, CooperationType
|
|
|
-from typing import List, Any
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-class FindJadeConfig(BaseModel):
|
|
|
|
|
- find_jade_json_path: str = Field(default='./config/findjade/find_jade.json', description='json conf file path')
|
|
|
|
|
- # extra: str = Field(default='')
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-class FindJade(ConfigBase):
|
|
|
|
|
- scheduler: Scheduler = Field(default_factory=Scheduler)
|
|
|
|
|
- find_jade_config: FindJadeConfig = Field(default_factory=FindJadeConfig)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class InviteHistoryItem(BaseModel):
|
|
class InviteHistoryItem(BaseModel):
|
|
|
cooperation_type: CooperationType
|
|
cooperation_type: CooperationType
|
|
|
- time: datetime
|
|
|
|
|
|
|
+ time: DateTime
|
|
|
|
|
|
|
|
|
|
|
|
|
class InviteInfo(BaseModel):
|
|
class InviteInfo(BaseModel):
|
|
|
# 被邀请人员昵称
|
|
# 被邀请人员昵称
|
|
|
- name: str = "defaultName"
|
|
|
|
|
- default_invite_type: CooperationSelectMaskDescription
|
|
|
|
|
|
|
+ name: str = Field(default="")
|
|
|
|
|
+ default_invite_type: CooperationSelectMaskDescription = Field(default=CooperationSelectMaskDescription.JadeAndFood)
|
|
|
|
|
|
|
|
# 协作任务类型 上次邀请时间
|
|
# 协作任务类型 上次邀请时间
|
|
|
- invite_history: list[InviteHistoryItem]
|
|
|
|
|
|
|
+ invite_history_1: DateTime = Field(default=DateTime.fromisoformat("2023-01-01 00:00:00"),
|
|
|
|
|
+ description='invite_history_1_help')
|
|
|
|
|
+ invite_history_2: DateTime = Field(default=DateTime.fromisoformat("2023-01-01 00:00:00"),
|
|
|
|
|
+ description='invite_history_2_help')
|
|
|
|
|
+ invite_history_4: DateTime = Field(default=DateTime.fromisoformat("2023-01-01 00:00:00"),
|
|
|
|
|
+ description='invite_history_4_help')
|
|
|
|
|
+ invite_history_8: DateTime = Field(default=DateTime.fromisoformat("2023-01-01 00:00:00"),
|
|
|
|
|
+ description='invite_history_8_help')
|
|
|
|
|
|
|
|
def need_invite(self, ctype: CooperationType):
|
|
def need_invite(self, ctype: CooperationType):
|
|
|
if not ctype & CooperationSelectMask[self.default_invite_type.value]:
|
|
if not ctype & CooperationSelectMask[self.default_invite_type.value]:
|
|
|
return False
|
|
return False
|
|
|
- # 判断是否邀请过
|
|
|
|
|
- lastTime = max([filtered.time for filtered in
|
|
|
|
|
- filter(lambda x: x.cooperation_type == ctype, self.invite_history)],
|
|
|
|
|
- default=datetime(1970, 2, 2))
|
|
|
|
|
|
|
+ last_time = self.__getattribute__("invite_history_" + str(ctype))
|
|
|
|
|
|
|
|
now = datetime.now()
|
|
now = datetime.now()
|
|
|
- if now - lastTime > timedelta(hours=13):
|
|
|
|
|
|
|
+ if now - last_time > timedelta(hours=13):
|
|
|
return True
|
|
return True
|
|
|
- if (lastTime.hour >= 18 or lastTime.hour < 5) and (18 > now.hour >= 5):
|
|
|
|
|
|
|
+ if (last_time.hour >= 18 or last_time.hour < 5) and (18 > now.hour >= 5):
|
|
|
return True
|
|
return True
|
|
|
- if (5 <= lastTime.hour < 18) and now.hour >= 18:
|
|
|
|
|
|
|
+ if (5 <= last_time.hour < 18) and now.hour >= 18:
|
|
|
return True
|
|
return True
|
|
|
return False
|
|
return False
|
|
|
|
|
|
|
|
- def add_invite_history(self, ctype: CooperationType, name=None):
|
|
|
|
|
|
|
+ def update_invite_history(self, ctype: CooperationType, name=None):
|
|
|
if name != self.name:
|
|
if name != self.name:
|
|
|
return
|
|
return
|
|
|
- self.invite_history.append(InviteHistoryItem(cooperation_type=ctype, time=datetime.now()))
|
|
|
|
|
- pass
|
|
|
|
|
|
|
+ self.__setattr__("invite_history_" + str(ctype), datetime.now())
|
|
|
|
|
|
|
|
|
|
+ def is_valid(self):
|
|
|
|
|
+ return self.name != "" and self.name is not None
|
|
|
|
|
|
|
|
-class FindJadeJSON(BaseModel, extra='allow'):
|
|
|
|
|
- find_jade_accounts_info: list[AccountInfo]
|
|
|
|
|
- invite_info_list: list[InviteInfo]
|
|
|
|
|
|
|
+
|
|
|
|
|
+class FindJadeConfig(ConfigBase, extra='allow'):
|
|
|
|
|
+ # 被邀请人数
|
|
|
|
|
+ invite_info_count: int = Field(default=1, ge=1, description='invite_info_count_help')
|
|
|
|
|
+ # 小号数
|
|
|
|
|
+ sup_account_count: int = Field(default=1, ge=1, description='sup_account_count_help')
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+class FindJade(ConfigBase):
|
|
|
|
|
+ scheduler: Scheduler = Field(default_factory=Scheduler)
|
|
|
|
|
+ find_jade_config: FindJadeConfig = Field(default_factory=FindJadeConfig)
|
|
|
|
|
+ # 邀请人员信息
|
|
|
|
|
+ invite_info_list: list[InviteInfo] = None
|
|
|
|
|
+ # 小号信息
|
|
|
|
|
+ sup_account_list: list[AccountInfo] = None
|
|
|
|
|
|
|
|
def get_invite_name(self, ctype: CooperationType):
|
|
def get_invite_name(self, ctype: CooperationType):
|
|
|
for info in self.invite_info_list:
|
|
for info in self.invite_info_list:
|
|
@@ -72,16 +79,15 @@ class FindJadeJSON(BaseModel, extra='allow'):
|
|
|
for info in self.invite_info_list:
|
|
for info in self.invite_info_list:
|
|
|
if info.name != name:
|
|
if info.name != name:
|
|
|
continue
|
|
continue
|
|
|
- info.add_invite_history(ctype, name)
|
|
|
|
|
- self.updateHandle()
|
|
|
|
|
|
|
+ info.update_invite_history(ctype, name)
|
|
|
|
|
|
|
|
def update_account_login_history(self, account: AccountInfo):
|
|
def update_account_login_history(self, account: AccountInfo):
|
|
|
- accountInfoList = self.find_jade_accounts_info
|
|
|
|
|
|
|
+ accountInfoList = self.sup_account_list
|
|
|
for info in accountInfoList:
|
|
for info in accountInfoList:
|
|
|
if info.character != account.character or info.svr != account.svr:
|
|
if info.character != account.character or info.svr != account.svr:
|
|
|
continue
|
|
continue
|
|
|
info.last_complete_time = datetime.now()
|
|
info.last_complete_time = datetime.now()
|
|
|
- self.updateHandle()
|
|
|
|
|
|
|
+ break
|
|
|
|
|
|
|
|
def get_cooperation_type_mask(self) -> CooperationSelectMaskDescription:
|
|
def get_cooperation_type_mask(self) -> CooperationSelectMaskDescription:
|
|
|
"""
|
|
"""
|
|
@@ -94,11 +100,59 @@ class FindJadeJSON(BaseModel, extra='allow'):
|
|
|
name = CooperationSelectMask(result).name
|
|
name = CooperationSelectMask(result).name
|
|
|
return CooperationSelectMaskDescription(name)
|
|
return CooperationSelectMaskDescription(name)
|
|
|
|
|
|
|
|
- def save2file(self, conf_path):
|
|
|
|
|
- write_file(conf_path, self.dict())
|
|
|
|
|
-
|
|
|
|
|
- def updateHandle(self):
|
|
|
|
|
- """
|
|
|
|
|
- 需要刷新配置到磁盘时调用
|
|
|
|
|
- """
|
|
|
|
|
- pass
|
|
|
|
|
|
|
+ @model_validator(mode='before')
|
|
|
|
|
+ @classmethod
|
|
|
|
|
+ def validator_all(cls, v: dict) -> Any:
|
|
|
|
|
+ invite_info_count = v.get('find_jade_config', {}).get('invite_info_count', 1)
|
|
|
|
|
+ sup_account_count = v.get('find_jade_config', {}).get('sup_account_count', 1)
|
|
|
|
|
+
|
|
|
|
|
+ def validator_list(list_name, data, item_type=None, list_size=1):
|
|
|
|
|
+ if list_name not in data:
|
|
|
|
|
+ data[list_name] = []
|
|
|
|
|
+
|
|
|
|
|
+ remove_keys = []
|
|
|
|
|
+ for key, value in data.items():
|
|
|
|
|
+ if list_name == key or list_name not in key:
|
|
|
|
|
+ continue
|
|
|
|
|
+ try:
|
|
|
|
|
+ item = item_type(**value)
|
|
|
|
|
+ if item.is_valid():
|
|
|
|
|
+ data[list_name].append(item)
|
|
|
|
|
+ remove_keys.append(key)
|
|
|
|
|
+ except ValidationError as e:
|
|
|
|
|
+ pass
|
|
|
|
|
+ except TypeError as e:
|
|
|
|
|
+ pass
|
|
|
|
|
+
|
|
|
|
|
+ for key in remove_keys:
|
|
|
|
|
+ del data[key]
|
|
|
|
|
+
|
|
|
|
|
+ if item_type is not None:
|
|
|
|
|
+ if len(data[list_name]) < list_size:
|
|
|
|
|
+ for i in range(list_size - len(data[list_name])):
|
|
|
|
|
+ data[list_name].append(item_type())
|
|
|
|
|
+
|
|
|
|
|
+ validator_list('invite_info_list', v, InviteInfo, invite_info_count)
|
|
|
|
|
+ validator_list('sup_account_list', v, AccountInfo, sup_account_count)
|
|
|
|
|
+
|
|
|
|
|
+ return v
|
|
|
|
|
+
|
|
|
|
|
+ @model_serializer()
|
|
|
|
|
+ def serializer_model(self, value: Any) -> Dict[str, Any]:
|
|
|
|
|
+ properties = self.__dict__
|
|
|
|
|
+ data = {}
|
|
|
|
|
+
|
|
|
|
|
+ def v_dump(v):
|
|
|
|
|
+ try:
|
|
|
|
|
+ return v.model_dump()
|
|
|
|
|
+ except AttributeError as e:
|
|
|
|
|
+ logger.error(e)
|
|
|
|
|
+ return v
|
|
|
|
|
+
|
|
|
|
|
+ for key, value in properties.items():
|
|
|
|
|
+ if isinstance(value, list):
|
|
|
|
|
+ for index, v in enumerate(value):
|
|
|
|
|
+ data[f'{key}_{index + 1}'] = v_dump(v)
|
|
|
|
|
+ else:
|
|
|
|
|
+ data[key] = v_dump(value)
|
|
|
|
|
+ return data
|