예제 #1
0
    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({})
예제 #2
0
    def out_fielder_update_listner(match_id, chat_id, request, fielder):
        bot = BotDatabase(match_id)
        response = bot.out_fielder_update(fielder)

        if response["type"] == 'ask_next_batsman':
            batsman_list = bot.get_available_batsman()
            TelegramHelper.send_keyboard_message(chat_id, "Next Batsman?",
                                                 batsman_list)
            return json.dumps({})

        elif response["type"] == "end":
            BotDatabase.set_match_status(match_id=match_id,
                                         from_status="live",
                                         to_status="end")

            clear = Helper.clear_contexts(match_id, request)
            TelegramHelper.remove_keyboard(chat_id)
            return clear

        elif response["type"] == "change":
            TelegramHelper.send_keyboard_general(chat_id, "change innings?",
                                                 [[{
                                                     "text": "change"
                                                 }, {
                                                     "text": "Undo"
                                                 }]])
            return json.dumps({})

        return json.dumps(response['response'])
예제 #3
0
    def out_with_fielder_action(match_id, chat_id, request, out_type):
        bot = BotDatabase(match_id)
        bot.out_with_fielder(out_type)

        fielder_list = bot.get_available_bowlers()
        TelegramHelper.send_keyboard_message(chat_id, "Fielder name?",
                                             fielder_list)
        return json.dumps({})
예제 #4
0
파일: main.py 프로젝트: aa3pankaj/PexaBot
def match_innings_change():
    match_id = Helper.get_match_params(request)['match_id']
    chat_id = request['originalDetectIntentRequest']['payload']['data'][
        'chat']['id']
    bot = BotDatabase(match_id)
    batsman_list = bot.get_available_batsman()
    TelegramHelper.send_keyboard_message(chat_id, "strike-batsman name?",
                                         batsman_list)
예제 #5
0
    def runout_update(match_id, chat_id, request, out_type, run):
        #TODO bowler stats update, personnel
        bot = BotDatabase(match_id)
        bot.run_out_update(out_type, int(run))

        fielder_list = bot.get_available_bowlers()
        TelegramHelper.send_keyboard_message(chat_id, "Fielder name?",
                                             fielder_list)
        return json.dumps({})
예제 #6
0
 def add_players_action(team_name, team_players_list, match_id, chat_id,
                        intent_name):
     bot = BotDatabase(match_id)
     bot.add_players(team_name, team_players_list)
     if intent_name == 'match.team2players':
         batsman_list = bot.get_available_batsman()
         TelegramHelper.send_keyboard_message(chat_id,
                                              "strike-batsman name?",
                                              batsman_list)
     return json.dumps({})
예제 #7
0
 def update_on_strike_batsmen_listener(batsman, match_id, chat_id,
                                       batsman_type):
     bot = BotDatabase(match_id)
     bot.on_strike_batsmen_update(batsman, batsman_type)
     player_list = []
     if batsman_type == "strike_batsman":
         player_list = bot.get_available_batsman()
         TelegramHelper.send_keyboard_message(chat_id,
                                              "non-strike batsman?",
                                              player_list)
     else:
         player_list = bot.get_available_bowlers()
         TelegramHelper.send_keyboard_message(chat_id, "Opening Bowler?",
                                              player_list)
     return json.dumps({})
예제 #8
0
    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({})
예제 #9
0
 def undo_next_over_action(chat_id, match_id):
     bot = BotDatabase(match_id)
     bowler_list = bot.get_available_bowlers()
     TelegramHelper.send_keyboard_message(chat_id, "Next Bowler?",
                                          bowler_list)