Compare commits

..

33 Commits

Author SHA1 Message Date
tamservo
e5219bc433 Changed processing for race messages because of new format coming through. 2025-05-18 12:24:17 -04:00
tamservo
839ee6306c Added file locking to avoid db contention 2025-05-03 22:07:31 -04:00
tamservo
4b636eed7a Took user restrictions off starting race reporting. Tried to improve sql writes to fix db locking error. 2025-04-21 16:47:05 -04:00
tamservo
069d2ca7d0 Merge branch 'main' of https://git.sdf.org/tamservo/robottas
fix workflow testing branch issue.
2025-01-09 14:37:37 -05:00
tamservo
72f96a493b fixed silly comparison error. 2025-01-09 14:36:29 -05:00
Aaron Colon
e11b2396b6 Testing workflow. 2025-01-01 16:51:39 -05:00
Aaron Colon
0c7d721ddd testing workflow 2025-01-01 16:48:51 -05:00
tamservo
58fe1cdda6 Testing workflow 2025-01-01 16:44:12 -05:00
tamservo
9dd76e16b7 Update README.md 2025-01-01 16:43:36 -05:00
tamservo
a0be0c7607 Updated Readme.md. Testing new workflow. 2025-01-01 16:41:31 -05:00
tamservo
50a45e40d5 testing 2025-01-01 16:22:06 -05:00
tamservo
5b3ade2863 Update README.md 2025-01-01 16:20:27 -05:00
tamservo
93364b8580 fix check on half distance 2024-12-08 09:41:08 -05:00
tamservo
4d288e871c Changed permission filter for race commands because discord changed the name to remove the #<number> portion of the id name. 2024-12-01 17:12:07 -05:00
tamservo
c3716613fe Added missing required module to requirements.txt 2024-11-30 19:32:32 -05:00
tamservo
f853f6c220 Added set_total_laps for when they change the number in the laps in the race (i.e. false start procedure.) Also fixed check for race half distance. 2024-11-24 17:35:36 -05:00
tamservo@mx.sdf.org
fabecd836b Added encouragement, slight commands. 2024-09-27 16:22:31 -04:00
tamservo@mx.sdf.org
09bdd939f2 Added steer command. 2024-09-27 16:03:00 -04:00
tamservo@mx.sdf.org
c85d850218 Added new icons for Lawson, Antonelli, Bearman, and Colapinto. 2024-09-27 15:53:01 -04:00
tamservo@mx.sdf.org
083fd06395 Added beans emoji for Colapinto 2024-09-22 10:54:08 -04:00
tamservo@mx.sdf.org
2f9b0af5d8 moved \!in to \!inin 2024-08-13 13:32:33 -04:00
tamservo@mx.sdf.org
b5c4c988f0 added \!in 2024-08-13 13:28:46 -04:00
tamservo@mx.sdf.org
082c4c16b9 Updated rbhelp command 2024-05-19 15:26:23 -04:00
tamservo@mx.sdf.org
0e837958d9 Added help line for \!wall 2024-03-09 15:22:07 -05:00
tamservo
116d69ece9 added wall cmd. 2024-03-09 14:27:24 -05:00
tamservo
35f818d00d Logging messages from db. 2024-03-09 10:14:14 -05:00
tamservo
3f3b8c53b2 Setting up logging 2024-03-09 10:07:12 -05:00
tamservo
f197ae3ab5 Add icon for Bearman 2024-03-09 10:01:14 -05:00
tamservo
5b58bfbb84 Added binger. Fixed issue with delta string. 2024-03-07 21:00:01 -05:00
tamservo
b9f10ebb0e added variety of free squares 2024-02-17 10:25:31 -05:00
tamservo
cf2af10110 added bingo card commands 2024-02-17 08:41:15 -05:00
tamservo
745300c921 adding bingo module 2024-02-17 08:01:17 -05:00
tamservo
96e9b11bdf added iloveyoubot command 2024-01-08 10:22:31 -05:00
64 changed files with 828 additions and 148 deletions

View File

@@ -2,4 +2,4 @@
Discord bot for reporting F1 information.
Makes use of code from fastf1 python library (https://github.com/theOehrly/Fast-F1)
Makes use of code from fastf1 python library (https://github.com/theOehrly/Fast-F1)

View File

@@ -5,7 +5,10 @@ import logging
import requests
import time
import sqlite3
import sys
from contextlib import closing
from filelock import Timeout, FileLock
from fastf1.signalr_aio import Connection
import fastf1
@@ -84,6 +87,8 @@ class SignalRClient:
"SessionData", "LapCount"]
self.debug = debug
self.messages_db = 'messages.db'
self.messages_lock = FileLock('messages.lock')
self.filename = filename
self.filemode = filemode
self.timeout = timeout
@@ -91,9 +96,11 @@ 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')
self.logger.warning("Created logger for SignalR")
else:
self.logger = logger
@@ -101,17 +108,15 @@ class SignalRClient:
self._t_last_message = None
def _to_file(self, msg):
"""
self._output_file.write(msg + '\n')
self._output_file.flush()
"""
#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 self.messages_lock:
with closing(sqlite3.connect(self.messages_db)) as con:
with closing(con.cursor()) as cur:
#self.logger.warning("about to log: " + msg)
cur.execute("insert into messages (message) values(?)", (msg,))
con.commit()
except:
print(f'Error writing message to db.')
async def _on_do_nothing(self, msg):
# just do nothing with the message; intended for debug mode where some
@@ -186,7 +191,7 @@ 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()
self.logger.warning("Exiting...")
def start(self):

BIN
alerts.db Normal file

Binary file not shown.

BIN
audio/bwoken.mp3 Normal file

Binary file not shown.

BIN
audio/no.mp3 Normal file

Binary file not shown.

BIN
bing/1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 218 KiB

BIN
bing/10.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 383 KiB

BIN
bing/2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 205 KiB

BIN
bing/3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 444 KiB

BIN
bing/4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 236 KiB

BIN
bing/5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 281 KiB

BIN
bing/6.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 356 KiB

BIN
bing/7.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 264 KiB

BIN
bing/8.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 329 KiB

BIN
bing/9.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 263 KiB

26
binger.py Executable file
View File

@@ -0,0 +1,26 @@
import glob
from random import randrange
import sqlite3
BING_IMGS_PATH = "bing/*"
DB = "bing.db"
def get_image_count():
# Choose a random image
bing_files = glob.glob(BING_IMGS_PATH)
image_idx = randrange(len(bing_files))
image = bing_files[image_idx]
# Get the latest count and increment
con = sqlite3.connect(DB)
cur = con.cursor()
cur.execute("UPDATE BING_COUNT SET COUNT = COUNT + 1")
con.commit()
result = cur.execute("SELECT COUNT FROM BING_COUNT")
count = result.fetchone()
count = count[0]
cur.close()
con.close()
return(image, count)

56
bingo.py Executable file
View File

@@ -0,0 +1,56 @@
import glob
from PIL import Image
from random import randrange
from uuid import uuid4
class Bingo:
"""Class which allows creation and cleanup of F1 bingo card images."""
def __init__(self):
self.LAYOUT_WIDTH = 88
self.X_OFFSET = 10
self.Y_OFFSET = 110
self.SQUARES_PATH = "bingo_images/squares/*.png"
self.FREE_SQUARES_PATH = "bingo_images/free_squares/*.png"
self.BLANK_CARD_PATH = "bingo_images/card_blank.png"
self.TEMP_FOLDER = "bingo_images/temp/"
def get_card(self):
square_files = glob.glob(self.SQUARES_PATH)
free_square_files = glob.glob(self.FREE_SQUARES_PATH)
used_files = set()
with Image.open(self.BLANK_CARD_PATH) as card_img:
card_img.load()
card_img = card_img.convert('RGBA')
# Fill the grid
for y in range(5):
for x in range(5):
square_file = ""
# If this is the center square, pick a random free square
if x == 2 and y == 2:
square_file = \
free_square_files[randrange(len(free_square_files))]
# otherwise, find a random file that hasn't been used yet
else:
rand_file_idx = randrange(len(square_files))
while rand_file_idx in used_files:
rand_file_idx = randrange(len(square_files))
square_file = square_files[rand_file_idx]
used_files.add(rand_file_idx)
with Image.open(square_file) as square:
position = (self.X_OFFSET + (x * self.LAYOUT_WIDTH),
self.Y_OFFSET + (y * self.LAYOUT_WIDTH))
card_img.paste(square, position, square)
# Write image to temp file
outfile = "".join((self.TEMP_FOLDER, str(uuid4()), ".png"))
print(f"{outfile=}")
card_img.save(outfile)
return outfile

BIN
bingo_images/card_blank.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

BIN
bingo_images/card_blank.xcf Normal file

Binary file not shown.

BIN
bingo_images/free_space.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

16
create_alerts_db.py Executable file
View File

@@ -0,0 +1,16 @@
#!/usr/bin/python3
import sqlite3
if __name__ == '__main__':
con = sqlite3.connect('alerts.db')
cur = con.cursor()
cur.execute("""drop table alert_schedule""")
cur.execute("""drop table alert_channels""")
cur.execute("""create table alert_schedule( id integer primary key, type, day, hour, minute, last_sent );""")
cur.execute("""create table alert_channels( id integer primary key, type, channel_id);""")
con.commit()
cur.close()
con.close()

BIN
races_backup.db Normal file

Binary file not shown.

1
requirements.txt Executable file → Normal file
View File

@@ -3,3 +3,4 @@ discord==2.2.3
fastf1==3.0.3
jdata==0.5.3
Requests==2.31.0
websockets==11.0.3

File diff suppressed because it is too large Load Diff

BIN
schedule.db Executable file

Binary file not shown.