Total Complexity | 9 |
Total Lines | 27 |
Duplicated Lines | 0 % |
1 | import telegram |
||
8 | class BotCommand(object): |
||
9 | command = None |
||
10 | |||
11 | def __init__(self, bot, *args, **kwargs): |
||
12 | self.bot = bot |
||
13 | self._db = self.bot.db |
||
14 | |||
15 | def __call__(self, message, *args, **kwargs): |
||
16 | return self.default(message, *args, **kwargs) |
||
17 | |||
18 | def queue(self, message, next_cmd): |
||
19 | if isinstance(message.chat, telegram.user.User): |
||
20 | # This is a direct chat with a user, reply to message will not |
||
21 | # get populated. Instead wait for the message with id msg+1 |
||
22 | msg_id = message.message_id+1 |
||
23 | else: |
||
24 | msg_id = message.message_id |
||
25 | self.bot.queue['{}_{}'.format(message.chat.id, msg_id)] = next_cmd |
||
26 | |||
27 | @classmethod |
||
28 | def match(cls, message): |
||
29 | if cls.command and message.text and message.text.startswith(cls.command): |
||
30 | return True |
||
31 | return False |
||
32 | |||
33 | def get_tab(self, tab_id): |
||
34 | return self._db.get_or_create_tab(tab_id)[0] |
||
35 |