Advertisement
Guest User

kaskj

a guest
Mar 31st, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.89 KB | None | 0 0
  1. # from telegram.ext import *
  2. # from TOKEN import Token
  3. import time
  4. import random
  5.  
  6. # test
  7. import os
  8. from telegram.ext import (Updater, CommandHandler)
  9.  
  10. def start(update, context):
  11.  
  12.     # context.type dict will store in pickle file if persistance with pickle
  13.     # Updater(Token, context=True, persistance=file_pickle.pickle)
  14.     # see doc telegram Updater
  15.  
  16.     context.user_data['flag'] = "/flag"
  17.     update.message.reply_text('Hey, if you are ready to play a Guess The Flag game, send /y')
  18.     # Debug
  19.     print(context.chat_data['flag'])
  20.  
  21.  
  22. def flag_game(update, context):
  23.  
  24.     flag_variable = context.user_data['flag']
  25.  
  26.     # Debug
  27.     print("Callback: flag_game. flag_variable: {}".format(flag_variable))
  28.  
  29.     flags = {'emoji': '🇦🇫', 'country': 'afghanistan'}, {'emoji': '🇦🇱', 'country': 'albania'}
  30.  
  31.         # message that says to the players what flag to guess
  32.     if context.user_data.get('flag'):
  33.         # allows a flag info to be chosen randomly
  34.         flag = random.choice(flags)
  35.         update.message.reply_text("""this is the flag of:""" + (flag['country']))
  36.         # here it breaks so the guess_flag() message doesn't repeat itself
  37.         # debug
  38.         print("Callback: flag_game. flag_variable: {} inside if statement".format(flag_variable))
  39.     else:
  40.         update.message.reply_text("You can't")
  41.         print('Callback:flag_game. Else statement')
  42.        
  43.  
  44.  
  45. def main():
  46.     updater = Updater(os.environ['TOKEN'], use_context=True)
  47.     dispatcher = updater.dispatcher
  48.  
  49.     start_handler = CommandHandler('start', start)
  50.     dispatcher.add_handler(start_handler)
  51.  
  52.     start_game_handler = CommandHandler('y', flag_game)
  53.     dispatcher.add_handler(start_game_handler)
  54.  
  55. #    start_lobby = CommandHandler('j', players)
  56. #    dispatcher.add_handler(start_lobby)
  57.  
  58.     updater.start_polling()
  59.     updater.idle()
  60.  
  61.  
  62. if __name__ == '__main__':
  63.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement