rewrite (core): Split and refactor Lion and config.
This commit is contained in:
@@ -415,7 +415,7 @@ class Economy(LionCog):
|
||||
).on_conflict(ignore=True)
|
||||
else:
|
||||
# With only one target, we can take a simpler path, and make better use of local caches.
|
||||
await self.bot.core.lions.fetch(ctx.guild.id, target.id)
|
||||
await self.bot.core.lions.fetch_member(ctx.guild.id, target.id)
|
||||
# Now we are certain these members have a database row
|
||||
|
||||
# Perform the appropriate action
|
||||
@@ -889,7 +889,7 @@ class Economy(LionCog):
|
||||
|
||||
t = self.bot.translator.t
|
||||
Member = self.bot.core.data.Member
|
||||
target_lion = await self.bot.core.lions.fetch(ctx.guild.id, target.id)
|
||||
target_lion = await self.bot.core.lions.fetch_member(ctx.guild.id, target.id)
|
||||
|
||||
# TODO: Add a "Send thanks" button to the DM?
|
||||
# Alternative flow could be waiting until the target user presses accept
|
||||
|
||||
@@ -11,7 +11,7 @@ from babel.translator import LazyStr
|
||||
from ..data import ShopData
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.lion import Lion
|
||||
from core.lion_member import LionMember
|
||||
|
||||
|
||||
class ShopCog(LionCog):
|
||||
@@ -65,7 +65,7 @@ class Customer:
|
||||
self.bot = bot
|
||||
self.data = shop_data
|
||||
|
||||
self.lion: 'Lion' = lion
|
||||
self.lion: 'LionMember' = lion
|
||||
|
||||
# A list of InventoryItems held by this customer
|
||||
self.inventory = inventory
|
||||
@@ -84,7 +84,7 @@ class Customer:
|
||||
|
||||
@classmethod
|
||||
async def fetch(cls, bot: LionBot, shop_data: ShopData, guildid: int, userid: int):
|
||||
lion = await bot.core.lions.fetch(guildid, userid)
|
||||
lion = await bot.core.lions.fetch_member(guildid, userid)
|
||||
inventory = await shop_data.MemberInventoryInfo.fetch_inventory_info(guildid, userid)
|
||||
return cls(bot, shop_data, lion, inventory)
|
||||
|
||||
@@ -92,7 +92,7 @@ class Customer:
|
||||
"""
|
||||
Refresh the data for this member.
|
||||
"""
|
||||
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)
|
||||
await self.lion.data.refresh()
|
||||
self.inventory = await self.data.MemberInventoryInfo.fetch_inventory_info(self.guildid, self.userid)
|
||||
return self
|
||||
|
||||
@@ -184,7 +184,7 @@ class ColourShop(Shop):
|
||||
)
|
||||
|
||||
# Ensure the customer member actually exists
|
||||
member = await self.customer.lion.get_member()
|
||||
member = await self.customer.lion.fetch_member()
|
||||
if member is None:
|
||||
raise SafeCancellation(
|
||||
t(_p(
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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, '#????')
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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, '#????')
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -130,8 +130,8 @@ class TasklistCog(LionCog):
|
||||
|
||||
async def cog_load(self):
|
||||
await self.data.init()
|
||||
self.bot.core.guild_settings.attach(self.settings.task_reward)
|
||||
self.bot.core.guild_settings.attach(self.settings.task_reward_limit)
|
||||
self.bot.core.guild_config.register_model_setting(self.settings.task_reward)
|
||||
self.bot.core.guild_config.register_model_setting(self.settings.task_reward_limit)
|
||||
|
||||
# TODO: Better method for getting single load
|
||||
# Or better, unloading crossloaded group
|
||||
|
||||
Reference in New Issue
Block a user