示例#1
0
def try_handler(message):
    if view.team.is_running(message.chat.id):
        text = message.text.split()[1]
        point = view.point.cur_point(message.chat.id)
        if point.right_answer.upper() == text.upper():
            reaction = view.reaction.get_answer_reaction(
                message.chat.id, RIGHT_ANSWER)
            bot.send_message(message.chat.id, reaction.text)
            view.team.next_online_level(message.chat.id)
            if view.team.is_finished(message.chat.id):
                bot.send_message(message.chat.id, get_msg(MSG_ONLINE_END))
            else:
                send_task(message.chat.id)
        else:
            reaction = view.reaction.get_answer_reaction(
                message.chat.id, WRONG_ANSWER)
            bot.send_message(message.chat.id, reaction.text)
            last_reaction = view.reaction.get_answer_reaction(
                message.chat.id, LAST_WRONG_ANSWER)
            if view.team.set_wrong(message.chat.id) == ATTEMPT_WAS_LAST:
                bot.send_message(message.chat.id, last_reaction.text)
                if view.team.is_finished(message.chat.id):
                    bot.send_message(message.chat.id, get_msg(MSG_ONLINE_END))
                else:
                    send_task(message.chat.id)
            else:
                send_task(message.chat.id)
    else:
        bot.send_message(message.chat.id, get_msg(MSG_NOT_RUNNING))
示例#2
0
def enter(message):
    if not view.team.is_running(message.chat.id):
        view.team.on_game_start(message.chat.id)
        bot.send_message(message.chat.id, get_msg(MSG_ONLINE_START))
        send_task(message.chat.id)
    else:
        bot.send_message(message.chat.id, get_msg(MSG_NOT_RUNNING))
示例#3
0
def skip(message):
    if not view.team.is_running(message.chat.id):
        bot.send_message(message.chat.id, get_msg(MSG_NOT_RUNNING))
    else:
        view.team.next_online_level(message.chat.id, True)
        if view.team.is_finished(message.chat.id):
            bot.send_message(message.chat.id, get_msg(MSG_ONLINE_END))
        else:
            send_task(message.chat.id)
示例#4
0
def reg(message):
    try:
        name, part_count, section = message.text.split()[1:]
    except:
        bot.send_message(message.chat.id, get_msg(MSG_REG_INFO))
    else:
        if view.team.add_team(message.chat.id, name, int(part_count),
                              int(section)) != ERROR:
            bot.send_message(message.chat.id, get_msg(MSG_SUCCESS))
        else:
            bot.send_message(message.chat.id, get_msg(MSG_ERROR))
示例#5
0
def check_time():
    for team in view.team.get_all_teams():
        if not team.responding:
            continue
        start_time = team.cur_start_time
        cur_point = view.point.get_point(team.off_point, team.section)
        time_delta = (datetime.now() - start_time).total_seconds() // 60
        attempt_num = team.attempt_num
        if attempt_num == MIDDLE_ATTEMPT and time_delta >= cur_point.slow:
            reaction = view.reaction.get_answer_reaction(
                team.chat_id, LAST_WRONG_ANSWER)
            bot.send_message(team.chat_id, reaction.text)
            view.team.set_wrong(team.chat_id)
            if view.team.is_finished(team.chat_id):
                bot.send_message(team.chat_id, get_msg(MSG_OFFLINE_END))
        elif attempt_num == FAST_ATTEMPT and time_delta >= cur_point.middle:
            view.team.set_wrong(team.chat_id)
            reaction = view.reaction.get_answer_reaction(
                team.chat_id, WRONG_ANSWER)
            bot.send_message(team.chat_id, reaction.text)
        elif attempt_num == RUN_ATTEMPT and time_delta >= cur_point.fast:
            view.team.set_wrong(team.chat_id)
            reaction = view.reaction.get_answer_reaction(
                team.chat_id, WRONG_ANSWER)
            bot.send_message(team.chat_id, reaction.text)
    t = Timer(CHECKER_TIME, check_time)
    t.start()
示例#6
0
def team(message):
    team = view.team.get_team(message.chat.id)
    if team == ERROR:
        bot.send_message(message.chat.id, ERROR)
    else:
        msg = get_msg(MSG_TEAM).format(team.name, team.participants,
                                       team.on_score + team.off_score,
                                       team.status, team.section)
        bot.send_message(message.chat.id, msg)
示例#7
0
def check_out(message):
    if not view.team.is_team_responding(message.chat.id):
        bot.send_message(message.chat.id, get_msg(MSG_NEED_CHECK_IN))
    else:
        try:
            code = message.text.split()[1]
        except IndexError:
            bot.send_message(get_msg(MSG_NEED_CODE))
        else:
            point = view.point.cur_point(message.chat.id)
            right_code = point.finish_code
            if code == right_code:
                reaction = view.reaction.get_answer_reaction(
                    message.chat.id, RIGHT_ANSWER)
                bot.send_message(message.chat.id, reaction.text)
                view.team.next_offline_level(message.chat.id)
                if view.team.is_finished(message.chat.id):
                    bot.send_message(message.chat.id, get_msg(MSG_OFFLINE_END))
            else:
                bot.send_message(message.chat.id, get_msg(MSG_WRONG_CODE))
示例#8
0
def check_in(message):
    if not view.team.is_running(message.chat.id):
        bot.send_message(message.chat.id, get_msg(MSG_NOT_OFF_RUNNING))
    elif view.team.is_team_responding(message.chat.id):
        bot.send_message(message.chat.id, get_msg(MSG_ALREADY_CHECKED_IN))
    else:
        try:
            code = message.text.split()[1]
        except IndexError:
            bot.send_message(message.chat.id, get_msg(MSG_NEED_CODE))
        else:
            point = view.point.get_off_point_with_code(code)
            if point == ERROR:
                bot.send_message(message.chat.id, get_msg(MSG_WRONG_CODE))
            elif point.id != view.point.cur_point(message.chat.id).id:
                bot.send_message(message.chat.id, get_msg(MSG_WRONG_POINT))
            elif point.section != view.team.get_section(message.chat.id):
                bot.send_message(message.chat.id, get_msg(MSG_WRONG_SECTION))
            else:
                bot.send_message(message.chat.id, point.task)
                view.team.set_team_responding(message.chat.id)
                view.team.set_cur_time(message.chat.id)
示例#9
0
 def wrapper(message):
     if not view.team.is_finished(message.chat.id):
         func(message)
     else:
         bot.send_message(message.chat.id, get_msg(MSG_FINISHED))
示例#10
0
def pinned(message):
    bot.send_message(message.chat.id, get_msg(MSG_PINNED))
示例#11
0
def util(message):
    bot.send_message(message.chat.id, get_msg(MSG_UTIL))
示例#12
0
def create_tables():
    with database:
        database.create_tables(
            [Team, OnPoint, OffPoint, OnReaction, OffReaction, File])
        return get_msg(MSG_SUCCESS)
示例#13
0
def task(message):
    if not view.team.is_running(message.chat.id):
        bot.send_message(message.chat.id, get_msg(MSG_NOT_RUNNING))
    else:
        send_task(message.chat.id)
示例#14
0
def hello(message):
    bot.send_message(message.chat.id, get_msg(MSG_HELLO))
示例#15
0
def kill(message):
    bot.send_message(message.chat.id, get_msg(MSG_OFFLINE_START))
    view.team.off_game_start(message.chat.id)
示例#16
0
def sos(message):
    bot.send_message(message.chat.id, get_msg(MSG_SOS))
示例#17
0
def offline_plain_text(message):
    if view.team.is_bot_speaking(message.chat.id):
        bot.send_message(message.chat.id, get_msg(MSG_PLAIN_TEXT))
示例#18
0
def shut(message):
    view.team.change_bot_reaction(message.chat.id, False)
    bot.send_message(message.chat.id, get_msg(MSG_STOP_SPEAK))
示例#19
0
def speak(message):
    view.team.change_bot_reaction(message.chat.id, True)
    bot.send_message(message.chat.id, get_msg(MSG_START_SPEAK))
示例#20
0
 def wrapper(message):
     if message.from_user.id in ADMIN_USER_IDS:
         func(message)
     else:
         bot.send_message(message.chat.id, get_msg(MSG_SUDO))
示例#21
0
 def wrapper(message):
     if MODE == ONLINE:
         func(message)
     else:
         bot.send_message(message.chat.id, get_msg(MSG_ONLINE_MODE))
示例#22
0
def help(message):
    if MODE == ONLINE:
        bot.send_message(message.chat.id, get_msg(MSG_HELP_ON))
    else:
        bot.send_message(message.chat.id, get_msg(MSG_HELP_OFF))