Files
tantine_bot/tantine.py
2026-01-07 09:07:52 +01:00

49 lines
1.4 KiB
Python

from typing import List
from maubot import Plugin, MessageEvent
from maubot.handlers import command
from mautrix.types import EventType
import datetime
import random
import asyncio
class Tantine(Plugin):
@command.new(name="tantine")
async def tantine(self, evt: MessageEvent) -> None:
await evt.mark_read()
weekday = datetime.datetime.now().weekday()
if weekday == 1: # mardi
when = "demain"
elif weekday == 2: # mercredi
when = "ce"
else:
when = "mercredi"
await evt.reply(f"Est-ce qu'il y a un buffet {when} soir ?")
await asyncio.sleep(random.randint(3, 10))
if random.random() < 0.4:
await evt.reply("Non")
return
# Récupération membres du salon
state = await self.client.get_state(evt.room_id)
members = []
for event in state:
if event.type == EventType.ROOM_MEMBER:
if event.state_key != self.client.mxid:
display = event.content.displayname or event.state_key
members.append(display)
if not members:
await evt.reply("Oui")
return
count = min(len(members), random.randint(1, 3))
chosen = random.sample(members, count)
mentions = ", ".join(chosen)
await evt.reply(f"Oui : {mentions}")