main.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. '''
  2. BOT FOR TELEGRAM
  3. '''
  4. import random
  5. import logging
  6. from telegram import (ParseMode)
  7. from telegram.ext import (Updater, CommandHandler)
  8. logging.basicConfig(
  9. format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
  10. logger = logging.getLogger(__name__)
  11. def error_callback(update, context):
  12. logger.warning('Update "%s" caused error "%s"', update, context.error)
  13. def start(update, context):
  14. '''
  15. Start
  16. '''
  17. context.bot.send_message(update.message.chat_id,
  18. "Welcome! to simple telegram bot", parse_mode=ParseMode.HTML)
  19. '''
  20. We can call other commands, without it being activated in the chat (/ help).
  21. '''
  22. coin(update, context)
  23. def coin(update, context):
  24. '''
  25. ⚪️ / ⚫️ Currency
  26. Generate an elatory number between 1 and 2.
  27. '''
  28. cid = update.message.chat_id
  29. msg = "⚫️ face " if random.randint(1, 2) == 1 else "⚪️ cross"
  30. '''
  31. He responds directly on the channel where he has been spoken to.
  32. '''
  33. update.message.reply_text(msg)
  34. def main():
  35. TOKEN = "1914536904:AAF4ZnqNvyg1pk-1pCPzTqhDYggAyf-1CF8"
  36. updater = Updater(TOKEN, use_context=True)
  37. dp = updater.dispatcher
  38. '''
  39. Events that will activate our bot.
  40. '''
  41. dp.add_handler(CommandHandler('start', start))
  42. dp.add_handler(CommandHandler('coin', coin))
  43. dp.add_error_handler(error_callback)
  44. '''
  45. The bot starts
  46. '''
  47. updater.start_polling()
  48. '''
  49. or leave listening. Keep it from stopping.
  50. '''
  51. updater.idle()
  52. if __name__ == '__main__':
  53. print('[Telegram simple bot] Start...')
  54. main()