aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorromangraef <roman.graef@gmail.com>2018-03-11 18:22:02 +0100
committerromangraef <roman.graef@gmail.com>2018-03-11 18:22:02 +0100
commit58f62605992da8fe6f107fc850aa4f18ba4ec274 (patch)
tree4a0e1fd59cb2f4333741eba69dd9f8ad89aaf816 /lib
downloadtelegramuserbot-58f62605992da8fe6f107fc850aa4f18ba4ec274.tar.gz
telegramuserbot-58f62605992da8fe6f107fc850aa4f18ba4ec274.tar.bz2
telegramuserbot-58f62605992da8fe6f107fc850aa4f18ba4ec274.zip
Initial commit
Diffstat (limited to 'lib')
-rw-r--r--lib/__init__.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/lib/__init__.py b/lib/__init__.py
new file mode 100644
index 0000000..2c67b83
--- /dev/null
+++ b/lib/__init__.py
@@ -0,0 +1,58 @@
+from typing import List
+
+import pyrogram
+from pyrogram.api import types as tgtypes
+
+
+def property_decorator(key):
+ def decorator(value):
+ def wrapper(func):
+ setattr(func, key, value)
+ return func
+
+ return wrapper
+
+ return decorator
+
+
+name = property_decorator('name')
+description = property_decorator('description')
+
+
+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
+
+
+commands = {}
+
+
+def get_all_commands():
+ return commands.values()
+
+
+class CommandContext(object):
+ def __init__(self, client: pyrogram.Client, channel, args: List[str], message: tgtypes.Message):
+ import re
+ self.args = args
+ self.client = client
+ self.channel = channel
+ self.message = message
+ self.rest_content = re.sub('.*? ', '', message.message)
+ self.author = message.from_id
+
+ def respond(self, text):
+ self.client.send_message(self.channel, text=text)
+
+
+def register_command(func):
+ if not is_command(func):
+ return
+ commands[get_command_name(func)] = func