blob: 2c67b8337c609823c525bc2b63419191f4fc59a4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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
|