From c92830f40bdef04449f7b998f965d45a070b8bad Mon Sep 17 00:00:00 2001 From: n Date: Fri, 31 Jan 2025 20:35:55 -0600 Subject: [PATCH] Get ready for release --- bot.py | 33 +++++++++++++++++++++++++++++---- fetch.py | 2 -- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/bot.py b/bot.py index bc5e93f..084d060 100644 --- a/bot.py +++ b/bot.py @@ -2,14 +2,25 @@ import simplematrixbotlib as botLibrary import json import fetch -with open('config.json', 'r') as f: - config = json.load(f) +version = "0.0.0" +print("Imag/quotes bot version " + version) +print("Loading config…") +try: + with open('config.json', 'r') as f: + config = json.load(f) + print("Loaded config.") +except FileNotFoundError: + print("Config file not found. Did you read the README?") +except: + print("Something bad and unforseen happened, please report the bug to @n:everypizza.im") + +print("Logging in…") credentials = botLibrary.Creds(config['matrix']['server'], config['matrix']['userid'], config['matrix']['password']) -print(credentials) bot = botLibrary.Bot(credentials) PREFIX = "!q" - +print("Logged in.") +print("Ready!") @bot.listener.on_message_event async def help_message(room, message): match = botLibrary.MessageMatch(room, message, bot, PREFIX) @@ -24,6 +35,7 @@ async def help_message(room, message): {PREFIX} help - show this message {PREFIX} get - fetch a image from the defined instance {PREFIX} source - send a link to the source code + {PREFIX} version - show the bot version """) await bot.api.send_text_message(room.room_id, message) @@ -64,4 +76,17 @@ async def help_message(room, message): await bot.api.send_text_message(room.room_id, message) +@bot.listener.on_message_event +async def help_message(room, message): + match = botLibrary.MessageMatch(room, message, bot, PREFIX) + if not (match.is_not_from_this_bot() and match.prefix() + and match.command("version")): + return + + message = (f""" + quotes-bot-python version {version} + """) + + await bot.api.send_text_message(room.room_id, message) + bot.run() diff --git a/fetch.py b/fetch.py index 3a5d97b..51e00d2 100644 --- a/fetch.py +++ b/fetch.py @@ -18,5 +18,3 @@ def fetchQuote(quoteId): else: print(f"An error occured while saving the file: {quote.status_code}") return None - -fetchQuote(34)