Kumi
5b500d34b5
Automatically accept room invites on sync Leave rooms if everyone else leaves README update !gptbot dice command Minor fixes
22 lines
No EOL
611 B
Python
22 lines
No EOL
611 B
Python
from nio.events.room_events import RoomMessageText
|
|
from nio.rooms import MatrixRoom
|
|
|
|
from random import SystemRandom
|
|
|
|
|
|
async def command_dice(room: MatrixRoom, event: RoomMessageText, bot):
|
|
bot.logger.log("Rolling a dice...")
|
|
|
|
try:
|
|
sides = int(event.body.split()[2])
|
|
except ValueError:
|
|
sides = 6
|
|
|
|
if sides < 2:
|
|
await bot.send_message(room, f"A dice with {sides} sides? How would that work?", True)
|
|
|
|
else:
|
|
result = SystemRandom().randint(1, sides)
|
|
body = f"Rolling a {sides}-sided dice... It's a {result}!"
|
|
|
|
await bot.send_message(room, body, True) |