first commit

This commit is contained in:
tfa
2022-09-06 20:04:49 +02:00
commit 30e671f309
2 changed files with 47 additions and 0 deletions

39
chef_mou.py Normal file
View File

@@ -0,0 +1,39 @@
from mautrix.util.config import BaseProxyConfig, ConfigUpdateHelper
from maubot import Plugin, MessageEvent
from maubot.handlers import command
import aiohttp
import asyncio
from bs4 import BeautifulSoup
import random
class ChefMou(Plugin):
async def start(self) -> None:
self.on_external_config_update()
async def get_site_content(self):
async with aiohttp.ClientSession() as session:
async with session.get("https://partoches.pustule.org") as resp:
text = await resp.read()
return BeautifulSoup(text.decode('iso-8859-1'), 'html.parser')
@command.new("chefmou")
@command.argument("pattern", pass_raw=True, required=False)
async def morceau(self, evt: MessageEvent, pattern: str) -> None:
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
soup = await self.get_site_content()
s = soup.findAll('th', background='/fond3.gif')
if not pattern:
ps = random.choice(s)
await evt.reply(ps.text)
else:
if pattern == "morceau":
ps = random.choice(s)
await evt.reply(ps.text)
else:
await evt.reply("Nope !")
loop.close()