🐛 修复 daily_material 参数错误的问题

This commit is contained in:
Karako 2022-09-18 16:14:23 +08:00
parent 69ee1567de
commit 0babbc7351
No known key found for this signature in database
GPG Key ID: 5920831B0095D4A0

View File

@ -127,10 +127,16 @@ class DailyMaterial(Plugin, BasePlugin):
now = datetime.now() now = datetime.now()
if args and is_number(args[0]): if args and is_number(args[0]):
# 适配出现 负数、小数和数字大于 7 的状况 # 适配出现 负数、小数、数字大于 7 、Nan 和 1e-10的状况
try:
weekday = (_ := int(args[0])) - (_ > 0) weekday = (_ := int(args[0])) - (_ > 0)
weekday = (weekday % 7 + 7) % 7 weekday = (weekday % 7 + 7) % 7
time = title = f"星期{WEEK_MAP[weekday]}" time = title = f"星期{WEEK_MAP[weekday]}"
except ValueError:
title = "今日"
weekday = now.weekday() - (1 if now.hour < 4 else 0)
weekday = 6 if weekday < 0 else weekday
time = now.strftime("%m-%d %H:%M") + " 星期" + WEEK_MAP[weekday]
else: # 获取今日是星期几判定了是否过了凌晨4点 else: # 获取今日是星期几判定了是否过了凌晨4点
title = "今日" title = "今日"
weekday = now.weekday() - (1 if now.hour < 4 else 0) weekday = now.weekday() - (1 if now.hour < 4 else 0)