imported functionality from separte bot (Jenson Botton).
This commit is contained in:
parent
c3747ee90e
commit
66eee52bb5
121
robottas.py
121
robottas.py
@ -5,6 +5,7 @@ from asyncio.subprocess import PIPE, STDOUT
|
||||
import collections.abc
|
||||
import json
|
||||
import os
|
||||
import random
|
||||
import sqlite3
|
||||
from subprocess import Popen
|
||||
import time
|
||||
@ -559,6 +560,13 @@ class Robottas(commands.Bot):
|
||||
print("Tried to kill collection process")
|
||||
|
||||
|
||||
async def decode_watched(self, w):
|
||||
if w == 0:
|
||||
return 'Not Watched Yet'
|
||||
else:
|
||||
return 'Watched Already'
|
||||
|
||||
|
||||
def __init__(self):
|
||||
# Set debug or not
|
||||
self.debug = True
|
||||
@ -693,6 +701,10 @@ class Robottas(commands.Bot):
|
||||
# Test file
|
||||
self.test_file = "test.json"
|
||||
|
||||
# Race db patterns
|
||||
self.loc_pattern = re.compile('[\w\s\-\d]+')
|
||||
self.yr_pattern = re.compile('\d{4}')
|
||||
|
||||
### END FastF1 adapted section ###
|
||||
|
||||
super().__init__(command_prefix=self.command_prefix,
|
||||
@ -840,6 +852,115 @@ class Robottas(commands.Bot):
|
||||
await ctx.send(file = df)
|
||||
|
||||
|
||||
@self.command()
|
||||
async def danger(ctx):
|
||||
await ctx.send("That's some dangerous driving! " + name_dict["HAM"]
|
||||
|
||||
|
||||
@self.command()
|
||||
async def dotd(ctx):
|
||||
await ctx.send( "I don't know, probably " + name_dict["ALB"] )
|
||||
|
||||
|
||||
@self.command()
|
||||
async def flip(ctx):
|
||||
await ctx.send( random.choice(["Heads","Tails")
|
||||
|
||||
|
||||
@self.command()
|
||||
async def gp2(ctx):
|
||||
await ctx.send("GP2 engine! GP2! ARGHHH! " + name_dict["ALO"])
|
||||
|
||||
|
||||
@self.command()
|
||||
async def quote(ctx):
|
||||
try:
|
||||
con = sqlite3.connect('races.db')
|
||||
cur = con.cursor()
|
||||
for row in cur.execute("select * from quotes " +
|
||||
"order by random() " +
|
||||
"limit 1")
|
||||
|
||||
message = row[0] + " -- " + row[1] + " " + row[2]
|
||||
await ctx.send(message)
|
||||
break # There should only be one row anyway
|
||||
|
||||
cur.close()
|
||||
con.close()
|
||||
|
||||
except:
|
||||
ctx.send("Can't think of a quote for some reason...")
|
||||
|
||||
|
||||
@self.command()
|
||||
@commands.has_permissions(administrator=True)
|
||||
async def race_watched(ctx, loc, yr):
|
||||
if re.match(self.loc_pattern, loc) and \
|
||||
re.match(self.yr_pattern, yr):
|
||||
|
||||
try:
|
||||
con = sqlite3.connect('races.db')
|
||||
cur = con.cursor()
|
||||
cur.execute('update races ' +
|
||||
'set watched = 1 ' +
|
||||
'where location = ? ' +
|
||||
'year = ?', (loc,yr))
|
||||
|
||||
con.commit()
|
||||
cur.close()
|
||||
con.close()
|
||||
await ctx.send(f"{loc} {yr} marked as watched.")
|
||||
|
||||
except:
|
||||
await ctx.send(f"Couldn't mark {loc} {yr} as watched for some reason.")
|
||||
|
||||
|
||||
@self.command()
|
||||
async def rand_race(ctx):
|
||||
try:
|
||||
con = sqlite3.connect('races.db')
|
||||
cur = con.cursor()
|
||||
for row in cur.execute('select * from races ' +
|
||||
'order by Random() ' +
|
||||
'limit 1')
|
||||
|
||||
watched = self.decode_watched(row[2])
|
||||
await ctx.send(f"Location: {row[0]} Year: {row[1]} {watched}")
|
||||
break
|
||||
|
||||
cur.close()
|
||||
con.close()
|
||||
|
||||
except:
|
||||
ctx.send("Can't find a random race for some reason.")
|
||||
|
||||
|
||||
@self.command()
|
||||
async def rand_race_new(ctx):
|
||||
try:
|
||||
con = sqlite3.connect('races.db')
|
||||
cur = con.cursor()
|
||||
for row in cur.execute('select * from races ' +
|
||||
'where watched = 0 ' +
|
||||
'order by Random() ' +
|
||||
'limit 1')
|
||||
|
||||
watched = self.decode_watched(row[2])
|
||||
await ctx.send(f"Location: {row[0]} Year: {row[1]}")
|
||||
break
|
||||
|
||||
cur.close()
|
||||
con.close()
|
||||
|
||||
except:
|
||||
ctx.send("Can't pick a race for some reason.")
|
||||
|
||||
|
||||
@self.command()
|
||||
async def tyres(ctx):
|
||||
await ctx.send("Bono, my tyres are gone " + name_dict["HAM"])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
rb = Robottas()
|
||||
rb.run_robottas()
|
||||
|
Loading…
Reference in New Issue
Block a user