From 30e671f30985e035f39c7dc320cff05f98a93304 Mon Sep 17 00:00:00 2001 From: tfa Date: Tue, 6 Sep 2022 20:04:49 +0200 Subject: [PATCH] first commit --- chef_mou.py | 39 +++++++++++++++++++++++++++++++++++++++ maubot.yaml | 8 ++++++++ 2 files changed, 47 insertions(+) create mode 100644 chef_mou.py create mode 100644 maubot.yaml diff --git a/chef_mou.py b/chef_mou.py new file mode 100644 index 0000000..02739fc --- /dev/null +++ b/chef_mou.py @@ -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() + diff --git a/maubot.yaml b/maubot.yaml new file mode 100644 index 0000000..c46f42e --- /dev/null +++ b/maubot.yaml @@ -0,0 +1,8 @@ +maubot: 0.1.0 +id: tfa.chefMou +version: 0.0.1 +license: AGPL-3.0-or-later +modules: +- chef_mou +main_class: ChefMou +extra_files: