daily pastebin goal
58%
SHARE
TWEET

Untitled

a guest Mar 26th, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import uuid
  2. import logging
  3. from telegram.ext import (Updater, CommandHandler, MessageHandler, Filters, RegexHandler,
  4.                           ConversationHandler)
  5.  
  6. NOTEL, NOINET= range(2)
  7.  
  8. # Enable logging
  9. logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
  10.                     level=logging.INFO)
  11.  
  12. logger = logging.getLogger(__name__)
  13.  
  14. def start(update, context):
  15.     update.message.reply_text('Let us start the game! Input whatever number you likes!')
  16.  
  17.     return NOTEL
  18.  
  19. def notel(update, context):
  20.     user = update.message.from_user
  21.     update.message.reply_text('Number: %s', update.message.text)
  22.  
  23.     return NOINET
  24.  
  25. def noinet(update, context):
  26.     return ConversationHandler.END
  27.  
  28. def error(update, context):
  29.     """Log Errors caused by Updates."""
  30.     logger.warning('Update "%s" caused error "%s"', update, context.error)
  31.  
  32. def cancel(update, context):
  33.     return ConversationHandler.END
  34.  
  35. # Algoritma Command Handler
  36. def main():
  37.     updater = Updater('701274031:AAHX_-XrsEiD2dlGZDz2mtqilFdLdzrxDr0', use_context=True)
  38.    
  39.     # Get the dispatcher to register handlers
  40.     dp = updater.dispatcher
  41.  
  42.     # Add conversation handler with states
  43.     conv_handler = ConversationHandler(
  44.         entry_points=[CommandHandler('start', start)],
  45.  
  46.         states={
  47.             NOTEL: [MessageHandler(Filters.text, notel)],
  48.             NOINET: [MessageHandler(Filters.text, noinet)]
  49.         },
  50.  
  51.         fallbacks=[CommandHandler('cancel', cancel)]
  52.     )
  53.    
  54.     dp.add_handler(conv_handler)
  55.     dp.add_error_handler(error)
  56.     updater.start_polling()
  57.     updater.idle()
  58.  
  59. if __name__ == '__main__':
  60.     main()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top