From 2e9b438a04c2e7389cf95a753ed72248dd971660 Mon Sep 17 00:00:00 2001 From: Conatum Date: Thu, 24 Aug 2023 14:40:32 +0300 Subject: [PATCH] fix: Fix minor statistics bugs --- src/modules/statistics/graphics/goals.py | 2 +- src/modules/statistics/settings.py | 8 ++++++++ src/modules/statistics/ui/weeklymonthly.py | 2 +- src/tracking/text/data.py | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/modules/statistics/graphics/goals.py b/src/modules/statistics/graphics/goals.py index 6ed8fc22..b16d9da3 100644 --- a/src/modules/statistics/graphics/goals.py +++ b/src/modules/statistics/graphics/goals.py @@ -87,7 +87,7 @@ async def get_goals_card( # Get member profile if user: username = (user.display_name, user.discriminator) - avatar = user.avatar.key + avatar = user.avatar.key if user.avatar else user.default_avatar.key else: username = (lion.data.display_name, '#????') avatar = luser.data.avatar_hash diff --git a/src/modules/statistics/settings.py b/src/modules/statistics/settings.py index 146ca3ca..236ee0d5 100644 --- a/src/modules/statistics/settings.py +++ b/src/modules/statistics/settings.py @@ -390,6 +390,14 @@ class StatisticsConfigUI(ConfigUI): embed.add_field(**setting.embed_field, inline=False) return MessageArgs(embed=embed) + async def reload(self): + # Re-fetch data for each instance + # This should generally hit cache + self.instances = [ + await setting.get(self.guildid) + for setting in self.setting_classes + ] + class StatisticsDashboard(DashboardSection): section_name = _p( diff --git a/src/modules/statistics/ui/weeklymonthly.py b/src/modules/statistics/ui/weeklymonthly.py index 9b273d07..54bd807d 100644 --- a/src/modules/statistics/ui/weeklymonthly.py +++ b/src/modules/statistics/ui/weeklymonthly.py @@ -473,7 +473,7 @@ class WeeklyMonthlyUI(StatsUI): # Update the tasklist if len(new_tasks) != len(tasks) or not all(t == new_t for (t, new_t) in zip(tasks, new_tasks)): modified = True - async with self._connector.connection() as conn: + async with self.bot.db.connection() as conn: async with conn.transaction(): await tasks_model.table.delete_where(**key).with_connection(conn) if new_tasks: diff --git a/src/tracking/text/data.py b/src/tracking/text/data.py index dda4c65d..95481da7 100644 --- a/src/tracking/text/data.py +++ b/src/tracking/text/data.py @@ -250,7 +250,7 @@ class TextTrackerData(Registry): query, tuple(chain((userid, guildid), *blocks)) ) - return [r['period_m'] or 0 for r in await cursor.fetchall()] + return [r['period_m'] or 0 for r in await cursor.fetchall()] @classmethod @log_wrap(action='member_messages_since')