Annotate component.

This commit is contained in:
2025-09-01 19:41:19 +10:00
parent a7b38c20b2
commit 0ea90b5cd2

View File

@@ -15,12 +15,22 @@ from .data import SubathonData, Subathon, RunningSubathon, SubathonContribution,
class TimerChannel(Channel): class TimerChannel(Channel):
# TODO: Replace the channel mechanism?
# Or at least allow the subscriber to select the communityid on connection
# Eventually want to replace with a mechanism where clients subscribe to
# scoped events (e.g. just subtimer/channel)
# This subscription can be handled by a dedicated local client which has the registry
# Or the registry itself
# And then update hooks send the subscribers the information as a well-defined payload.
# Subscribers might want to communicate as well..
# Each module can have a tiny client that handles it? A bit like this channel...
name = 'Timer' name = 'Timer'
def __init__(self, cog: 'SubathonComponent', **kwargs): def __init__(self, cog: 'SubathonComponent', **kwargs):
super().__init__(**kwargs) super().__init__(**kwargs)
self.cog = cog self.cog = cog
# TODO: ...
self.communityid = 1 self.communityid = 1
async def on_connection(self, websocket, event): async def on_connection(self, websocket, event):
@@ -61,6 +71,8 @@ class TimerChannel(Channel):
class ActiveSubathon: class ActiveSubathon:
# TODO: Version check
# Relies on event tracker and profiles module as well.
def __init__(self, subathondata: Subathon, runningdata: RunningSubathon | None): def __init__(self, subathondata: Subathon, runningdata: RunningSubathon | None):
self.subathondata = subathondata self.subathondata = subathondata
self.runningdata = runningdata self.runningdata = runningdata
@@ -85,6 +97,7 @@ class ActiveSubathon:
new_duration = self.get_duration() new_duration = self.get_duration()
await self.subathondata.update(duration=new_duration) await self.subathondata.update(duration=new_duration)
await self.runningdata.delete() await self.runningdata.delete()
self.runningdata = None
async def resume(self): async def resume(self):
if self.running: if self.running:
@@ -356,7 +369,6 @@ class SubathonComponent(cmds.Component):
@cmds.group(name='subathon', aliases=['studython'], invoke_fallback=True) @cmds.group(name='subathon', aliases=['studython'], invoke_fallback=True)
async def group_subathon(self, ctx: cmds.Context): async def group_subathon(self, ctx: cmds.Context):
# TODO: Status
community = await self.bot.community_fetch(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 cid = community.communityid
if (active := await self.get_active_subathon(cid)) is not None: if (active := await self.get_active_subathon(cid)) is not None:
@@ -383,6 +395,7 @@ class SubathonComponent(cmds.Component):
@group_subathon.command(name='setup') @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, timecap: Optional[int]=None): async def cmd_setup(self, ctx: cmds.Context, initial_hours: float, sub1: float, sub2: float, sub3: float, bit: float, timescore: int, timecap: Optional[int]=None):
if ctx.broadcaster: if ctx.broadcaster:
# TODO: Usage. Maybe implement ? commands?
community = await self.bot.community_fetch(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 cid = community.communityid
if (active := await self.get_active_subathon(cid)) is not None: if (active := await self.get_active_subathon(cid)) is not None: