feat: basic commands + prototype of roll parser

This commit is contained in:
RatCornu 2026-03-24 00:24:58 +01:00
parent 4b47899a3d
commit 74f991af40
Signed by: ratcornu
GPG key ID: B3BE02E379E6E8E2
4 changed files with 84 additions and 1 deletions

33
main.py
View file

@ -1,6 +1,11 @@
from datetime import datetime
import simplematrixbotlib as matrix
from dotenv import dotenv_values
import dice
import misc
DOTENV = dotenv_values(".env")
PREFIX = "!"
@ -14,13 +19,39 @@ creds = matrix.Creds(
)
bot = matrix.bot.Bot(creds, config)
bot.start_time = datetime.now()
@bot.listener.on_message_event
async def ping(room, message):
mtch = matrix.match.MessageMatch(room, message, bot, PREFIX)
if mtch.is_not_from_this_bot and mtch.prefix and mtch.command("ping"):
await misc.ping(bot, mtch, room, message)
@bot.listener.on_message_event
async def echo(room, message):
mtch = matrix.match.MessageMatch(room, message, bot, PREFIX)
if mtch.is_not_from_this_bot and mtch.prefix and mtch.command("echo"):
await bot.api.send_text_message(room.room_id, " ".join(mtch.args()))
await misc.echo(bot, mtch, room, message)
@bot.listener.on_message_event
async def uptime(room, message):
mtch = matrix.match.MessageMatch(room, message, bot, PREFIX)
if mtch.is_not_from_this_bot and mtch.prefix and mtch.command("uptime"):
await misc.uptime(bot, mtch, room, message)
@bot.listener.on_message_event
async def roll(room, message):
mtch = matrix.match.MessageMatch(room, message, bot, PREFIX)
if (
mtch.is_not_from_this_bot
and mtch.prefix
and (mtch.command("roll") or mtch.command("r"))
):
await dice.roll(bot, mtch, room, message)
bot.run()