Skip to content

Commit

Permalink
v0.3.0a6-patch1: fix weekly refreshment
Browse files Browse the repository at this point in the history
  • Loading branch information
KafCoppelia committed Aug 29, 2022
1 parent 5607142 commit bbfa06a
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions nonebot_plugin_morning/data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ def weekly_night_refresh(self) -> None:

for gid in self._morning:
for uid, user_items in self._morning[gid].items():
# Remember to jump over the key "group_count"
if uid == "group_count":
continue

user_items["weekly"]["lastweek_night_count"] = user_items["weekly"]["weekly_night_count"]
user_items["weekly"]["weekly_night_count"] = 0

Expand All @@ -178,6 +182,10 @@ def weekly_sleep_time_refresh(self) -> None:
_sleeping_king_uid: str = ""

for uid, user_items in self._morning[gid].items():
# Remember to jump over the key "group_count"
if uid == "group_count":
continue

user_items["weekly"]["lastweek_morning_count"] = user_items["weekly"]["weekly_morning_count"]
user_items["weekly"]["lastweek_sleep"] = user_items["weekly"]["weekly_sleep"]

Expand Down Expand Up @@ -557,16 +565,15 @@ def get_my_routine(self, gid: str, uid: str) -> MessageSegment:
if threshold_hour != -1 and is_later_oclock(now_time, threshold_hour):
lastweek_morning_count: int = self._morning[gid][uid]["weekly"]["lastweek_morning_count"]
lastweek_night_count: int = self._morning[gid][uid]["weekly"]["lastweek_night_count"]

lastweek_sleep: List[int] = self._morning[gid][uid]["weekly"]["lastweek_sleep"]

lastweek_lnt_date: datetime = datetime.strptime(self._morning[gid][uid]["weekly"]["lastweek_latest_night_time"], "%Y-%m-%d %H:%M:%S")
lastweek_lnt: time = datetime.strptime(lastweek_lnt_date, "%Y-%m-%d %H:%M:%S").time()
latest_day: int = datetime.strptime(lastweek_lnt_date, "%Y-%m-%d %H:%M:%S").weekday()
lastweek_lnt: time = lastweek_lnt_date.time()
latest_day: int = lastweek_lnt_date.weekday()

lastweek_emt_date: datetime = datetime.strptime(self._morning[gid][uid]["weekly"]["lastweek_earliest_morning_time"], "%Y-%m-%d %H:%M:%S")
lastweek_emt: time = datetime.strptime(lastweek_emt_date, "%Y-%m-%d %H:%M:%S").time()
earliest_day: int = datetime.strptime(lastweek_emt_date, "%Y-%m-%d %H:%M:%S").weekday()
lastweek_emt: time = lastweek_emt_date.time()
earliest_day: int = lastweek_emt_date.weekday()

msg += f"\n上周早安了{lastweek_morning_count}次"
msg += f"\n上周晚安了{lastweek_night_count}次"
Expand Down Expand Up @@ -604,10 +611,11 @@ def get_group_routine(self, gid: str) -> Tuple[int, int, Optional[str]]:
night_count: int = self._morning[gid]["group_count"]["daily"]["good_night"]

if today == MONDAY:
uid: str = ""
threshold_hour: int = self.get_refresh_time("morning", "late_time")

if threshold_hour != -1 and is_later_oclock(now_time, threshold_hour):
uid: str = self._morning[gid]["group_count"]["weekly"]["sleeping_king"]
uid = self._morning[gid]["group_count"]["weekly"]["sleeping_king"]

return morning_count, night_count, uid if uid != "" else None

Expand Down

0 comments on commit bbfa06a

Please sign in to comment.