1er commit
This commit is contained in:
48
tantine.py
Normal file
48
tantine.py
Normal file
@@ -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}")
|
||||
Reference in New Issue
Block a user