Compare commits
3 Commits
772b3387f6
...
31b0f29a9e
Author | SHA1 | Date |
---|---|---|
Shadow15510 | 31b0f29a9e | |
Shadow15510 | 490f6b7e8f | |
Shadow15510 | 2643e7e944 |
|
@ -4,16 +4,11 @@ from irc_api.api import auto_help
|
|||
|
||||
@api.channel("#glados")
|
||||
@api.on(lambda m: "blague" in m.text.lower())
|
||||
def fun(bot, msg, *args):
|
||||
def fun(bot, msg):
|
||||
bot.send(msg.to, "Mais je suis nuuuullle en blagues euh.")
|
||||
|
||||
|
||||
@api.command("limite")
|
||||
def history_limit(bot, msg, *args):
|
||||
bot.send(msg.to, f"limite historique : {bot.history._History__limit}")
|
||||
|
||||
|
||||
@api.user("Shadow15510")
|
||||
@api.on(lambda m: "glados" in m.text.lower())
|
||||
def agree(bot, msg, *args):
|
||||
def agree(bot, msg):
|
||||
bot.send(msg.to, "Ouaip ! Complètement d'accord avec toi !")
|
|
@ -14,18 +14,18 @@ def greetings_hello(bot, msg):
|
|||
bot.send(msg.to, f"{choice(greetings)} {msg.author}.")
|
||||
|
||||
|
||||
@api.on(lambda m: isinstance(re.match(r"(.*)(au revoir|à plus|a\+|à toute|bye|see you|see you soon) glados(.*)", m.text, re.IGNORECASE), re.Match))
|
||||
@api.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", "À toute", "Bye bye", "See you soon")
|
||||
greetings = ("Au revoir,", "À plus,", "Bye bye,", "See you soon,", "Bye,")
|
||||
bot.send(msg.to, f"{choice(greetings)} {msg.author}.")
|
||||
|
||||
|
||||
@api.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", "Je n'en ferais rien")
|
||||
bot.send(msg.to, f"{choice(thanks_choice)}, {msg.author}")
|
||||
thanks_choice = ("Mais je vous en prie.", "Tout le plaisir est pour moi.", "C'est tout naturel.")
|
||||
bot.send(msg.to, choice(thanks_choice))
|
||||
|
||||
|
||||
@api.on(lambda m: isinstance(re.match(r"(.*)quelle heure(.*)?", m.text, re.IGNORECASE), re.Match))
|
||||
|
@ -37,6 +37,8 @@ def hour(bot, msg):
|
|||
|
||||
@api.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',
|
||||
|
@ -53,16 +55,3 @@ def wiki(bot, msg, text: str, limit: int=1):
|
|||
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}")
|
||||
|
||||
|
||||
@api.channel("#glados")
|
||||
def spam_on_glados(bot, msg):
|
||||
"""Détecte les monologues sur #glados."""
|
||||
if len(bot.history) > 2 and bot.history.get()[-2].author == msg.author:
|
||||
bot.counter += 1
|
||||
else:
|
||||
bot.counter = 1
|
||||
|
||||
if bot.counter > 10:
|
||||
bot.send(msg.to, f"Bon, {msg.author}, tu vas arrêter de spammer un jour ou bien ?")
|
||||
bot.counter = 0
|
||||
|
|
|
@ -226,11 +226,11 @@ def auto_help(bot, msg, fct_name: str=""):
|
|||
bot.send(msg.to, f"Aide sur la commande : {fct_name}")
|
||||
|
||||
for line in bot.commands_help[fct_name].desc.splitlines():
|
||||
bot.send(msg.to, f" {line}")
|
||||
bot.send(msg.to, f" │ {line}")
|
||||
else:
|
||||
bot.send(msg.to, f"Liste des commandes ({PREFIX}aide <cmnd> pour plus d'info)")
|
||||
for cmnd_name in bot.commands_help.keys():
|
||||
bot.send(msg.to, f" - {cmnd_name}")
|
||||
bot.send(msg.to, f" - {cmnd_name}")
|
||||
|
||||
|
||||
def parse(message):
|
||||
|
@ -254,33 +254,40 @@ def convert(data, new_type, default=None):
|
|||
|
||||
|
||||
def check_args(func, *input_args):
|
||||
# args[0] = (type, is_optionnal)
|
||||
# gets the defaults values given in arguments
|
||||
defaults = getattr(func, "__defaults__")
|
||||
if not defaults:
|
||||
defaults = []
|
||||
|
||||
# gets the arguments and their types
|
||||
annotations = getattr(func, "__annotations__")
|
||||
if not annotations:
|
||||
return []
|
||||
|
||||
# nb of required arguments
|
||||
required_args = len(annotations) - len(defaults)
|
||||
|
||||
check_args = []
|
||||
for index, arg_type in enumerate(annotations.values()):
|
||||
if index + 1 > required_args:
|
||||
check_args.append((arg_type, defaults[index - required_args]))
|
||||
else:
|
||||
check_args.append((arg_type, None))
|
||||
|
||||
# if the number of given arguments just can't match
|
||||
if len(input_args) < required_args:
|
||||
return None
|
||||
|
||||
converted_args = []
|
||||
for index, arg in enumerate(check_args):
|
||||
if len(input_args) > index:
|
||||
converted_args.append(convert(input_args[index], *check_args[index]))
|
||||
for index, arg_type in enumerate(annotations.values()):
|
||||
# construction of a tuple (type, default_value) for each expected argument
|
||||
if index + 1 > required_args:
|
||||
check_args = (arg_type, defaults[index - required_args])
|
||||
else:
|
||||
converted_args.append(check_args[index][1])
|
||||
check_args = (arg_type, None)
|
||||
|
||||
# transtypes each given arguments to its target type
|
||||
if len(input_args) > index:
|
||||
converted_args.append(convert(input_args[index], *check_args))
|
||||
else:
|
||||
converted_args.append(check_args[1])
|
||||
|
||||
# if an argument has no default value and transtyping has failed
|
||||
if None in converted_args:
|
||||
return None
|
||||
|
||||
return converted_args
|
||||
|
||||
|
|
8
main.py
8
main.py
|
@ -22,15 +22,13 @@ LOG_FORMAT = "%(asctime)s [%(levelname)s] <%(filename)s> %(funcName)s: %(message
|
|||
logging.basicConfig(format=LOG_FORMAT, level=logging.DEBUG)
|
||||
|
||||
|
||||
class MyBot(api.Bot):
|
||||
counter = 1
|
||||
|
||||
glados = MyBot(
|
||||
glados = api.Bot(
|
||||
(USER, PASSWORD),
|
||||
('irc.planet-casio.com', 6697),
|
||||
["#glados"],
|
||||
gv4_cmnds,
|
||||
gv4_cmnds, fcmnds,
|
||||
prefix="!",
|
||||
limit=50
|
||||
)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue