def ball_action_listener(run, match_id, chat_id, request, SESSION_ID, action, intent_name, user_text, response): #TODO bowler stats update bot = BotDatabase(match_id) bot.players_stats_update(int(run)) res = bot.run_update(int(run)) #for resume match only #TODO below BotDatabase.push_history(match_id, SESSION_ID, action, intent_name, user_text, res["response"]) if res["type"] == "ask_next_bowler": bowler_list = bot.get_available_bowlers() TelegramHelper.send_keyboard_message( chat_id, res['response'] + "\n\nNext Bowler?", bowler_list) return json.dumps({}) elif res["type"] == "end": # end_message = Message.end_match_payload() # res = Helper.append_clear_context_payload(end_message,request) clear = Helper.clear_contexts(match_id, request) TelegramHelper.remove_keyboard(chat_id) return clear elif res["type"] == "change": TelegramHelper.send_keyboard_general(chat_id, "change innings?", [[{ "text": "change" }, { "text": "Undo" }]]) return json.dumps({}) match_info = bot.get_live_match_info() TelegramHelper.send_scoring_keyboard(chat_id, match_info) return json.dumps({})
def strike_change_action(chat_id, match_id): bot = BotDatabase(match_id) bot.strike_change() bot.match["undo_count"] = 1 bot.match.save() match_info = bot.get_live_match_info() TelegramHelper.send_scoring_keyboard(chat_id, match_info) return json.dumps({})
def test_noball_back(): match_params = Helper.get_match_params(request) chat_id = request['originalDetectIntentRequest']['payload']['data'][ 'chat']['id'] match_id = match_params['match_id'] bot = BotDatabase(match_id) match_info = bot.get_live_match_info() TelegramHelper.send_scoring_keyboard(chat_id, match_info) return json.dumps({})
def undo_listener(chat_id, match_id): bot = BotDatabase(match_id) bot.undo_match() match_info = bot.get_live_match_info() if match_info["ball_number"] == 6: TelegramHelper.send_scoring_keyboard(chat_id, match_info, undo=True) else: TelegramHelper.send_scoring_keyboard(chat_id, match_info)
def batsman_change_action_listener(batsman, match_id, chat_id): bot = BotDatabase(match_id) response = bot.batsman_change(batsman) if response["type"] == 'ask_next_bowler': bowler_list = bot.get_available_bowlers() TelegramHelper.send_keyboard_message( chat_id, response['response'] + "\n\nNext Bowler?", bowler_list) return json.dumps({}) elif response["type"] == 'next': match_info = bot.get_live_match_info() TelegramHelper.send_scoring_keyboard(chat_id, match_info) # TelegramHelper.send_ball_keyboard_message(chat_id) return json.dumps({}) return json.dumps({})
def test_ball_listener(bowler, match_id, chat_id): bot = BotDatabase(match_id) bot.current_bowler_update(bowler) match_info = bot.get_live_match_info() TelegramHelper.send_scoring_keyboard(chat_id, match_info)
def noball_with_number_number_action_listener(run, match_id, chat_id): bot = BotDatabase(match_id) bot.noball_update(int(run)) match_info = bot.get_live_match_info() TelegramHelper.send_scoring_keyboard(chat_id, match_info) return json.dumps({})
def bowler_change_action_listener(bowler, match_id, chat_id): bot = BotDatabase(match_id) bot.current_bowler_update(bowler) match_info = bot.get_live_match_info() TelegramHelper.send_scoring_keyboard(chat_id, match_info) return json.dumps({})