Advertisement
Guest User

Untitled

a guest
Jun 19th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. import sys
  2. import time
  3. import telepot
  4. from telepot.loop import MessageLoop
  5. from telepot.namedtuple import InlineKeyboardMarkup, InlineKeyboardButton
  6.  
  7.  
  8. usrs = []
  9. stts = []
  10. def main(data, usr, msg):
  11. # bot.sendMessage(chat_id, 'Nikita pidor', reply_markup=keyboard)
  12. # content_type, chat_type, chat_id = telepot.glance(msg)
  13. if(usr == None):
  14. content_type, chat_type, chat_id = telepot.glance(msg)
  15. usrs.append(chat_id)
  16. stts.append(0)
  17. keyboard = InlineKeyboardMarkup(inline_keyboard=[
  18. [InlineKeyboardButton(text='Start game', callback_data='0')],
  19. ])
  20. bot.sendMessage(chat_id, 'Nikita pidor', reply_markup=keyboard)
  21. return
  22. if(stts[usr] == 0):
  23. query_id, chat_id, query_data = telepot.glance(msg, flavor='callback_query')
  24. if(data == '0'):
  25. bot.sendMessage(chat_id, 'Searching for games...')
  26. # keyboard = InlineKeyboardMarkup(inline_keyboard=[
  27. # [InlineKeyboardButton(text='Press me', callback_data='press')],
  28. # ])
  29.  
  30. # bot.sendMessage(chat_id, 'Use inline keyboard', reply_markup=keyboard)
  31.  
  32.  
  33.  
  34. def on_chat_message(msg):
  35. content_type, chat_type, chat_id = telepot.glance(msg)
  36. main(msg['text'], next((i for i, x in enumerate(usrs) if x == chat_id), None), msg)
  37.  
  38.  
  39. def on_callback_query(msg):
  40. query_id, from_id, query_data = telepot.glance(msg, flavor='callback_query')
  41. main(query_data, next((i for i, x in enumerate(usrs) if x == from_id), None), msg)
  42.  
  43.  
  44.  
  45.  
  46. # print('Callback Query:', query_id, from_id, query_data)
  47.  
  48. # bot.answerCallbackQuery(query_id, text='Got it')
  49.  
  50. # TOKEN = sys.argv[1] # get token from command-line
  51.  
  52. bot = telepot.Bot('501244459:AAGgUNa4mpb_S9QyAR_W9wR2bva_PcEn4kQ')
  53. MessageLoop(bot, {'chat': on_chat_message,
  54. 'callback_query': on_callback_query}).run_as_thread()
  55. print('Listening ...')
  56.  
  57. while 1:
  58. time.sleep(10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement