From 79f4f81ff899378eb537e73856eb2811e9d1c51a Mon Sep 17 00:00:00 2001 From: BFlow Date: Fri, 10 Apr 2020 16:53:48 +0200 Subject: [PATCH] Kamoulox 2.0 --- kabot/kabot/kabot.py | 84 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 81 insertions(+), 3 deletions(-) diff --git a/kabot/kabot/kabot.py b/kabot/kabot/kabot.py index 12fe155..6995b90 100644 --- a/kabot/kabot/kabot.py +++ b/kabot/kabot/kabot.py @@ -10,6 +10,7 @@ import aiocron import asyncio import giphy_client import gitlab +import lxml from time import sleep from discord.ext import tasks, commands @@ -17,6 +18,7 @@ from subprocess import * from sys import argv from pathlib import Path from giphy_client.rest import ApiException +from bs4 import BeautifulSoup as bs class Mybot(commands.Cog): def __init__(self, bot): @@ -193,9 +195,24 @@ class Mybot(commands.Cog): @commands.command(help="Je menotte une cornemuse et je fume Eddy Malou") async def kamoulox(self, ctx): - kamoulox_request = requests.get('https://kmlproject.com/Launcher/LKamoulox.php') - kamoulox_sentence = kamoulox_request.content.decode('utf-8') - await ctx.send(kamoulox_sentence) + sans_verbe = get_word('nom').text + " " + get_word('complement').get('m') + " et " + get_word('nom').text + " " + get_word('complement').get('m') + "." + nom1 = get_word('nom') + nom2 = get_word('nom') + un1 = "un" + un2 = "un" + if nom1.get('gender') == 'F': + un1 = "une" + if nom2.get('gender') == 'F': + un2 = "une" + phrase1 = get_word('verbe').text + " " + un1 + " " + nom1.text + " " + random.choice([get_word('complement').get('m'), ""]) + phrase2 = get_word('verbe').text + " " + un2 + " " + nom2.text + " " + random.choice([get_word('complement').get('m'), ""]) + avec_verbe = phrase1 + " et " + phrase2 + "." + piece = random.choice(['pile', 'face']) + if piece == "pile": + sans_verbe + elif piece == "face": + avec_verbe + await ctx.send(piece) @tasks.loop(seconds=1.5) async def play_next(self): @@ -211,6 +228,67 @@ class Mybot(commands.Cog): if len(self.sounds_history) >5: self.sounds_history = self.sounds_history[:5] +def get_word(word_type): + content = [] + with open("base_kml.xml", "r") as file: + content = file.readlines() + content = "".join(content) + bs_content = bs(content, 'lxml') + if word_type == 'nom': + nom = bs_content.resources.nom.find_all('word') + result = random.choice(nom) + return result + elif word_type == 'nom_propre': + nom_propre = bs_content.resources.nompropre.find_all('word') + result = random.choice(nom_propre) + return result + elif word_type == 'verbe': + verbe = bs_content.resources.verbe.find_all('word') + result = random.choice(verbe) + return result + elif word_type == 'complement': + complement = bs_content.resources.complement.find_all('word') + result = random.choice(complement) + return result + elif word_type == 'nom_special': + nom_special = bs_content.resources.complement.find_all('word') + result = random.choice(nom_special) + return result + elif word_type == 'prenom': + prenom = bs_content.resources.prenom.find_all('word') + result = random.choice(prenom) + return result + elif word_type == 'prescuse': + prescuse = bs_content.resources.prescuse.find_all('word') + result = random.choice(prescuse) + return result + elif word_type == 'scuse1': + scuse1 = bs_content.resources.scuse1.find_all('word') + result = random.choice(scuse1) + return result + elif word_type == 'scuse2': + scuse2 = bs_content.resources.scuse2.find_all('word') + result = random.choice(scuse2) + return result + elif word_type == 'presulte': + presulte = bs_content.resources.presulte.find_all('word') + result = random.choice(presulte) + return result + elif word_type == 'sulte': + sulte = bs_content.resources.sulte.find_all('word') + result = random.choice(sulte) + return result + elif word_type == 'postsulte': + postsulte = bs_content.resources.presulte.find_all('word') + result = random.choice(postsulte) + return result + elif word_type == 'mail': + mail = bs_content.resources.mail.find_all('word') + result = random.choice(mail) + return result + else: + result = 'Nique bien ta mère!' + return result def main(): token = "NjI3MTM3NDY1MDA5ODMxOTQ2.XY4Raw.pw8sAen3bNR5aYsoTChQOudM0L8"