Fix profile fetching.

This commit is contained in:
2025-07-28 13:51:34 +10:00
parent 239b778f27
commit af95977577
3 changed files with 46 additions and 30 deletions

View File

@@ -86,10 +86,10 @@ class SubathonComponent(cmds.Component):
# ----- Methods -----
async def get_community(self, twitchid: str, name: str | None) -> Communities:
return await Communities.fetch_or_create(twitchid=twitchid, name=name)
return await self.bot.community_fetch(twitchid=twitchid, name=name)
async def get_profile(self, twitchid: str, name: str | None) -> UserProfile:
return await UserProfile.fetch_or_create(twitchid=twitchid, name=name)
return await self.bot.profile_fetch(twitchid=twitchid, name=name)
async def get_active_subathon(self, communityid: int) -> ActiveSubathon | None:
rows = await Subathon.fetch_where(communityid=communityid, ended_at=None)
@@ -211,7 +211,7 @@ class SubathonComponent(cmds.Component):
# end stream => Automatically pause the timer
@cmds.Component.listener()
async def event_stream_offline(self, payload: twitchio.StreamOffline):
community = await Communities.fetch_or_create(twitchid=payload.broadcaster.id, name=payload.broadcaster.name)
community = await self.bot.community_fetch(twitchid=payload.broadcaster.id, name=payload.broadcaster.name)
cid = community.communityid
if (active := await self.get_active_subathon(cid)) is not None:
if active.running:
@@ -233,7 +233,7 @@ class SubathonComponent(cmds.Component):
@group_subathon.command(name='setup')
async def cmd_setup(self, ctx: cmds.Context, initial_hours: float, sub1: float, sub2: float, sub3: float, bit: float, timescore: int):
if ctx.broadcaster:
community = await Communities.fetch_or_create(twitchid=ctx.broadcaster.id, name=ctx.broadcaster.name)
community = await self.bot.community_fetch(twitchid=ctx.broadcaster.id, name=ctx.broadcaster.name)
cid = community.communityid
if (active := await self.get_active_subathon(cid)) is not None:
await ctx.reply("There is already an active subathon running! Use !subathon stop to stop it!")
@@ -256,7 +256,7 @@ class SubathonComponent(cmds.Component):
@group_subathon.command(name='stop')
async def cmd_stop(self, ctx: cmds.Context):
if ctx.broadcaster:
community = await Communities.fetch_or_create(twitchid=ctx.broadcaster.id, name=ctx.broadcaster.name)
community = await self.bot.community_fetch(twitchid=ctx.broadcaster.id, name=ctx.broadcaster.name)
cid = community.communityid
if (active := await self.get_active_subathon(cid)) is not None:
if active.running:
@@ -277,7 +277,7 @@ class SubathonComponent(cmds.Component):
@group_subathon.command(name='pause')
async def cmd_pause(self, ctx: cmds.Context):
if ctx.broadcaster or ctx.author.moderator:
community = await Communities.fetch_or_create(twitchid=ctx.broadcaster.id, name=ctx.broadcaster.name)
community = await self.bot.community_fetch(twitchid=ctx.broadcaster.id, name=ctx.broadcaster.name)
cid = community.communityid
if (active := await self.get_active_subathon(cid)) is not None:
if active.running:
@@ -293,7 +293,7 @@ class SubathonComponent(cmds.Component):
@group_subathon.command(name='resume')
async def cmd_resume(self, ctx: cmds.Context):
if ctx.broadcaster or ctx.author.moderator:
community = await Communities.fetch_or_create(twitchid=ctx.broadcaster.id, name=ctx.broadcaster.name)
community = await self.bot.community_fetch(twitchid=ctx.broadcaster.id, name=ctx.broadcaster.name)
cid = community.communityid
if (active := await self.get_active_subathon(cid)) is not None:
if not active.running:
@@ -308,7 +308,7 @@ class SubathonComponent(cmds.Component):
@cmds.group(name='goals', invoke_fallback=True)
async def group_goals(self, ctx: cmds.Context):
# List the goals
community = await Communities.fetch_or_create(twitchid=ctx.broadcaster.id, name=ctx.broadcaster.name)
community = await self.bot.community_fetch(twitchid=ctx.broadcaster.id, name=ctx.broadcaster.name)
cid = community.communityid
if (active := await self.get_active_subathon(cid)) is not None:
goals = await active.get_goals()
@@ -328,7 +328,7 @@ class SubathonComponent(cmds.Component):
@group_goals.command(name='add')
async def cmd_add(self, ctx: cmds.Context, required: int, description: str):
if ctx.broadcaster or ctx.author.moderator:
community = await Communities.fetch_or_create(twitchid=ctx.broadcaster.id, name=ctx.broadcaster.name)
community = await self.bot.community_fetch(twitchid=ctx.broadcaster.id, name=ctx.broadcaster.name)
cid = community.communityid
if (active := await self.get_active_subathon(cid)) is not None:
await SubathonGoal.create(