Compare commits

..

4 Commits

Author SHA1 Message Date
0ea90b5cd2 Annotate component. 2025-09-01 19:41:19 +10:00
a7b38c20b2 Add created_by field for contribution. 2025-09-01 19:41:03 +10:00
4e9dbeee79 Add schema. 2025-09-01 19:40:49 +10:00
d1abe6782e Update plugin name. 2025-09-01 19:21:07 +10:00
4 changed files with 59 additions and 2 deletions

44
data/subathon.sql Normal file
View File

@@ -0,0 +1,44 @@
BEGIN;
INSERT INTO version_history (component, from_version, to_version, author)
VALUES ('SUBATHON', 0, 1, 'Initial Creation');
CREATE TABLE subathons(
subathon_id INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
communityid INTEGER NOT NULL REFERENCES communities(communityid),
started_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
initial_time INTEGER NOT NULL,
sub1_score NUMERIC NOT NULL DEFAULT 1,
sub2_score NUMERIC NOT NULL DEFAULT 2,
sub3_score NUMERIC NOT NULL DEFAULT 6,
bit_score NUMERIC NOT NULL,
score_time NUMERIC NOT NULL,
duration INTEGER NOT NULL DEFAULT 0,
ended_at TIMESTAMPTZ
);
CREATE TABLE running_subathons(
subathon_id INTEGER PRIMARY KEY REFERENCES subathons(subathon_id),
last_started TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
CREATE TABLE subathon_contributions(
contribution_id INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
subathon_id INTEGER NOT NULL REFERENCES subathons(subathon_id),
profileid INTEGER REFERENCES user_profiles(profileid),
score NUMERIC NOT NULL,
event_id INTEGER REFERENCES events(event_id),
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
CREATE TABLE subathon_goals(
goal_id INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
subathon_id INTEGER NOT NULL REFERENCES subathons(subathon_id),
required_score NUMERIC NOT NULL,
description TEXT NOT NULL,
notified BOOLEAN DEFAULT false,
created_at TIMESTAMPTZ DEFAULT NOW()
);
COMMIT;

View File

@@ -15,12 +15,22 @@ from .data import SubathonData, Subathon, RunningSubathon, SubathonContribution,
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'
def __init__(self, cog: 'SubathonComponent', **kwargs):
super().__init__(**kwargs)
self.cog = cog
# TODO: ...
self.communityid = 1
async def on_connection(self, websocket, event):
@@ -61,6 +71,8 @@ class TimerChannel(Channel):
class ActiveSubathon:
# TODO: Version check
# Relies on event tracker and profiles module as well.
def __init__(self, subathondata: Subathon, runningdata: RunningSubathon | None):
self.subathondata = subathondata
self.runningdata = runningdata
@@ -85,6 +97,7 @@ class ActiveSubathon:
new_duration = self.get_duration()
await self.subathondata.update(duration=new_duration)
await self.runningdata.delete()
self.runningdata = None
async def resume(self):
if self.running:
@@ -356,7 +369,6 @@ class SubathonComponent(cmds.Component):
@cmds.group(name='subathon', aliases=['studython'], invoke_fallback=True)
async def group_subathon(self, ctx: cmds.Context):
# TODO: Status
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:
@@ -383,6 +395,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, timecap: Optional[int]=None):
if ctx.broadcaster:
# TODO: Usage. Maybe implement ? commands?
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:

View File

@@ -37,7 +37,7 @@ class SubathonContribution(RowModel):
profileid = Integer()
score = Integer()
event_id = Integer()
# TODO: Should add a created timestamp here, since not all contributions have event ids
created_at = Timestamp()
class SubathonGoal(RowModel):
_tablename_ = 'subathon_goals'