def match_start(): logger.info(request) print(request) match_params = Helper.get_match_params(request) match_id = match_params['match_id'] username = match_params['username'] #TODO add dialogflow prompt instead of returning normal message if username == '': return json.dumps( Message.general_message( "ValidationError: Telegram username is required, please go to settings and create one" )) if match_id == None: return json.dumps( Message.general_message( "ValidationError: Please say 'Add me' to register yourself")) match = BotDatabase.get_match_document(match_id) if match != None: print("found match") return json.dumps( Message.general_message( "You already have a live match in db, should I delete it?")) else: print("No match") return json.dumps( Message.general_message("Enter team names e.g Pexa vs Lexa?"))
def test_batsman_change(batsman): match_params = Helper.get_match_params(request) match_id = match_params['match_id'] chat_id = request['originalDetectIntentRequest']['payload']['data'][ 'chat']['id'] if 'exit' in match_params: TelegramHelper.remove_keyboard(chat_id) return match_params['exit'] match = BotDatabase.get_match_document(match_id) send_live_data(match) return ActionListener.batsman_change_action_listener( batsman, match_params['match_id'], chat_id)
def noball_with_number(number): #test.noball_with_number match_params = Helper.get_match_params(request) chat_id = request['originalDetectIntentRequest']['payload']['data'][ 'chat']['id'] match_id = match_params['match_id'] if 'exit' in match_params: TelegramHelper.remove_keyboard(chat_id) return match_params['exit'] response = ActionListener.noball_with_number_number_action_listener( number, match_params['match_id'], chat_id) #websocket response start match = BotDatabase.get_match_document(match_id) send_live_data(match) #websocket response end return response
def test_runs(number): #score = req['queryResult']['parameters']['number'] # flask_request_json = flask_request.get_json() number = int(number) match_params = Helper.get_match_params(request) match_id = '' chat_id = '' if match_params['username'] == '': match_id = request['queryResult']['parameters']['match_id'] else: match_id = match_params['match_id'] chat_id = request['originalDetectIntentRequest']['payload']['data'][ 'chat']['id'] if 'exit' in match_params: TelegramHelper.remove_keyboard(chat_id) return match_params['exit'] # if 'undo' in match_params: # ActionListener.undo_listener(chat_id,match_id) # return json.dumps(Message.general_message("Undo done.")) match_status = BotDatabase.get_match_status(match_id) print("match_status before processing:") print(match_status) if match_status == 'pause': BotDatabase.set_match_status(match_id=match_id, from_status="pause", to_status="resume") user_text = request['queryResult']['queryText'] response = '' session = request['session'] intent_name = request['queryResult']['intent']['displayName'] action = request['queryResult']['action'] SESSION_ID = session.rpartition('/')[2] match_status = BotDatabase.get_match_status(match_id) print("match_status after change:") print(match_status) if match_status == 'live': chat_id = request['originalDetectIntentRequest']['payload']['data'][ 'chat']['id'] response = ActionListener.ball_action_listener(number, match_id, chat_id, request, SESSION_ID, action, intent_name, user_text, response) match = BotDatabase.get_match_document(match_id) start_int = time.process_time() print("start of send_live_data==>") send_live_data(match) print("end of send_live_data==>") print(time.process_time() - start_int) elif match_status == 'resume': print('********** Resume *************') print("match_id:" + match_id) print("status in if block:") print(match_status) last_txn = ActionListener.get_last_txn_from_history( match_id, match_status) response = json.dumps(last_txn['response']) print(json.dumps(response)) return response