Add subathon name.
This commit is contained in:
@@ -9,6 +9,7 @@ CREATE TABLE subathons(
|
|||||||
communityid INTEGER NOT NULL REFERENCES communities(communityid),
|
communityid INTEGER NOT NULL REFERENCES communities(communityid),
|
||||||
started_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
started_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||||
initial_time INTEGER NOT NULL,
|
initial_time INTEGER NOT NULL,
|
||||||
|
name TEXT,
|
||||||
sub1_score NUMERIC NOT NULL DEFAULT 1,
|
sub1_score NUMERIC NOT NULL DEFAULT 1,
|
||||||
sub2_score NUMERIC NOT NULL DEFAULT 2,
|
sub2_score NUMERIC NOT NULL DEFAULT 2,
|
||||||
sub3_score NUMERIC NOT NULL DEFAULT 6,
|
sub3_score NUMERIC NOT NULL DEFAULT 6,
|
||||||
|
|||||||
@@ -85,6 +85,10 @@ class ActiveSubathon:
|
|||||||
def running(self):
|
def running(self):
|
||||||
return self.runningdata is not None
|
return self.runningdata is not None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name(self):
|
||||||
|
return self.subathondata.name or 'Subathon'
|
||||||
|
|
||||||
async def check_cap(self):
|
async def check_cap(self):
|
||||||
if not (cap := self.subathondata.timecap):
|
if not (cap := self.subathondata.timecap):
|
||||||
return False
|
return False
|
||||||
@@ -385,7 +389,7 @@ class SubathonComponent(cmds.Component):
|
|||||||
duration = strfdelta(timedelta(seconds=secs))
|
duration = strfdelta(timedelta(seconds=secs))
|
||||||
|
|
||||||
text = (
|
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)
|
await ctx.reply(text)
|
||||||
else:
|
else:
|
||||||
@@ -393,7 +397,7 @@ class SubathonComponent(cmds.Component):
|
|||||||
|
|
||||||
# subathon start
|
# subathon start
|
||||||
@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, name: str, 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?
|
# TODO: Usage. Maybe implement ? commands?
|
||||||
community = await self.bot.profiles.fetch_community(ctx.broadcaster)
|
community = await self.bot.profiles.fetch_community(ctx.broadcaster)
|
||||||
@@ -405,6 +409,7 @@ class SubathonComponent(cmds.Component):
|
|||||||
|
|
||||||
active = await Subathon.create(
|
active = await Subathon.create(
|
||||||
communityid=cid,
|
communityid=cid,
|
||||||
|
name=name,
|
||||||
initial_time=initial_time,
|
initial_time=initial_time,
|
||||||
sub1_score=sub1,
|
sub1_score=sub1,
|
||||||
sub2_score=sub2,
|
sub2_score=sub2,
|
||||||
@@ -414,7 +419,7 @@ class SubathonComponent(cmds.Component):
|
|||||||
timecap=timecap
|
timecap=timecap
|
||||||
)
|
)
|
||||||
timer_link = f"https://izashi.thewisewolf.dev/tracker/timer?channelid={ctx.channel.id}"
|
timer_link = f"https://izashi.thewisewolf.dev/tracker/timer?channelid={ctx.channel.id}"
|
||||||
await ctx.reply(f"Setup a new subathon! Use !subathon resume to get the timer running. Your timer link: {timer_link}")
|
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)
|
await self.channel.send_updates(cid)
|
||||||
|
|
||||||
# subathon stop
|
# subathon stop
|
||||||
@@ -433,7 +438,7 @@ class SubathonComponent(cmds.Component):
|
|||||||
dur = strfdelta(timedelta(seconds=dursecs))
|
dur = strfdelta(timedelta(seconds=dursecs))
|
||||||
|
|
||||||
await ctx.reply(
|
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:
|
else:
|
||||||
await ctx.reply("No active subathon to stop.")
|
await ctx.reply("No active subathon to stop.")
|
||||||
@@ -447,10 +452,10 @@ class SubathonComponent(cmds.Component):
|
|||||||
if (active := await self.get_active_subathon(cid)) is not None:
|
if (active := await self.get_active_subathon(cid)) is not None:
|
||||||
if active.running:
|
if active.running:
|
||||||
await active.pause()
|
await active.pause()
|
||||||
await ctx.reply("Subathon timer paused!")
|
await ctx.reply(f"{active.name} timer paused!")
|
||||||
await self.channel.send_updates(cid)
|
await self.channel.send_updates(cid)
|
||||||
else:
|
else:
|
||||||
await ctx.reply("Subathon timer already paused!")
|
await ctx.reply(f"{active.name} timer already paused!")
|
||||||
else:
|
else:
|
||||||
await ctx.reply("No active subathon to pause")
|
await ctx.reply("No active subathon to pause")
|
||||||
|
|
||||||
@@ -463,10 +468,10 @@ class SubathonComponent(cmds.Component):
|
|||||||
if (active := await self.get_active_subathon(cid)) is not None:
|
if (active := await self.get_active_subathon(cid)) is not None:
|
||||||
if not active.running:
|
if not active.running:
|
||||||
await active.resume()
|
await active.resume()
|
||||||
await ctx.reply("Subathon timer resumed!")
|
await ctx.reply(f"{active.name} timer resumed!")
|
||||||
await self.channel.send_updates(cid)
|
await self.channel.send_updates(cid)
|
||||||
else:
|
else:
|
||||||
await ctx.reply("Subathon timer already running!")
|
await ctx.reply(f"{active.name} timer already running!")
|
||||||
else:
|
else:
|
||||||
await ctx.reply("No active subathon to resume")
|
await ctx.reply("No active subathon to resume")
|
||||||
|
|
||||||
@@ -479,12 +484,12 @@ class SubathonComponent(cmds.Component):
|
|||||||
goals = await active.get_goals()
|
goals = await active.get_goals()
|
||||||
goalstrs = []
|
goalstrs = []
|
||||||
for i, goal in enumerate(goals, start=1):
|
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)
|
goalstrs.append(line)
|
||||||
|
|
||||||
if goals:
|
if goals:
|
||||||
text = ', '.join(goalstrs)
|
text = ', '.join(goalstrs)
|
||||||
await ctx.reply(f"Subathon Goals! -- {text}")
|
await ctx.reply(f"{active.name} Goals! -- {text}")
|
||||||
else:
|
else:
|
||||||
await ctx.reply("No goals have been configured!")
|
await ctx.reply("No goals have been configured!")
|
||||||
else:
|
else:
|
||||||
@@ -504,3 +509,5 @@ class SubathonComponent(cmds.Component):
|
|||||||
await ctx.reply("Goal added!")
|
await ctx.reply("Goal added!")
|
||||||
else:
|
else:
|
||||||
await ctx.reply("No active subathon to add goal to!")
|
await ctx.reply("No active subathon to add goal to!")
|
||||||
|
|
||||||
|
# TODO:
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ class Subathon(RowModel):
|
|||||||
subathon_id = Integer(primary=True)
|
subathon_id = Integer(primary=True)
|
||||||
communityid = Integer()
|
communityid = Integer()
|
||||||
started_at = Timestamp()
|
started_at = Timestamp()
|
||||||
|
name = String()
|
||||||
initial_time = Integer() # Initial number of seconds
|
initial_time = Integer() # Initial number of seconds
|
||||||
sub1_score = Integer()
|
sub1_score = Integer()
|
||||||
sub2_score = Integer()
|
sub2_score = Integer()
|
||||||
|
|||||||
Reference in New Issue
Block a user