@@ -271,26 +271,12 @@ class LimitUnitListConfig(UnitConfigMixin, MultiSearchConfig):
271271 def __init__ (self , key : str , desc : str ):
272272 super ().__init__ (key , desc , [], db .limit_unit_condition_candidate )
273273
274- class ConditionalExecutionMixin :
275- """Mixin for conditional execution configs."""
276- async def check_campaigns (self , campaign_list , client_data ):
277- """Check if any campaign in the list is active."""
278- hit = [campaign for campaign in campaign_list if client_data .is_campaign (campaign )]
279- return hit
280-
281- class ConditionalExecution1Config (ConditionalExecutionMixin , MultiChoiceConfig ):
282- def __init__ (self , key : str , desc : str = "执行条件" , default = [], check : bool = True ):
283- super ().__init__ (key , desc , default , ['无庆典' , 'n庆典' , 'h庆典' , 'vh庆典' , '总是执行' ])
274+ class ConditionalExecutionWrapper (Config ):
275+ def __init__ (self , key : str , desc : str , default : Any , candidates : Union [Callable , List ], check : bool ):
276+ super ().__init__ (key , desc , default , candidates )
284277 self .check_enabled = check
285-
286- async def do_check (self , client : pcrclient ) -> Tuple [bool , str ]:
287-
288- run_time = self .get_value ()
289- hit = await self .check_campaigns (run_time , client .data )
290-
291- if hit :
292- return True , "今日" + ',' .join (hit ) + ",执行"
293- return False , "今日不符合执行条件"
278+
279+ async def do_check (self , client : Union [pcrclient , None ] = None ) -> Tuple [bool , str ]: ...
294280
295281 def wrap_init (self , cls : Type , sself : Type ):
296282 super ().wrap_init (cls , sself )
@@ -309,68 +295,45 @@ async def new_do_check(*args, **kwargs):
309295
310296 cls .do_check = new_do_check
311297
298+ class ConditionalExecutionClient (ConditionalExecutionWrapper ):
299+ async def do_check (self , client : pcrclient ) -> Tuple [bool , str ]:
300+ run_time = self .get_value ()
301+ hit = [campaign for campaign in run_time if client .data .is_campaign (campaign )]
302+ if hit :
303+ return True , "今日" + ',' .join (hit ) + ",执行"
304+ return False , "今日不符合执行条件"
312305
313- class ConditionalExecution2Config (ConditionalExecutionMixin , MultiChoiceConfig ):
314- def __init__ (self , key : str , desc : str = "执行条件" , default = [], check : bool = True ):
315- super ().__init__ (key , desc , default , ['n3以上前夕' , 'n3以上首日午前' , 'h3以上前夕' , '会战前夕' , '会战期间' , '总是执行' ])
316- self .check_enabled = check
317-
306+ class ConditionalExecutionDB (ConditionalExecutionWrapper , MultiChoiceConfig ):
318307 async def do_check (self ) -> Tuple [bool , str ]:
319-
320308 run_time = self .get_value ()
321309 hit = [campaign for campaign in run_time if db .is_campaign (campaign )]
322-
323310 if hit :
324311 return True , "今日" + ',' .join (hit ) + ",执行"
325312 return False , "今日不符合执行条件"
326-
327- def wrap_init (self , cls : Type , sself : Type ):
328- super ().wrap_init (cls , sself )
329- if sself .check_enabled and hasattr (cls , 'do_check' ):
330- old_do_check = cls .do_check
331313
332- async def new_do_check (* args , ** kwargs ):
333- ok , msg = await old_do_check (* args , ** kwargs )
334- if not ok :
335- return False , msg
336-
337- ok , msg2 = await sself .do_check (* args , ** kwargs )
338- if not ok :
339- return False , msg + msg2
340- return True , msg + msg2
341-
342- cls .do_check = new_do_check
343-
344-
345- class ConditionalNotExecutionConfig (ConditionalExecutionMixin , MultiChoiceConfig ):
346- def __init__ (self , key : str , desc : str = "不执行条件" , default = [], check : bool = True ):
347- super ().__init__ (key , desc , default , ['n2' , 'n3' , 'n4及以上' , 'h2' , 'h3及以上' , 'vh2' , 'vh3及以上' ])
348- self .check_enabled = check
349-
314+ class ConditionalNotExecutionClient (ConditionalExecutionWrapper ):
350315 async def do_check (self , client : pcrclient ) -> Tuple [bool , str ]:
351316 run_time = self .get_value ()
352- hit = await self .check_campaigns (run_time , client .data )
353-
317+ hit = [campaign for campaign in run_time if client .data .is_campaign (campaign )]
354318 if hit :
355319 return False , "今日" + ',' .join (hit ) + ",不执行"
356320 return True , ""
357-
358- def wrap_init (self , cls : Type , sself : Type ):
359- super ().wrap_init (cls , sself )
360- if sself .check_enabled and hasattr (cls , 'do_check' ):
361- old_do_check = cls .do_check
362321
363- async def new_do_check (* args , ** kwargs ):
364- ok , msg = await old_do_check (* args , ** kwargs )
365- if not ok :
366- return False , msg
322+ class ConditionalExecution1Config (ConditionalExecutionClient , MultiChoiceConfig ):
323+ def __init__ (self , key : str , desc : str = "执行条件" , default = [], check : bool = True ):
324+ super ().__init__ (key , desc , default , ['无庆典' , 'n庆典' , 'h庆典' , 'vh庆典' , '总是执行' ], check )
367325
368- ok , msg2 = await sself .do_check (* args , ** kwargs )
369- if not ok :
370- return False , msg + msg2
371- return True , msg + msg2
326+ class ConditionalExecution2Config (ConditionalExecutionDB , MultiChoiceConfig ):
327+ def __init__ (self , key : str , desc : str = "执行条件" , default = [], check : bool = True ):
328+ super ().__init__ (key , desc , default , ['n3以上前夕' , 'n3以上首日午前' , 'h3以上前夕' , '会战前夕' , '会战期间' , '总是执行' ], check )
372329
373- cls .do_check = new_do_check
330+ class ConditionalExecution3Config (ConditionalExecutionClient , MultiChoiceConfig ):
331+ def __init__ (self , key : str , desc : str = "执行条件" , default = [], check : bool = True ):
332+ super ().__init__ (key , desc , default , ['n2' , 'n3' , 'n4及以上' , 'h2' , 'h3及以上' , 'vh2' , 'vh3及以上' , '总是执行' ], check )
333+
334+ class ConditionalNotExecutionConfig (ConditionalNotExecutionClient , MultiChoiceConfig ):
335+ def __init__ (self , key : str , desc : str = "不执行条件" , default = [], check : bool = True ):
336+ super ().__init__ (key , desc , default , ['n2' , 'n3' , 'n4及以上' , 'h2' , 'h3及以上' , 'vh2' , 'vh3及以上' ], check )
374337
375338class TravelQuestConfig (MultiChoiceConfig ):
376339 """Configuration for travel quests."""
0 commit comments