62
62
from tasks .Hyakkiyakou .config import Hyakkiyakou
63
63
from tasks .HeroTest .config import HeroTest
64
64
65
+ from tasks .FindJade .config import FindJade
65
66
# ----------------------------------------------------------------------------------------------------------------------
66
67
67
68
# 每周任务---------------------------------------------------------------------------------------------------------------
@@ -119,6 +120,7 @@ class ConfigModel(ConfigBase):
119
120
goryou_realm : GoryouRealm = Field (default_factory = GoryouRealm )
120
121
hyakkiyakou : Hyakkiyakou = Field (default_factory = Hyakkiyakou )
121
122
hero_test : HeroTest = Field (default_factory = HeroTest )
123
+ find_jade : FindJade = Field (default_factory = FindJade )
122
124
123
125
# 这些是每周任务
124
126
true_orochi : TrueOrochi = Field (default_factory = TrueOrochi )
@@ -134,10 +136,6 @@ class ConfigModel(ConfigBase):
134
136
dokan : Dokan = Field (default_factory = Dokan )
135
137
abyss_shadows : AbyssShadows = Field (default_factory = AbyssShadows )
136
138
137
- # @validator('script')
138
- # def script_validator(cls, v):
139
- # if v is None:
140
- # return Script()
141
139
142
140
def __init__ (self , config_name : str = None ) -> None :
143
141
"""
@@ -225,7 +223,7 @@ def save(self) -> None:
225
223
226
224
:return:
227
225
"""
228
- self .write_json (self .config_name , self .dict ())
226
+ self .write_json (self .config_name , self .model_dump ())
229
227
230
228
@staticmethod
231
229
def type (key : str ) -> str :
@@ -243,16 +241,6 @@ def type(key: str) -> str:
243
241
classname = re .findall (r"'([^']*)'" , field_type )[0 ]
244
242
return classname
245
243
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
-
256
244
@staticmethod
257
245
def deep_get (obj , keys : str , default = None ):
258
246
"""
@@ -298,21 +286,20 @@ def script_task(self, task: str) -> dict:
298
286
logger .warning (f'{ task } is no inexistence' )
299
287
return {}
300
288
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
-
307
289
def extract_groups (sch ):
308
290
# 从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 )
310
299
311
- result = {}
312
300
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
316
303
317
304
def merge_value (groups , jsons , definitions ) -> list [dict ]:
318
305
# 将 groups的参数,同导出的json一起合并, 用于前端显示
@@ -326,20 +313,26 @@ def merge_value(groups, jsons, definitions) -> list[dict]:
326
313
item ["default" ] = value ["default" ]
327
314
item ["value" ] = jsons [key ] if key in jsons else value ["default" ]
328
315
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 )
332
318
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"]
334
322
result .append (item )
335
323
return result
336
324
337
- schema = task .schema ()
325
+ schema = task .model_json_schema ()
338
326
groups = extract_groups (schema )
327
+ groups_value = groups .copy ()
339
328
340
329
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" ])
343
336
344
337
return result
345
338
@@ -373,9 +366,15 @@ def script_set_arg(self, task: str, group: str, argument: str, value) -> bool:
373
366
374
367
task_object = getattr (self , task , None )
375
368
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
376
377
argument_object = getattr (group_object , argument , None )
377
- # print(group_object)
378
- # print(argument_object)
379
378
380
379
if argument_object is None :
381
380
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):
426
425
data = self .read_json (self .config_name )
427
426
super ().__init__ (** data )
428
427
428
+
429
429
if __name__ == "__main__" :
430
430
try :
431
431
c = ConfigModel ("oas1" )
432
432
except ValidationError as e :
433
433
print (e )
434
434
c = ConfigModel ()
435
435
436
- # c.save()
437
- print (c .script_task ('Orochi' ))
436
+ c .script_set_arg ('Duel' , 'test_list_2' , 'switch_all_soul' , 'false' )
0 commit comments