diff --git a/RobottasSignalr.py b/RobottasSignalr.py index b3ca932..3d3d71a 100755 --- a/RobottasSignalr.py +++ b/RobottasSignalr.py @@ -5,6 +5,7 @@ import logging import requests import time import sqlite3 +import sys from fastf1.signalr_aio import Connection @@ -84,6 +85,7 @@ class SignalRClient: "SessionData", "LapCount"] self.debug = debug + self._db_is_open = False self.filename = filename self.filemode = filemode self.timeout = timeout @@ -91,7 +93,8 @@ class SignalRClient: if not logger: logging.basicConfig( - format="%(asctime)s - %(levelname)s: %(message)s" + format="%(asctime)s - %(levelname)s: %(message)s", \ + stream=sys.stderr ) self.logger = logging.getLogger('SignalR') else: @@ -107,11 +110,17 @@ class SignalRClient: """ #print(msg) con = sqlite3.connect('messages.db') - cur = con.cursor() - cur.execute("insert into messages (message) values(?)", (msg,)) - con.commit() - cur.close() - con.close() + + try: + with con: + self._db_is_open = True + con.execute("insert into messages (message) values(?)", (msg,)) + con.close() + self.db_is_open = False + except: + if con is not None: + con.close() + self._db_is_open = False async def _on_do_nothing(self, msg): # just do nothing with the message; intended for debug mode where some @@ -186,7 +195,9 @@ class SignalRClient: f"[v{fastf1.__version__}]") await asyncio.gather(asyncio.ensure_future(self._supervise()), asyncio.ensure_future(self._run())) - self._output_file.close() + #self._output_file.close() + while(self._db_is_open): + asyncio.sleep(1) self.logger.warning("Exiting...") def start(self): diff --git a/robottas.py b/robottas.py index 5bf9fd1..3ab9534 100755 --- a/robottas.py +++ b/robottas.py @@ -904,56 +904,60 @@ class Robottas(commands.Bot): self.driver_dict = { '1': '<:VER:1067541523748630570>', '3': '<:RIC:1067870312949108887>', - '5': '<:VET:1067964065516884079>', + '4': '<:NOR:1067840487593082941>', + '5': '<:BOR:1345026018938716161>', + '6': '<:HAD:1345027038104387674>', + '7': '<:DOO:1289936390993215601>', + '10': '<:GAS:1067836596495327283>', '11': '<:PER:1067822335123525732>', '12': '<:ANT:1289237308805222491>', '14': '<:ALO:1067876094033793054>', + '16': '<:LEC:1067544797050585198>', + '18': '<:STR:1067871582854336663>', + '20': '<:MAG:1067883814992486510>', + '22': '<:TSU:1067888851676315660>', + '23': '<:ALB:1067874026871074887>', + '24': '<:ZHO:1067865955117568010>', + '27': '<:HUL:1067880110918742187>', '30': '<:LAW:1289237140051464204>', + '31': '<:OCO:1067834157465612398>', '43': '<:COL:1289237227049844849>', '44': '<:HAM:1067828533746991165>', '55': '<:SAI:1067824776502067270>', '63': '<:RUS:1067831294748274728>', - '16': '<:LEC:1067544797050585198>', - '18': '<:STR:1067871582854336663>', - '4': '<:NOR:1067840487593082941>', - '10': '<:GAS:1067836596495327283>', - '27': '<:HUL:1067880110918742187>', - '31': '<:OCO:1067834157465612398>', '77': '<:BOT:1067819716527276032>', '81': '<:PIA:1067844998369914961>', - '24': '<:ZHO:1067865955117568010>', - '22': '<:TSU:1067888851676315660>', - '20': '<:MAG:1067883814992486510>', - '23': '<:ALB:1067874026871074887>', - '38': '<:BEA:1289237392649224278>', + '87': '<:BEA:1289237392649224278>' } # Holds dictionary for driver 3-letter code to icon self.name_dict = { - 'VER': '<:VER:1067541523748630570>', - 'RIC': '<:RIC:1067870312949108887>', - 'VET': '<:VET:1067964065516884079>', - 'PER': '<:PER:1067822335123525732>', + 'ALB': '<:ALB:1067874026871074887>', 'ALO': '<:ALO:1067876094033793054>', - 'HAM': '<:HAM:1067828533746991165>', - 'SAI': '<:SAI:1067824776502067270>', - 'RUS': '<:RUS:1067831294748274728>', - 'LEC': '<:LEC:1067544797050585198>', - 'STR': '<:STR:1067871582854336663>', - 'NOR': '<:NOR:1067840487593082941>', + 'ANT': '<:ANT:1289237308805222491>', + 'BEA': '<:BEA:1289237392649224278>', + 'BOR': '<:BOR:1345026018938716161>', + 'BOT': '<:BOT:1067819716527276032>', + 'COL': '<:COL:1289237227049844849>', + 'DOO': '<:DOO:1289936390993215601>', 'GAS': '<:GAS:1067836596495327283>', + 'HAD': '<:HAD:1345027038104387674>', + 'HAM': '<:HAM:1067828533746991165>', 'HUL': '<:HUL:1067880110918742187>', 'LAW': '<:LAW:1289237140051464204>', - 'OCO': '<:OCO:1067834157465612398>', - 'BOT': '<:BOT:1067819716527276032>', - 'PIA': '<:PIA:1067844998369914961>', - 'ZHO': '<:ZHO:1067865955117568010>', - 'TSU': '<:TSU:1067888851676315660>', + 'LEC': '<:LEC:1067544797050585198>', 'MAG': '<:MAG:1067883814992486510>', - 'ALB': '<:ALB:1067874026871074887>', - 'BEA': '<:BEA:1289237392649224278>', - 'COL': '<:COL:1289237227049844849>', - 'ANT': '<:ANT:1289237308805222491>' + 'NOR': '<:NOR:1067840487593082941>', + 'OCO': '<:OCO:1067834157465612398>', + 'PIA': '<:PIA:1067844998369914961>', + 'RIC': '<:RIC:1067870312949108887>', + 'RUS': '<:RUS:1067831294748274728>', + 'SAI': '<:SAI:1067824776502067270>', + 'STR': '<:STR:1067871582854336663>', + 'TSU': '<:TSU:1067888851676315660>', + 'VER': '<:VER:1067541523748630570>', + 'VET': '<:VET:1067964065516884079>', + 'ZHO': '<:ZHO:1067865955117568010>' } # Holds dictionary for race states to icons @@ -986,7 +990,7 @@ class Robottas(commands.Bot): self.started = False # Hold message delay - self.delay = 45 + self.delay = 25 self.message_queue = [] # Hold whether to report deleted lap messages @@ -1127,24 +1131,24 @@ class Robottas(commands.Bot): @self.command() async def race(ctx): - if ctx.author.id == 581960756271251457 or \ - ctx.author.guild_permissions.administrator: - await ctx.send(":robot::peach: Ready to report for the race!") - await self._race_report(ctx) + #if ctx.author.id == 581960756271251457 or \ + # ctx.author.guild_permissions.administrator: + await ctx.send(":robot::peach: Ready to report for the race!") + await self._race_report(ctx) @self.command() async def quali(ctx): - if ctx.author.id == 581960756271251457 or \ - ctx.author.guild_permissions.administrator: - await ctx.send(":robot::peach: Ready to report on quali!") - await self._quali_report(ctx) + #if ctx.author.id == 581960756271251457 or \ + # ctx.author.guild_permissions.administrator: + await ctx.send(":robot::peach: Ready to report on quali!") + await self._quali_report(ctx) @self.command() async def practice(ctx): - if ctx.author.id == 581960756271251457 or \ - ctx.author.guild_permissions.administrator: - await ctx.send(":robot::peach: Ready to report on practice!") - await self._practice_report(ctx) + #if ctx.author.id == 581960756271251457 or \ + # ctx.author.guild_permissions.administrator: + await ctx.send(":robot::peach: Ready to report on practice!") + await self._practice_report(ctx) @self.command() async def flap(ctx):