Add next_event and next_race

This commit is contained in:
tamservo
2023-12-25 15:28:15 -05:00
parent 51d5331d9d
commit e8fd9611d2
3 changed files with 113 additions and 0 deletions

View File

@@ -2,6 +2,7 @@
import asyncio
import collections.abc
import datetime
import json
import os
import random
@@ -527,6 +528,51 @@ class Robottas(commands.Bot):
return 'Not Watched Yet'
else:
return 'Watched Already'
async def report_next_event(self,ctx):
try:
con = sqlite3.connect('schedule.db')
cur = con.cursor()
now_secs = datetime.datetime.now().timestamp()
for row in cur.execute('select * from schedule ' + \
'where date_start > ?' + \
'order by date_start ascending limit 1',
(now_secs)):
next_secs = row[2]
delta_seconds = next_secs - now_secs
td = datetime.timedelta(seconds=delta_seconds)
next_date = datetime.datetime.fromtimestamp(next_secs)
message = f"Next event is {row[0]} at {next_date}. " + \
f"Time remaining {td}"
await ctx.send(message)
break # There should only be one row anyway
except:
ctx.send("Sorry, hit the wall trying to find the answer...")
async def report_next_race(self,ctx):
try:
con = sqlite3.connect('schedule.db')
cur = con.cursor()
now_secs = datetime.datetime.now().timestamp()
for row in cur.execute('select * from schedule ' + \
'where date_start > ? and ' + \
'session_type = "Race" ' + \
'order by date_start ascending limit 1',
(now_secs)):
next_secs = row[2]
delta_seconds = next_secs - now_secs
td = datetime.timedelta(seconds=delta_seconds)
next_date = datetime.datetime.fromtimestamp(next_secs)
message = f"Next event is {row[0]} at {next_date}. " + \
f"Time remaining {td}"
await ctx.send(message)
break # There should only be one row anyway
except:
ctx.send("Sorry, hit the wall trying to find the answer...")
def __init__(self):
# Set debug or not
@@ -900,6 +946,18 @@ class Robottas(commands.Bot):
async def undercut(ctx):
await self.send_image(ctx, "images/undercut.png")
## Calendar Commands
# Give days, hours, minutes until the next event
@self.command()
async def next_event(ctx):
await self.report_next_event(ctx)
# Give days, hours, minutes until the next race
@self.command()
async def next_race(ctx):
await self.report_next_race(ctx)
if __name__ == '__main__':
rb = Robottas()