From 8f1553883f337e3e37fa7609973c145c881c3bf1 Mon Sep 17 00:00:00 2001 From: Shadow15510 Date: Mon, 12 Jun 2023 10:17:47 +0200 Subject: [PATCH] Add a decorator on user match --- fun_cmnds.py | 7 ++++++- irc_api/api.py | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/fun_cmnds.py b/fun_cmnds.py index 9af762c..59361bf 100644 --- a/fun_cmnds.py +++ b/fun_cmnds.py @@ -10,4 +10,9 @@ def fun(bot, msg, *args): @api.command("limite") def history_limit(bot, msg, *args): - bot.send(msg.to, f"limite historique : {bot.history._History__limit}") \ No newline at end of file + bot.send(msg.to, f"limite historique : {bot.history._History__limit}") + + +@api.user("Shadow15510") +def agree(bot, msg, *args): + bot.send(msg.to, "Ouaip ! Complètement d'accord avec toi !") \ No newline at end of file diff --git a/irc_api/api.py b/irc_api/api.py index e64beb5..15a9252 100644 --- a/irc_api/api.py +++ b/irc_api/api.py @@ -43,7 +43,22 @@ def channel(channel_name, desc=""): desc=desc, cmnd_type=0 ) + return decorator + +def user(user_name, desc=""): + def decorator(func_or_cmnd): + if isinstance(func_or_cmnd, Command): + func_or_cmnd.events.append(lambda m: m.author == user_name) + return func_or_cmnd + else: + return Command( + name=func_or_cmnd.__name__, + func=func_or_cmnd, + events=[lambda m: m.author == user_name], + desc=desc, + cmnd_type=0 + ) return decorator