commit b8739a582e0fe59436b3ac2c514a46a25843bedc Author: Tanguy Herbron Date: Thu Feb 15 01:27:13 2024 +0100 WIP: Initial commit 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()