aboutsummaryrefslogtreecommitdiff
path: root/lib/commands.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/commands.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/commands.py')
-rw-r--r--lib/commands.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/lib/commands.py b/lib/commands.py
new file mode 100644
index 0000000..638ab9b
--- /dev/null
+++ b/lib/commands.py
@@ -0,0 +1,48 @@
+import typing
+
+import pyrogram
+from pyrogram.api import types as tgtypes
+
+from lib.common import CommonContext
+from util import property_decorator
+
+commands = {}
+
+
+def get_all_commands():
+ return commands.values()
+
+
+class CommandContext(CommonContext):
+ def __init__(self, client: pyrogram.Client, channel, args: typing.List[str], message: tgtypes.Message):
+ super().__init__(client, channel, message)
+ import re
+ self.args = args
+ self.rest_content = re.sub('^.*? ', '', message.message)
+
+
+
+def register_command(func):
+ if not is_command(func):
+ return
+ commands[get_command_name(func)] = func
+
+
+def is_command(func):
+ return hasattr(func, 'name') and func.name is not None
+
+
+def get_command_name(func):
+ return func.name
+
+
+def get_command_description(func):
+ return func.description
+
+
+def get_command_by_name(command_name: str):
+ return commands[command_name.lower()]
+
+
+name = property_decorator('name')
+description = property_decorator('description')