Skip to content

Commit 8237d40

Browse files
committed
Fix bug where habit db would not update with new time period
1 parent 2ff1b19 commit 8237d40

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

cogs/habit_tracker_cog.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,9 @@ async def create_tracked_habit(
245245
"end": end.isoformat(),
246246
"users": {}, # {user_id: {"types": {...}, "count": int}}
247247
},
248-
"total": {}, # user_id: {"types": {...}, "count": int, "achieved_goals": int, "missed_goals": int}
249248
},
250249
"started": False,
250+
"total": {}, # user_id: {"types": {...}, "count": int, "achieved_goals": int, "missed_goals": int}
251251
}
252252
logging.debug(f"Adding New Tracked Habit: {name}")
253253
await tracked_habit_cols.insert_one(habit)
@@ -534,8 +534,6 @@ async def update_habits(self, ctx):
534534
channel = self.bot.get_channel(habit.get("channel_id"))
535535
habit["total"] = self.update_totals(habit)
536536

537-
await config.db["habits"].replace_one({"_id": habit["_id"]}, habit)
538-
539537
if channel:
540538
# Generate the weekly summary image, to be sent
541539
self.generate_weekly_summary_image(guild, habit)
@@ -571,7 +569,6 @@ async def update_habits(self, ctx):
571569
logging.error("Channel not found for habit: %s", habit["name"])
572570

573571
start_new, end_new = self.get_period_bounds(habit["frequency"])
574-
575572
empty_types = {act_type: 0 for act_type in habit["types"]}
576573
current_users = {
577574
str(user_id): {"types": empty_types.copy(), "count": 0}
@@ -583,6 +580,7 @@ async def update_habits(self, ctx):
583580
"end": end_new.isoformat(),
584581
"users": current_users,
585582
}
583+
await config.db["habits"].replace_one({"_id": habit["_id"]}, habit)
586584

587585

588586
def setup(bot):

0 commit comments

Comments
 (0)