commands.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. """Telegram commands"""
  2. from telegram import ParseMode
  3. from app import LOGGER, database, functions
  4. def cmd_start(update, context):
  5. """Start command"""
  6. LOGGER.info('"@%s" start bot', update.message.from_user.username)
  7. update.message.reply_text(
  8. 'Hello {}, use /add to add an account, use /help for a list of commands.'.format(
  9. update.message.from_user.first_name
  10. )
  11. )
  12. telegram_account = database.get_telegram_account(update.message.from_user.id)
  13. if not telegram_account:
  14. database.add_telegram_account(update)
  15. def cmd_help(update, context):
  16. """Help command"""
  17. message_list = [
  18. '**Command list**',
  19. '/add - add verified account',
  20. '/remove - remove verified account',
  21. '/accounts - list of verified accounts',
  22. ]
  23. message = '\n'.join(message_list)
  24. update.message.reply_text(message, parse_mode=ParseMode.MARKDOWN)
  25. def cmd_accounts(update, context):
  26. """Return player list"""
  27. message_list = ['Accounts verified to this Telgeram account:']
  28. telegram_account = database.get_telegram_account(update.message.from_user.id)
  29. if telegram_account:
  30. players = database.get_rr_players(telegram_account)
  31. else:
  32. players = []
  33. if not players:
  34. message_list.append('• none')
  35. for player in players:
  36. desktop_link = '[desktop](https://rivalregions.com/#slide/profile/{})'.format(player.id)
  37. mobile_link = '[mobile](https://m.rivalregions.com/#slide/profile/{})'.format(player.id)
  38. message_list.append(
  39. '• {} {} - {}'.format(
  40. functions.escape_text(player.name),
  41. desktop_link,
  42. mobile_link,
  43. )
  44. )
  45. message = '\n'.join(message_list)
  46. update.message.reply_text(message, parse_mode=ParseMode.MARKDOWN)