first commit
This commit is contained in:
39
chef_mou.py
Normal file
39
chef_mou.py
Normal 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()
|
||||||
|
|
||||||
8
maubot.yaml
Normal file
8
maubot.yaml
Normal file
@@ -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:
|
||||||
Reference in New Issue
Block a user