Ajout recherche partition par instrus

This commit is contained in:
tfa
2022-09-07 10:46:58 +02:00
parent cc16e95ee8
commit ab405ca3b7

View File

@@ -24,15 +24,55 @@ class ChefMou(Plugin):
async def morceau(self, evt: MessageEvent, pattern: str) -> None: async def morceau(self, evt: MessageEvent, pattern: str) -> None:
loop = asyncio.new_event_loop() loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop) asyncio.set_event_loop(loop)
soup = await self.get_site_content()
s = soup.findAll('th', background='/fond3.gif')
if not pattern: if not pattern:
ps = random.choice(s) await evt.respond(
await evt.respond(ps.text) """
!chefmou morceau -> Donne un morceau aléatoire
!chefmou partition instru titre -> Renvoi le lien vers la partition de ce morceau pour cet instrument
"""
)
else: else:
if pattern == "morceau": if pattern == "morceau":
soup = await self.get_site_content()
s = soup.findAll('th', background='/fond3.gif')
ps = random.choice(s) ps = random.choice(s)
await evt.respond(ps.text) await evt.respond(ps.text)
elif pattern.__contains__("partition"):
chunks = pattern.split(None, 2)
if len(chunks) != 3 :
await evt.respond(
"""
!chefmou morceau -> Donne un morceau aléatoire
!chefmou partition instru titre -> Renvoi le lien vers la partition de ce morceau pour cet instrument
"""
)
loop.close()
return
soup = await self.get_site_content()
s = soup.find('th', string=chunks[2])
if not s :
await evt.respond("Morceau non trouvé")
return
t = s.parent.findAll('a')
idx = 9
if chunks[1].lower() == "souba" or chunks[1].lower() == "soubassophone" or chunks[1].lower() == "sb":
idx = 0
elif chunks[1].lower() == "basse" or chunks[1].lower() == "bs" :
idx = 1
elif chunks[1].lower() == "trombone" or chunks[1].lower() == "tb":
idx = 2
elif chunks[1].lower() == "trompette" or chunks[1].lower() == "tp":
idx = 3
elif chunks[1].lower() == "sax" or chunks[1].lower() == "saxophone":
idx = 4
elif chunks[1].lower() == "clarinette" or chunks[1].lower() == "cl":
idx = 5
else:
await evt.respond("Pas trouvé cet instru")
loop.close()
return
await evt.respond("["+chunks[2]+ " " + chunks[1]+"]"+"(<https://partoches.pustule.org"+t[idx].get("href")+">)")
else: else:
await evt.respond("Nope !") await evt.respond("Nope !")
loop.close() loop.close()