rewrite (core): Split and refactor Lion and config.

This commit is contained in:
2023-03-03 15:35:08 +02:00
parent aa326b759b
commit b0dcbaa727
18 changed files with 213 additions and 188 deletions

View File

@@ -15,7 +15,7 @@ async def get_goals_card(
):
data: StatsData = bot.get_cog('StatsCog').data
lion = await bot.core.lions.fetch(guildid, userid)
lion = await bot.core.lions.fetch_member(guildid, userid)
today = lion.today
# Calculate periodid and select the correct model
@@ -63,7 +63,7 @@ async def get_goals_card(
sessions_complete = 0.5
# Get member profile
if member := await lion.get_member():
if member := await lion.fetch_member():
username = (member.display_name, member.discriminator)
avatar = member.avatar.key
else:

View File

@@ -14,7 +14,7 @@ from ..lib import apply_month_offset
async def get_monthly_card(bot: LionBot, userid: int, guildid: int, offset: int, mode: CardMode) -> MonthlyStatsCard:
data: StatsData = bot.get_cog('StatsCog').data
lion = await bot.core.lions.fetch(guildid, userid)
lion = await bot.core.lions.fetch_member(guildid, userid)
today = lion.today
month_start = today.replace(day=1, hour=0, minute=0, second=0, microsecond=0)
target = apply_month_offset(month_start, offset)
@@ -77,7 +77,7 @@ async def get_monthly_card(bot: LionBot, userid: int, guildid: int, offset: int,
monthly[i][day.day - 1] = stat / 3600
# Get member profile
if member := await lion.get_member():
if member := await lion.fetch_member():
username = (member.display_name, member.discriminator)
else:
username = (lion.data.display_name, '#????')

View File

@@ -16,7 +16,7 @@ async def get_stats_card(bot: LionBot, userid: int, guildid: int):
# TODO: Leaderboard rankings
guildid = guildid or 0
lion = await bot.core.lions.fetch(guildid, userid)
lion = await bot.core.lions.fetch_member(guildid, userid)
# Calculate the period timestamps, i.e. start time for each summary period
# TODO: Don't do the alltime one like this, not efficient anymore

View File

@@ -12,7 +12,7 @@ from ..data import StatsData
async def get_weekly_card(bot: LionBot, userid: int, guildid: int, offset: int, mode: CardMode) -> WeeklyStatsCard:
data: StatsData = bot.get_cog('StatsCog').data
lion = await bot.core.lions.fetch(guildid, userid)
lion = await bot.core.lions.fetch_member(guildid, userid)
today = lion.today
week_start = today - timedelta(days=today.weekday()) - timedelta(weeks=offset)
days = [week_start + timedelta(i) for i in range(-7, 7 if offset else (today.weekday() + 1))]
@@ -34,7 +34,7 @@ async def get_weekly_card(bot: LionBot, userid: int, guildid: int, offset: int,
day_stats.append(0)
# Get member profile
if member := await lion.get_member():
if member := await lion.fetch_member():
username = (member.display_name, member.discriminator)
else:
username = (lion.data.display_name, '#????')

View File

@@ -21,7 +21,7 @@ from babel.translator import ctx_translator, LazyStr
from babel.utils import local_month
from gui.cards import WeeklyGoalCard, WeeklyStatsCard, MonthlyGoalCard, MonthlyStatsCard
from gui.base import CardMode
from core.lion import Lion
from core.lion_member import LionMember
from ..graphics.weekly import get_weekly_card
from ..graphics.monthly import get_monthly_card
@@ -338,7 +338,7 @@ class WeeklyMonthlyUI(StatsUI):
self.data: StatsData = bot.get_cog('StatsCog').data
# State
self.lion: Optional[Lion] = None
self.lion: Optional[LionMember] = None
self._stat_page: StatPage = StatPage.WEEKLY_VOICE
self._week_offset = 0
@@ -859,7 +859,7 @@ class WeeklyMonthlyUI(StatsUI):
"""
self._original = interaction
self._showing_global = False
self.lion = await self.bot.core.lions.fetch(self.guildid, self.userid)
self.lion = await self.bot.core.lions.fetch_member(self.guildid, self.userid)
# TODO: Switch to using data cache in reload to calculate global/local