commit cdfa2b47163edc3ec7a49a2e39dcd62c1498ea80 Author: tfa Date: Wed Jan 7 09:07:52 2026 +0100 1er commit diff --git a/maubot.yaml b/maubot.yaml new file mode 100644 index 0000000..c9a9201 --- /dev/null +++ b/maubot.yaml @@ -0,0 +1,9 @@ +maubot: 0.1.0 +id: tfa.tantine +version: 1.0.0 +license: AGPL-3.0-or-later +modules: +- tantine +main_class: Tantine +config: false +extra_files: diff --git a/tantine.py b/tantine.py new file mode 100644 index 0000000..e55fa63 --- /dev/null +++ b/tantine.py @@ -0,0 +1,48 @@ +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}")