From b8739a582e0fe59436b3ac2c514a46a25843bedc Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Thu, 15 Feb 2024 01:27:13 +0100 Subject: [PATCH] WIP: Initial commit --- .gitignore | 2 ++ main.py | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 .gitignore create mode 100644 main.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..871a0cf --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +session.txt +venv/* diff --git a/main.py b/main.py new file mode 100644 index 0000000..34f31a7 --- /dev/null +++ b/main.py @@ -0,0 +1,38 @@ +import simplematrixbotlib as botlib + +# TODO +## Add file save to keep count after reboot +## Add secret injection through environment variable +## Add time check to avoid double counts + +creds = botlib.Creds("url", "user", "pass") +bot = botlib.Bot(creds) + +w_counter = 0 +t_counter = 0 + +printer = "Undskyldpenge\n\ +W-{} T-{}" + +@bot.listener.on_message_event +async def check_message(room, message): + global w_counter + global t_counter + + print(room.room_id) + + match = botlib.MessageMatch(room, message, bot) + if match.is_not_from_this_bot() and match.command("undskyldpenge") or match.command("Undskyldpenge"): + + print(match.args()) + if match.args()[0] == "W": + w_counter = w_counter + 1 + + if match.args()[0] == "T": + t_counter = t_counter + 1 + + global printer + await bot.api.send_text_message(room_id=room.room_id, message=printer.format(w_counter, t_counter), msgtype="m.text") + + +bot.run()