Add a decorator on user match

This commit is contained in:
Shadow15510 2023-06-12 10:17:47 +02:00
parent 8178a602fd
commit 8f1553883f
2 changed files with 21 additions and 1 deletions

View File

@ -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}")
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 !")

View File

@ -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