Undskyldpenge-bot/main.py

39 lines
962 B
Python
Raw Normal View History

2024-02-15 00:27:13 +00:00
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()