73 lines
2.8 KiB
Python
73 lines
2.8 KiB
Python
from random import choice
|
|
import re
|
|
import requests
|
|
import time
|
|
|
|
from irc_api import commands
|
|
# from irc_api.commands import auto_help
|
|
|
|
|
|
@commands.on(lambda m: isinstance(re.match(r"(.*)(bonjour|coucou|salut|hey|hello|hi|yo) glados(.*)", m.text, re.IGNORECASE), re.Match))
|
|
def greetings_hello(bot, msg):
|
|
"""Dit bonjour à l'utilisateur"""
|
|
greetings = ("Bonjour", "Coucou", "Salut", "Hey", "Hello", "Hi", "Yo")
|
|
bot.send(msg.to, f"{choice(greetings)} {msg.author}.")
|
|
|
|
|
|
@commands.on(lambda m: isinstance(re.match(r"(.*)(au revoir|(à|a) plus|a\+|(à|a) toute|@\+|bye|see you|see you soon) glados(.*)", m.text, re.IGNORECASE), re.Match))
|
|
def greetings_bye(bot, msg):
|
|
"""Dit au revoir à l'utilisateur."""
|
|
greetings = ("Au revoir,", "À plus,", "Bye bye,", "See you soon,", "Bye,")
|
|
bot.send(msg.to, f"{choice(greetings)} {msg.author}.")
|
|
|
|
|
|
@commands.on(lambda m: isinstance(re.match(r"(.*)(merci|merci beaucoup|thx|thanks|thank you) glados(.*)", m.text, re.IGNORECASE), re.Match))
|
|
def thanks(bot, msg):
|
|
"""Répond aux remerciements de l'utilisateur."""
|
|
thanks_choice = ("Mais je vous en prie.", "Tout le plaisir est pour moi.", "C'est tout naturel.")
|
|
bot.send(msg.to, choice(thanks_choice))
|
|
|
|
|
|
@commands.on(lambda m: isinstance(re.match(r"(.*)quelle heure(.*)?", m.text, re.IGNORECASE), re.Match))
|
|
def hour(bot, msg):
|
|
"""Donne l'heure actuelle"""
|
|
now = time.strftime("%Hh%M", time.localtime())
|
|
bot.send(msg.to, f"Il est très exactement {now}.")
|
|
|
|
|
|
@commands.on(lambda m: "mec" in m.text.lower() and "glados" in m.text.lower())
|
|
def react_on_mec(bot, msg):
|
|
bot.send(msg.to, "Chuis pas ton mec, mon pote.")
|
|
|
|
|
|
@commands.on(lambda m: "pote" in m.text.lower() and "glados" in m.text.lower())
|
|
def react_on_pote(bot, msg):
|
|
bot.send(msg.to, "Chuis pas ton pote, mon gars.")
|
|
|
|
|
|
@commands.on(lambda m: "gars" in m.text.lower() and "glados" in m.text.lower())
|
|
def react_on_gars(bot, msg):
|
|
bot.send(msg.to, "Chuis pas ton gars, mec.")
|
|
|
|
|
|
@commands.command("wiki", desc="wiki <recherche> [limite=1]\nFait une recherche wikipedia.")
|
|
def wiki(bot, msg, text: str, limit: int=1):
|
|
if not (1 < limit <= 10):
|
|
limit = 1
|
|
session = requests.Session()
|
|
params = {
|
|
'action': 'opensearch',
|
|
'search': text,
|
|
'limit': limit,
|
|
'namespace': 0,
|
|
'redirects': 'resolve',
|
|
'format': 'json'
|
|
}
|
|
response = session.get(url="https://fr.wikipedia.org/w/api.php", params=params, timeout=(4, 12)).json()
|
|
if len(response[1]) == 0:
|
|
bot.send(msg.to, f"Aucun résultat trouvé pour la recherche : {text}.")
|
|
else:
|
|
bot.send(msg.to, f"{len(response[1])} résultat{('', 's')[limit > 1]} pour la recherche : '{text}'.")
|
|
for name, link in zip(response[1], response[3]):
|
|
bot.send(msg.to, f" {name} : {link}")
|