Skip to content

Commit 7a0e9de

Browse files
committed
feat: 修改按日期挂卡为按星期挂卡
1 parent e4fc0be commit 7a0e9de

2 files changed

Lines changed: 42 additions & 7 deletions

File tree

tasks/KekkaiActivation/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class ActivationConfig(BaseModel):
2929
card_priority: CardPriority = Field(default=CardPriority.HIGH, description='挂卡优先级:high=优先高值卡,low=优先低值卡')
3030
min_taiko_num: int = Field(default=8, description='挂卡太鼓每小时最少收益,低于则不挂卡')
3131
min_fish_num: int = Field(default=16, description='挂卡斗鱼每小时最少收益,低于则不挂卡')
32-
activation_dates: str = Field(default="", description='挂卡日期过滤:使用逗号分隔的日期列表,例如 1,5,10,15,20,25 表示只在每月的这些日期挂卡。留空则每天都可以挂卡。适合多个小号轮流挂卡给大号吃')
32+
activation_weekdays: str = Field(default="", description='挂卡星期过滤:使用逗号或顿号分隔的星期列表,支持中文(周一、周二...)或数字(1-7,1=周一,7=周日)。例如:周一、周三、周五 或 1,3,5。留空则每天都可以挂卡。适合多个小号轮流挂卡给大号吃')
3333
exchange_before: bool = Field(default=True, description='exchange_before_help')
3434
exchange_max: bool = Field(default=True, description='exchange_max_help')
3535
shikigami_class: ShikigamiClass = Field(default=ShikigamiClass.N, description='shikigami_class_help')

tasks/KekkaiActivation/script_task.py

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ class ScriptTask(KU, KekkaiActivationAssets):
3131
def run(self):
3232
con = self.config.kekkai_activation.activation_config
3333

34-
# 日期过滤检查(适合多个小号轮流挂卡给大号吃)
35-
if con.activation_dates:
36-
today = datetime.now().day
37-
allowed_dates = [int(d.strip()) for d in con.activation_dates.split(',') if d.strip().isdigit()]
38-
if today not in allowed_dates:
39-
logger.info(f"今日日期{today}不在挂卡日期列表{allowed_dates}中,跳过挂卡任务")
34+
# 星期过滤检查(适合多个小号轮流挂卡给大号吃)
35+
if con.activation_weekdays:
36+
weekday = datetime.now().weekday() # 0=周一, 6=周日
37+
allowed_weekdays = self.parse_weekdays(con.activation_weekdays)
38+
if weekday not in allowed_weekdays:
39+
logger.info(f"今日星期{weekday + 1}不在挂卡星期列表{allowed_weekdays}中,跳过挂卡任务")
4040
# 设置下次执行时间为明天0点
4141
next_run = (datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
4242
+ timedelta(days=1))
@@ -163,6 +163,41 @@ def run_activation(self, _config: ActivationConfig) -> bool:
163163
logger.info('Card is not selected also not using')
164164
self.screening_card(_config.card_type)
165165

166+
def parse_weekdays(self, weekdays_str: str) -> list[int]:
167+
"""
168+
解析星期配置,支持多种格式:
169+
- 中文:周一、周二、周三、周四、周五、周六、周日
170+
- 数字:1-7(1=周一,7=周日)
171+
- 分隔符:支持英文逗号(,)、中文逗号(,)、顿号(、)
172+
返回:datetime.weekday() 格式(0=周一,6=周日)
173+
"""
174+
weekday_map = {
175+
# 中文 -> weekday (0=周一)
176+
'周一': 0, '周二': 1, '周三': 2, '周四': 3, '周五': 4, '周六': 5, '周日': 6,
177+
}
178+
179+
# 统一分隔符:将中文逗号和顿号都替换为英文逗号
180+
normalized_str = weekdays_str.replace(',', ',').replace('、', ',')
181+
182+
allowed_weekdays = []
183+
for item in normalized_str.split(','):
184+
item = item.strip()
185+
if not item:
186+
continue
187+
188+
# 数字(1-7,1=周一)
189+
if item.isdigit():
190+
weekday = int(item)
191+
if 1 <= weekday <= 7:
192+
allowed_weekdays.append(weekday - 1) # 转换为 weekday 格式
193+
# 中文
194+
elif item in weekday_map:
195+
allowed_weekdays.append(weekday_map[item])
196+
else:
197+
logger.warning(f"无法识别的星期配置:{item}")
198+
199+
return allowed_weekdays
200+
166201
def goto_cards(self):
167202
"""
168203
寮结界,前往挂卡界面

0 commit comments

Comments
 (0)