Skip to content

Commit

Permalink
FIX: Get command
Browse files Browse the repository at this point in the history
  • Loading branch information
x4leqxinn committed May 25, 2023
1 parent 783abb4 commit 5337776
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions app/models/telegram_custom_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ class TelegramCustomBot:
__instance = None
__LOOP = asyncio.get_event_loop()

@classmethod
def _set_help_command_template(cls):
template = settings.HELP_COMMAND_HEADER + '\n'
for key in settings.COMMANDS.keys():
text = '{}: {}\n'.format(key,settings.COMMANDS.get(key).get('description'))
template = template + text

template = template + settings.HELP_COMMAND_FOOTER
settings.COMMANDS['!help']['template'] = template

@staticmethod
async def _set_url():
await TelegramCustomBot.__instance.bot.set_webhook(url=settings.TELEGRAM.get('WEBHOOK_URL'))
Expand All @@ -16,6 +26,7 @@ def __new__(cls, *args, **kwargs):
cls.__instance = super().__new__(cls)
cls.__instance.bot = Bot(token=settings.TELEGRAM.get('API_KEY'))
cls.__LOOP.create_task(cls._set_url()) # Thread
cls._set_help_command_template()
logger.info('Bot started')
return cls.__instance

Expand Down Expand Up @@ -62,22 +73,23 @@ def _verify_command(self) -> str:
return self._get_failed_message(self.__attempts)

def _get_failed_message(self,attempts):
# TODO: Refac or extend
switch = {
1: 'Oye aweonao ve los comandos con !help :)',
2: 'Tonto ctm q te dije',
3: '._.',
1: 'test',
2: 'test',
3: 'test',
4: 'test',
5: 'test'
}
message = switch.get(attempts,None)

if not message:
message = 'Superaste el limite de aweonamiento'
message = 'Last message'
self._reset_failed_attempts()
return message

def _get_template(self):
return settings.COMMANDS.get(self.__command)
return settings.COMMANDS.get(self.__command).get('template')

async def send_message(self):
self.command = self.current_message.text
Expand Down

0 comments on commit 5337776

Please sign in to comment.