diff --git a/bing/1.png b/bing/1.png new file mode 100644 index 0000000..0828d71 Binary files /dev/null and b/bing/1.png differ diff --git a/bing/10.png b/bing/10.png new file mode 100644 index 0000000..abf91dd Binary files /dev/null and b/bing/10.png differ diff --git a/bing/2.png b/bing/2.png new file mode 100644 index 0000000..03c428f Binary files /dev/null and b/bing/2.png differ diff --git a/bing/3.png b/bing/3.png new file mode 100644 index 0000000..51e18bc Binary files /dev/null and b/bing/3.png differ diff --git a/bing/4.png b/bing/4.png new file mode 100644 index 0000000..1de0a0b Binary files /dev/null and b/bing/4.png differ diff --git a/bing/5.png b/bing/5.png new file mode 100644 index 0000000..dcdefd4 Binary files /dev/null and b/bing/5.png differ diff --git a/bing/6.png b/bing/6.png new file mode 100644 index 0000000..605bbea Binary files /dev/null and b/bing/6.png differ diff --git a/bing/7.png b/bing/7.png new file mode 100644 index 0000000..2235e3d Binary files /dev/null and b/bing/7.png differ diff --git a/bing/8.png b/bing/8.png new file mode 100644 index 0000000..6182b48 Binary files /dev/null and b/bing/8.png differ diff --git a/bing/9.png b/bing/9.png new file mode 100644 index 0000000..fc87667 Binary files /dev/null and b/bing/9.png differ diff --git a/binger.py b/binger.py new file mode 100755 index 0000000..5d1c46c --- /dev/null +++ b/binger.py @@ -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) diff --git a/bingo_images/temp/46f23587-3ddb-4911-af76-6f9ea5b82fee.png b/bingo_images/temp/46f23587-3ddb-4911-af76-6f9ea5b82fee.png deleted file mode 100644 index f6e449a..0000000 Binary files a/bingo_images/temp/46f23587-3ddb-4911-af76-6f9ea5b82fee.png and /dev/null differ diff --git a/bingo_images/temp/7d5c2afb-6a2c-4473-bb4c-48ff1c186f56.png b/bingo_images/temp/7d5c2afb-6a2c-4473-bb4c-48ff1c186f56.png deleted file mode 100644 index 42b7144..0000000 Binary files a/bingo_images/temp/7d5c2afb-6a2c-4473-bb4c-48ff1c186f56.png and /dev/null differ diff --git a/bingo_images/temp/99f346d2-fb0d-400d-96e7-77c66683abf1.png b/bingo_images/temp/99f346d2-fb0d-400d-96e7-77c66683abf1.png deleted file mode 100644 index 1b57faf..0000000 Binary files a/bingo_images/temp/99f346d2-fb0d-400d-96e7-77c66683abf1.png and /dev/null differ diff --git a/bingo_images/temp/9c53d2c0-bc8e-44ed-8b38-7501c7d4b501.png b/bingo_images/temp/9c53d2c0-bc8e-44ed-8b38-7501c7d4b501.png deleted file mode 100644 index e3caf8f..0000000 Binary files a/bingo_images/temp/9c53d2c0-bc8e-44ed-8b38-7501c7d4b501.png and /dev/null differ diff --git a/bingo_images/temp/b652b79c-f7d4-41af-888e-b18af704aaf6.png b/bingo_images/temp/b652b79c-f7d4-41af-888e-b18af704aaf6.png deleted file mode 100644 index 0b479bb..0000000 Binary files a/bingo_images/temp/b652b79c-f7d4-41af-888e-b18af704aaf6.png and /dev/null differ diff --git a/bingo_images/temp/d0798a8c-70f2-4c12-8e6c-40452988a7c9.png b/bingo_images/temp/d0798a8c-70f2-4c12-8e6c-40452988a7c9.png deleted file mode 100644 index 560ef82..0000000 Binary files a/bingo_images/temp/d0798a8c-70f2-4c12-8e6c-40452988a7c9.png and /dev/null differ diff --git a/bingo_images/temp/e4e85cbd-0d2c-4276-90da-7a9ada55a7d1.png b/bingo_images/temp/e4e85cbd-0d2c-4276-90da-7a9ada55a7d1.png deleted file mode 100644 index 01c140b..0000000 Binary files a/bingo_images/temp/e4e85cbd-0d2c-4276-90da-7a9ada55a7d1.png and /dev/null differ diff --git a/robottas.py b/robottas.py index 3ebe64e..d79dfbe 100755 --- a/robottas.py +++ b/robottas.py @@ -2,6 +2,7 @@ import asyncio from bingo import Bingo +import binger import collections.abc import datetime import json @@ -619,18 +620,26 @@ class Robottas(commands.Bot): hour_str = "hour" day_str = "day" - delta_str = str(delta) - (days, junk, rest) = delta_str.split(" ") - rest = rest.split(".")[0] - (hours, minutes, seconds) = rest.split(":") + (hours, minutes, seconds) = (-1, -1, -1) + (days, rest) = (0, "") - if int(days) > 1: + delta_str = str(delta) + if " " in delta_str: + (days, _, rest) = delta_str.split(" ") + rest = rest.split(".")[0] + (hours, minutes, seconds) = rest.split(":") + else: + rest = delta_str.split(".")[0] + (hours, minutes, seconds) = rest.split(":") + + + if int(days) != 1: day_str = "days" - if int(minutes) > 1: + if int(minutes) != 1: min_str = "minutes" - if int(hours) > 1: + if int(hours) != 1: hour_str = "hours" return f"{days} {day_str} {hours} {hour_str} {minutes} {min_str}" @@ -647,13 +656,13 @@ class Robottas(commands.Bot): query = 'select * from schedule where date_start > ? ' + \ 'order by date_start asc limit 1' + cur.execute(query, (now_str,)) rows = cur.fetchall() for row in rows: t2 = datetime.datetime.fromisoformat(row[3] + "+00:00") delta = t2 - t1 - delta_str = self.get_delta_str(delta) message = f"The next event is Round {row[5]}: {row[1]} in {row[4]} which is {delta_str} from now." @@ -661,8 +670,9 @@ class Robottas(commands.Bot): break # There should only be one row anyway - except: + except Exception as e: await ctx.send("Sorry, hit the wall trying to find the answer...") + print(e, file=sys.stderr) async def report_next_race(self, ctx): @@ -813,6 +823,12 @@ class Robottas(commands.Bot): con.close() + async def show_bing(self, ctx): + (image, count) = binger.get_image_count() + await self.send_image(ctx, image) + await ctx.send(f"Bing count: {count}") + + def __init__(self): # Set debug or not self.debug = True @@ -999,7 +1015,10 @@ class Robottas(commands.Bot): "The following register / unregister scheduled next race / event messages.\n" + "!register_next_race_alerts - get an alert for the next race on Monday.\n" + "!register_next_event_alerts - get an alert for the next event on Monday.\n" + - "!unregister_alerts - stop getting alerts on this channel.\n" + "!unregister_alerts - stop getting alerts on this channel.\n" + + "!bingo_card - get a random bingo card.\n" + + "!bingo - announce that you've won bingo.\n" + + "!bing - bing counter." ) @self.command() @@ -1295,7 +1314,13 @@ class Robottas(commands.Bot): async def bingo_card(ctx): card_file = self.bingo.get_card() await self.send_image(ctx, card_file) - pathlib.Path.unlink(card_file) + os.remove(card_file) + + + # Big counter + @self.command() + async def bing(ctx): + await self.show_bing(ctx) if __name__ == '__main__':