aboutsummaryrefslogtreecommitdiff
path: root/lib/match_script.py
diff options
context:
space:
mode:
authorromangraef <roman.graef@gmail.com>2018-03-17 22:11:47 +0100
committerromangraef <roman.graef@gmail.com>2018-03-17 22:11:47 +0100
commit50afa23b9dc26f914522a55fe5cbb893d34ad27c (patch)
tree9711c076e4af283523f51fbd72ceb67bde4f5366 /lib/match_script.py
parent473d84ec2c82932fa1c09e4b96d6e8198bbb71df (diff)
downloadtelegramuserbot-master.tar.gz
telegramuserbot-master.tar.bz2
telegramuserbot-master.zip
added todos as well as regex based command triggers.HEADmaster
Diffstat (limited to 'lib/match_script.py')
-rw-r--r--lib/match_script.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/lib/match_script.py b/lib/match_script.py
new file mode 100644
index 0000000..124c23b
--- /dev/null
+++ b/lib/match_script.py
@@ -0,0 +1,42 @@
+import pyrogram
+from pyrogram.api import types as tgtypes
+
+from lib.common import CommonContext
+
+
+def match_text(regex):
+ import re
+ regex = re.compile(regex)
+
+ def wrapper(func):
+ func.regex = regex
+ return func
+
+ return wrapper
+
+
+match_scripts = {}
+
+
+def is_match_script(func):
+ return hasattr(func, 'regex') and func.regex is not None
+
+
+def get_match_script_matcher(func):
+ return func.regex
+
+
+def register_match_script(func):
+ match_scripts[func.regex] = func
+
+
+class MatchContext(CommonContext):
+ def __init__(self, client: pyrogram.Client, channel, message: tgtypes.Message, match, groups, named_groups):
+ super().__init__(client, channel, message)
+ self.match = match
+ self.groups = groups
+ self.named_groups = named_groups
+
+
+def get_match_scripts():
+ return match_scripts