Advertisement
Guest User

Untitled

a guest
Jun 21st, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.11 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. 0 - in menu
  9. 1 - waiting the end of drawing
  10. 2 - no free seats/create a new table or room  ??
  11.  
  12.  
  13. """
  14.  
  15. def main(data, usr, msg):
  16. #     content_type, chat_type, chat_id = telepot.glance(msg)
  17.     if(stts[usr] == 0):
  18.         content_type, chat_type, chat_id = telepot.glance(msg)
  19.         keyboard = InlineKeyboardMarkup(inline_keyboard=[
  20.                    [InlineKeyboardButton(text='Start game', callback_data='0'),
  21.                     InlineKeyboardButton(text='Add money', callback_data='1')
  22.                    ],
  23.                    ])
  24.         bot.sendMessage(chat_id,"Balance: ???\nsosi",reply_markup = keyboard)
  25.         stts[usr] = 1
  26.         return
  27.    
  28.     if(stts[usr] == 1):
  29.         query_id, chat_id, query_data = telepot.glance(msg, flavor='callback_query')
  30.         if (data == '0'):
  31.             bot.sendMessage(chat_id, 'Searching for games...')
  32.             stts[usr] = 1
  33.             #append to table...
  34.             return
  35.         if (data == '1'):
  36.             bot.sendMessage(chat_id, '..account status..')
  37.            
  38.             return
  39.     if (stts[usr] == 2):
  40.         bot.sendMessage(chat_id, 'Nu tipo za stolom')
  41.        
  42.         return
  43.        
  44.  
  45. def on_chat_message(msg):
  46.    
  47.     content_type, chat_type, chat_id = telepot.glance(msg)
  48.     state = next((i for i, x in enumerate(usrs) if x == chat_id), None)
  49.     print(state)
  50.     if state == None:
  51.         usrs.append(chat_id)
  52.         stts.append(0)
  53.         main(msg['text'], 0, msg)
  54.     else:
  55.         main(msg['text'], state , msg)
  56.    
  57.  
  58. def on_callback_query(msg):
  59.    
  60.     query_id, from_id, query_data = telepot.glance(msg, flavor='callback_query')
  61.     main(query_data, next((i for i, x in enumerate(usrs) if x == from_id), None), msg)
  62.  
  63.    
  64. bot = telepot.Bot('501244459:AAEwhp4AJEE7OhpDvZ_mLZlJFNfGDk2jGos')
  65. MessageLoop(bot, {'chat': on_chat_message,
  66.                   'callback_query': on_callback_query}).run_as_thread()
  67. print('Listening ...')
  68.  
  69. while 1:
  70.     time.sleep(10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement