Skip to content

Commit e900042

Browse files
authored
Merge pull request #531 from ChengRanORZ/FindJade
feat(FindJade): 实现自动寻找勾协悬赏任务功能
2 parents 5f3b663 + 9594472 commit e900042

38 files changed

+804
-237
lines changed

config/findjade/find_jade.json

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"find_jade_accounts_info": [
3+
{
4+
"character": "小号1",
5+
"svr": "万事屋",
6+
"account": "150****4444",
7+
"accountAlias": "150★***4444#150*★**4444#150**★*4444#150***★4444",
8+
"appleOrAndroid": true,
9+
"last_complete_time": "2024-11-12 18:02:28.342305"
10+
},
11+
{
12+
"character": "小号2",
13+
"svr": "祈世之舞",
14+
"account": "150****4444",
15+
"accountAlias": "150★***4444#150*★**4444#150**★*4444#150***★4444",
16+
"appleOrAndroid": true,
17+
"last_complete_time": "2024-11-12 18:03:08.517909"
18+
}],
19+
"invite_info_list": [
20+
{
21+
"name": "大号1",
22+
"default_invite_type": "JadeAndFood",
23+
"invite_history": [
24+
{
25+
"cooperation_type": 2,
26+
"time": "2024-11-05 18:08:53.597534"
27+
}]
28+
},
29+
{
30+
"name": "大号2",
31+
"default_invite_type": "JadeAndFood",
32+
"invite_history": []
33+
}],
34+
"updateHandle": "<bound method ScriptTask.save_jade_json of <script_task.ScriptTask object at 0x000001C5E7229D50>>"
35+
}

module/config/config.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@ def __getattr__(self, name):
125125
def lock_config(self) -> Lock:
126126
return Lock()
127127

128+
@cached_property
129+
def notifier(self):
130+
notifier = Notifier(self.model.script.error.notify_config, enable=self.model.script.error.notify_enable)
131+
notifier.config_name = self.config_name.upper()
132+
logger.info(f'Notifier: {notifier.config_name}')
133+
return notifier
134+
128135
def gui_args(self, task: str) -> str:
129136
"""
130137
获取给gui显示的参数
@@ -378,12 +385,7 @@ def task_delay(self, task: str, start_time: datetime = None,
378385
logger.attr(f'{task}.scheduler.next_run', next_run)
379386

380387

381-
@cached_property
382-
def notifier(self):
383-
notifier = Notifier(self.model.script.error.notify_config, enable=self.model.script.error.notify_enable)
384-
notifier.config_name = self.config_name.upper()
385-
logger.info(f'Notifier: {notifier.config_name}')
386-
return notifier
388+
387389

388390
if __name__ == '__main__':
389391
config = Config(config_name='oas1')

module/config/config_menu.py

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def __init__(self) -> None:
3232
"Exploration",
3333
"Hyakkiyakou",
3434
"HeroTest",
35+
"FindJade"
3536
]
3637
# 阴阳寮
3738
self.menu["Guild"] = ['KekkaiUtilize', 'KekkaiActivation', 'RealmRaid', 'RyouToppa', 'Dokan', 'CollectiveMissions',

module/config/config_model.py

+36-37
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
from tasks.Hyakkiyakou.config import Hyakkiyakou
6363
from tasks.HeroTest.config import HeroTest
6464

65+
from tasks.FindJade.config import FindJade
6566
# ----------------------------------------------------------------------------------------------------------------------
6667

6768
# 每周任务---------------------------------------------------------------------------------------------------------------
@@ -119,6 +120,7 @@ class ConfigModel(ConfigBase):
119120
goryou_realm: GoryouRealm = Field(default_factory=GoryouRealm)
120121
hyakkiyakou: Hyakkiyakou = Field(default_factory=Hyakkiyakou)
121122
hero_test: HeroTest = Field(default_factory=HeroTest)
123+
find_jade: FindJade = Field(default_factory=FindJade)
122124

123125
# 这些是每周任务
124126
true_orochi: TrueOrochi = Field(default_factory=TrueOrochi)
@@ -134,10 +136,6 @@ class ConfigModel(ConfigBase):
134136
dokan: Dokan = Field(default_factory=Dokan)
135137
abyss_shadows: AbyssShadows = Field(default_factory=AbyssShadows)
136138

137-
# @validator('script')
138-
# def script_validator(cls, v):
139-
# if v is None:
140-
# return Script()
141139

142140
def __init__(self, config_name: str=None) -> None:
143141
"""
@@ -225,7 +223,7 @@ def save(self) -> None:
225223
226224
:return:
227225
"""
228-
self.write_json(self.config_name, self.dict())
226+
self.write_json(self.config_name, self.model_dump())
229227

230228
@staticmethod
231229
def type(key: str) -> str:
@@ -243,16 +241,6 @@ def type(key: str) -> str:
243241
classname = re.findall(r"'([^']*)'", field_type)[0]
244242
return classname
245243

246-
# @root_validator
247-
# def on_on_property_change(cls, values):
248-
# """
249-
# 当属性改变时保存
250-
# :param values:
251-
# :return:
252-
# """
253-
# logger.info(f'property change auto save')
254-
# cls.save()
255-
256244
@staticmethod
257245
def deep_get(obj, keys: str, default=None):
258246
"""
@@ -298,21 +286,20 @@ def script_task(self, task: str) -> dict:
298286
logger.warning(f'{task} is no inexistence')
299287
return {}
300288

301-
def properties_groups(sch) -> dict:
302-
properties = {}
303-
for key, value in sch["properties"].items():
304-
properties[key] = re.search(r"/([^/]+)$", value['$ref']).group(1)
305-
return properties
306-
307289
def extract_groups(sch):
308290
# 从schema 中提取未解析的group的数据
309-
properties = properties_groups(sch)
291+
# properties = properties_groups(sch)
292+
results = {}
293+
properties = {}
294+
for key, value in sch["properties"].items():
295+
if 'items' in value:
296+
properties[key] = re.search(r"/([^/]+)$", value['items']['$ref']).group(1)
297+
else:
298+
properties[key] = re.search(r"/([^/]+)$", value['$ref']).group(1)
310299

311-
result = {}
312300
for key, value in properties.items():
313-
result[key] = sch["definitions"][value]
314-
315-
return result
301+
results[key] = sch["$defs"][value]
302+
return results
316303

317304
def merge_value(groups, jsons, definitions) -> list[dict]:
318305
# 将 groups的参数,同导出的json一起合并, 用于前端显示
@@ -326,20 +313,26 @@ def merge_value(groups, jsons, definitions) -> list[dict]:
326313
item["default"] = value["default"]
327314
item["value"] = jsons[key] if key in jsons else value["default"]
328315
item["type"] = value["type"] if "type" in value else "enum"
329-
if 'allOf' in value:
330-
# list
331-
enum_key = re.search(r"/([^/]+)$", value['allOf'][0]['$ref']).group(1)
316+
if '$ref' in value: # list
317+
enum_key = re.search(r"/([^/]+)$", value['$ref']).group(1)
332318
item["enumEnum"] = definitions[enum_key]["enum"]
333-
# TODO: 最大值最小值
319+
# if 'allOf' in value:
320+
# enum_key = re.search(r"/([^/]+)$", value['allOf'][0]['$ref']).group(1)
321+
# item["enumEnum"] = definitions[enum_key]["enum"]
334322
result.append(item)
335323
return result
336324

337-
schema = task.schema()
325+
schema = task.model_json_schema()
338326
groups = extract_groups(schema)
327+
groups_value = groups.copy()
339328

340329
result: dict[str, list] = {}
341-
for key, value in task.dict().items():
342-
result[key] = merge_value(groups[key], value, schema["definitions"])
330+
for key, value in task.model_dump().items():
331+
if key not in groups:
332+
for group_name in groups.keys():
333+
if group_name in key:
334+
groups_value[key] = groups[group_name]
335+
result[key] = merge_value(groups_value[key], value, schema["$defs"])
343336

344337
return result
345338

@@ -373,9 +366,15 @@ def script_set_arg(self, task: str, group: str, argument: str, value) -> bool:
373366

374367
task_object = getattr(self, task, None)
375368
group_object = getattr(task_object, group, None)
369+
if group_object is None: # deal list
370+
matchs = re.findall(r'\d+', group)
371+
index = int(matchs[-1]) - 1 if matchs else None
372+
task_object_list = list(dict(task_object))
373+
for k, v in dict(task_object).items():
374+
if k not in group:
375+
continue
376+
group_object = v[index] if group_object is None else None
376377
argument_object = getattr(group_object, argument, None)
377-
# print(group_object)
378-
# print(argument_object)
379378

380379
if argument_object is None:
381380
logger.error(f'Set arg {task}.{group}.{argument}.{value} failed')
@@ -426,12 +425,12 @@ def reset_datetime_for_all_enabled_tasks(self, task_datetime: datetime):
426425
data = self.read_json(self.config_name)
427426
super().__init__(**data)
428427

428+
429429
if __name__ == "__main__":
430430
try:
431431
c = ConfigModel("oas1")
432432
except ValidationError as e:
433433
print(e)
434434
c = ConfigModel()
435435

436-
# c.save()
437-
print(c.script_task('Orochi'))
436+
c.script_set_arg('Duel', 'test_list_2', 'switch_all_soul', 'false')

requirements-in.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ anytree==2.8.0
1111
pywin32==306
1212
zerorpc==0.6.3
1313
wrapt==1.15.0
14-
pydantic==1.10.7
14+
pydantic==2.10.0
1515
inflection==0.5.1
1616
tqdm==4.65.0
1717
ppocr-onnx==0.0.3.9

requirements.txt

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88

99
adbutils==0.11.0 # via -r requirements-in.txt, uiautomator2
10+
annotated-types==0.7.0 # via pydantic
1011
anyio==3.7.1 # via fastapi, starlette
1112
anytree==2.8.0 # via -r requirements-in.txt
1213
apkutils2==1.0.0 # via adbutils
@@ -53,7 +54,8 @@ protobuf==4.25.1 # via onnxruntime
5354
py==1.11.0 # via retry
5455
pyclipper==1.3.0.post5 # via ppocr-onnx
5556
pycparser==2.21 # via cffi
56-
pydantic==1.10.7 # via -r requirements-in.txt, fastapi
57+
pydantic==2.10.0 # via -r requirements-in.txt, fastapi
58+
pydantic-core==2.27.0 # via pydantic
5759
pyelftools==0.30 # via apkutils2
5860
pygments==2.17.2 # via rich
5961
pyparsing==3.1.1 # via packaging
@@ -70,7 +72,7 @@ sniffio==1.3.0 # via anyio
7072
starlette==0.27.0 # via fastapi
7173
sympy==1.12 # via onnxruntime
7274
tqdm==4.65.0 # via -r requirements-in.txt
73-
typing-extensions==4.9.0 # via fastapi, pydantic, uvicorn
75+
typing-extensions==4.12.2 # via fastapi, pydantic, pydantic-core, uvicorn
7476
uiautomator2==2.16.17 # via -r requirements-in.txt
7577
uiautomator2cache==0.3.0.1 # via -r requirements-in.txt
7678
urllib3==2.1.0 # via requests
Binary file not shown.
Binary file not shown.
Binary file not shown.

tasks/Component/SwitchAccount/switch_account_config.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
from datetime import datetime
21
from pydantic import Field, BaseModel
32

3+
from tasks.Component.config_base import DateTime
4+
45

56
class AccountInfo(BaseModel):
67
"""
@@ -18,7 +19,7 @@ class AccountInfo(BaseModel):
1819
accountAlias: str = Field(default="", description="")
1920
appleOrAndroid: bool = Field(default=True, description="apple_or_android_help")
2021
# 上一次执行成功的时间 ,防止出错时重复登录浪费时间
21-
last_complete_time: datetime = Field(default=datetime(1970, 1, 1, 1, 1, 1), description="last_complete_time_help")
22+
last_complete_time: DateTime = Field(default=DateTime.fromisoformat("2023-01-01 00:00:00"), description="last_complete_time_help")
2223

2324
def is_account_alias(self, ocr_account):
2425
tmp_account = AccountInfo.preprocessAccount(self.account)
@@ -43,3 +44,6 @@ def preprocessAccount(account: str):
4344
@rtype:
4445
"""
4546
return account.split('@')[0]
47+
48+
def is_valid(self):
49+
return self.character!="" and self.character is not None

0 commit comments

Comments
 (0)