diff --git a/nemubot/hooks/abstract.py b/nemubot/hooks/abstract.py index 25efc45..eac4b20 100644 --- a/nemubot/hooks/abstract.py +++ b/nemubot/hooks/abstract.py @@ -43,7 +43,7 @@ class Abstract: """Abstract class for Hook implementation""" def __init__(self, call, data=None, channels=None, servers=None, mtimes=-1, - end_call=None): + end_call=None, check=None, match=None): """Create basis of the hook Arguments: @@ -58,6 +58,8 @@ class Abstract: assert callable(call), call assert end_call is None or callable(end_call), end_call + assert check is None or callable(check), check + assert match is None or callable(match), match assert isinstance(channels, list), channels assert isinstance(servers, list), servers assert type(mtimes) is int, mtimes @@ -65,6 +67,9 @@ class Abstract: self.call = call self.data = data + self.mod_check = check + self.mod_match = match + # TODO: find a way to have only one list: a limit is server + channel, not only server or channel self.channels = channels self.servers = servers @@ -96,11 +101,11 @@ class Abstract: def check(self, data1): - return True + return self.mod_check(data1) if self.mod_check is not None else True def match(self, data1): - return True + return self.mod_match(data1) if self.mod_match is not None else True def run(self, data1, *args): diff --git a/nemubot/hooks/command.py b/nemubot/hooks/command.py index 02fdb4d..863d672 100644 --- a/nemubot/hooks/command.py +++ b/nemubot/hooks/command.py @@ -17,6 +17,7 @@ import re from nemubot.hooks.message import Message +from nemubot.hooks.abstract import Abstract from nemubot.hooks.keywords import NoKeyword from nemubot.hooks.keywords.abstract import Abstract as AbstractKeywords from nemubot.hooks.keywords.dict import Dict as DictKeywords @@ -61,5 +62,6 @@ class Command(Message): else: return ( (self.name is None or msg.cmd == self.name) and - (self.regexp is None or re.match(self.regexp, msg.cmd)) + (self.regexp is None or re.match(self.regexp, msg.cmd)) and + Abstract.match(self, msg) ) diff --git a/nemubot/hooks/message.py b/nemubot/hooks/message.py index 1c245ea..ee07600 100644 --- a/nemubot/hooks/message.py +++ b/nemubot/hooks/message.py @@ -46,4 +46,4 @@ class Message(Abstract): if not isinstance(msg, nemubot.message.text.Text): return False else: - return self.regexp is None or re.match(self.regexp, msg.message) + return (self.regexp is None or re.match(self.regexp, msg.message)) and super().match(msg)