Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # from telegram.ext import *
- # from TOKEN import Token
- import time
- import random
- # test
- import os
- from telegram.ext import (Updater, CommandHandler)
- def start(update, context):
- # context.type dict will store in pickle file if persistance with pickle
- # Updater(Token, context=True, persistance=file_pickle.pickle)
- # see doc telegram Updater
- context.user_data['flag'] = "/flag"
- update.message.reply_text('Hey, if you are ready to play a Guess The Flag game, send /y')
- # Debug
- print(context.chat_data['flag'])
- def flag_game(update, context):
- flag_variable = context.user_data['flag']
- # Debug
- print("Callback: flag_game. flag_variable: {}".format(flag_variable))
- flags = {'emoji': '🇦🇫', 'country': 'afghanistan'}, {'emoji': '🇦🇱', 'country': 'albania'}
- # message that says to the players what flag to guess
- if context.user_data.get('flag'):
- # allows a flag info to be chosen randomly
- flag = random.choice(flags)
- update.message.reply_text("""this is the flag of:""" + (flag['country']))
- # here it breaks so the guess_flag() message doesn't repeat itself
- # debug
- print("Callback: flag_game. flag_variable: {} inside if statement".format(flag_variable))
- else:
- update.message.reply_text("You can't")
- print('Callback:flag_game. Else statement')
- def main():
- updater = Updater(os.environ['TOKEN'], use_context=True)
- dispatcher = updater.dispatcher
- start_handler = CommandHandler('start', start)
- dispatcher.add_handler(start_handler)
- start_game_handler = CommandHandler('y', flag_game)
- dispatcher.add_handler(start_game_handler)
- # start_lobby = CommandHandler('j', players)
- # dispatcher.add_handler(start_lobby)
- updater.start_polling()
- updater.idle()
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement