Compare commits

..

2 Commits

Author SHA1 Message Date
a3a3b36230 Add subathon name. 2025-09-02 10:40:01 +10:00
0934ee3af4 Tweak timer channel. 2025-09-02 09:17:00 +10:00
3 changed files with 22 additions and 12 deletions

View File

@@ -9,6 +9,7 @@ CREATE TABLE subathons(
communityid INTEGER NOT NULL REFERENCES communities(communityid),
started_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
initial_time INTEGER NOT NULL,
name TEXT,
sub1_score NUMERIC NOT NULL DEFAULT 1,
sub2_score NUMERIC NOT NULL DEFAULT 2,
sub3_score NUMERIC NOT NULL DEFAULT 6,

View File

@@ -28,9 +28,9 @@ class TimerChannel(Channel):
# TODO: Properly this should be communityid
# Which is retrieved via API call to the profiles module for the channel
# This should also be a different error so we can pass it back to the client.
if not event.get('channel', None):
if not event.get('channelid', None):
raise ValueError("Subtimer connection missing channel!")
community = await self.cog.bot.profiles.profiles.get_community_twitch(event['channel'])
community = await self.cog.bot.profiles.profiles.get_community_twitch(event['channelid'])
if community is None:
raise ValueError('Requested channel is not registered. Add the bot first.')
@@ -85,6 +85,10 @@ class ActiveSubathon:
def running(self):
return self.runningdata is not None
@property
def name(self):
return self.subathondata.name or 'Subathon'
async def check_cap(self):
if not (cap := self.subathondata.timecap):
return False
@@ -385,7 +389,7 @@ class SubathonComponent(cmds.Component):
duration = strfdelta(timedelta(seconds=secs))
text = (
f"Subathon running for {duration}! {score} points recieved, {goalstr}, and {remaining} left on the timer"
f"{active.name} running for {duration}! {score} points recieved, {goalstr}, and {remaining} left on the timer"
)
await ctx.reply(text)
else:
@@ -393,7 +397,7 @@ class SubathonComponent(cmds.Component):
# subathon start
@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, name: str, 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.profiles.fetch_community(ctx.broadcaster)
@@ -405,6 +409,7 @@ class SubathonComponent(cmds.Component):
active = await Subathon.create(
communityid=cid,
name=name,
initial_time=initial_time,
sub1_score=sub1,
sub2_score=sub2,
@@ -413,7 +418,8 @@ class SubathonComponent(cmds.Component):
score_time=timescore,
timecap=timecap
)
await ctx.reply("Setup a new subathon! Use !subathon resume to get the timer running.")
timer_link = f"https://izashi.thewisewolf.dev/tracker/timer?channelid={ctx.channel.id}"
await ctx.reply(f"Setup your {name}! Use !subathon resume to get the timer running. Your timer link: {timer_link}")
await self.channel.send_updates(cid)
# subathon stop
@@ -432,7 +438,7 @@ class SubathonComponent(cmds.Component):
dur = strfdelta(timedelta(seconds=dursecs))
await ctx.reply(
f"Subathon complete after {dur} with a total of {total} points, congratulations!"
f"{active.name} complete after {dur} with a total of {total} points, congratulations!"
)
else:
await ctx.reply("No active subathon to stop.")
@@ -446,10 +452,10 @@ class SubathonComponent(cmds.Component):
if (active := await self.get_active_subathon(cid)) is not None:
if active.running:
await active.pause()
await ctx.reply("Subathon timer paused!")
await ctx.reply(f"{active.name} timer paused!")
await self.channel.send_updates(cid)
else:
await ctx.reply("Subathon timer already paused!")
await ctx.reply(f"{active.name} timer already paused!")
else:
await ctx.reply("No active subathon to pause")
@@ -462,10 +468,10 @@ class SubathonComponent(cmds.Component):
if (active := await self.get_active_subathon(cid)) is not None:
if not active.running:
await active.resume()
await ctx.reply("Subathon timer resumed!")
await ctx.reply(f"{active.name} timer resumed!")
await self.channel.send_updates(cid)
else:
await ctx.reply("Subathon timer already running!")
await ctx.reply(f"{active.name} timer already running!")
else:
await ctx.reply("No active subathon to resume")
@@ -478,12 +484,12 @@ class SubathonComponent(cmds.Component):
goals = await active.get_goals()
goalstrs = []
for i, goal in enumerate(goals, start=1):
line = f"{goal.required_score} subs: {goal.description}"
line = f"{goal.required_score} points: {goal.description}"
goalstrs.append(line)
if goals:
text = ', '.join(goalstrs)
await ctx.reply(f"Subathon Goals! -- {text}")
await ctx.reply(f"{active.name} Goals! -- {text}")
else:
await ctx.reply("No goals have been configured!")
else:
@@ -503,3 +509,5 @@ class SubathonComponent(cmds.Component):
await ctx.reply("Goal added!")
else:
await ctx.reply("No active subathon to add goal to!")
# TODO:

View File

@@ -11,6 +11,7 @@ class Subathon(RowModel):
subathon_id = Integer(primary=True)
communityid = Integer()
started_at = Timestamp()
name = String()
initial_time = Integer() # Initial number of seconds
sub1_score = Integer()
sub2_score = Integer()