Ejemplo n.º 1
0
def new_game(message: Message):
    bot.send_chat_action(action='typing', chat_id=message.from_user.id)
    if dbm.get_user_language(message.from_user.id) == "NONE" and (
            message.text != "English" and message.text != "Русский"):
        bot.send_message(message.chat.id, text.UNDEFINED_LANGUAGE)
    else:
        if dbm.get_user_game_state(user_id=message.from_user.id) == "NONE":
            message_text = getattr(
                text,
                dbm.get_user_language(message.from_user.id) +
                "_cant_end_game")()
            bot.send_message(message.chat.id, message_text)
        elif dbm.get_user_game_state(message.from_user.id) == states.GAMING:
            message_text = getattr(
                text,
                dbm.get_user_language(message.from_user.id) + "_ended_game")()
            dbm.update(user_id=message.from_user.id,
                       item='Game_status',
                       new_value=states.NONE)
            dbm.update(user_id=message.from_user.id,
                       item='Game_comb',
                       new_value=states.NONE)
            dbm.update(user_id=message.from_user.id,
                       item='Steps',
                       new_value=states.NONE)
            bot.send_message(chat_id=message.chat.id, text=message_text)
        else:
            bot.send_message(message.chat.id, 'Error')
Ejemplo n.º 2
0
def new_game(message: Message):
    bot.send_chat_action(action='typing', chat_id=message.from_user.id)
    if dbm.get_user_language(message.from_user.id) == "NONE" and (
            message.text != "English" and message.text != "Русский"):
        bot.send_message(message.chat.id, text.UNDEFINED_LANGUAGE)
    else:
        if dbm.get_user_game_state(message.from_user.id) == states.GAMING:
            message_text = getattr(
                text,
                dbm.get_user_language(message.from_user.id) +
                "_new_game_while_gaming")()
            bot.send_message(message.chat.id, message_text)
        elif dbm.get_user_game_state(message.from_user.id) == states.NONE:
            message_text = getattr(
                text,
                dbm.get_user_language(user_id=message.from_user.id) +
                "_game_rules")()
            dbm.update(user_id=message.from_user.id,
                       item='Game_status',
                       new_value=states.GAMING)
            dbm.update(user_id=message.from_user.id,
                       item='Game_comb',
                       new_value=random_combination())
            dbm.update(user_id=message.from_user.id,
                       item='Steps',
                       new_value=str(0))
            bot.send_message(message.chat.id, message_text, parse_mode='HTML')
        else:
            bot.send_message(message.chat.id, 'Error')
Ejemplo n.º 3
0
def send_welcome(message: Message):
    bot.send_chat_action(action='typing', chat_id=message.from_user.id)
    if dbm.exists(value=message.from_user.id):
        if dbm.get_user_language(message.from_user.id) == "NONE" and (
                message.text != "English" and message.text != "Русский"):
            bot.send_message(message.chat.id, text.UNDEFINED_LANGUAGE)
        else:
            bot.send_message(
                message.chat.id,
                getattr(
                    text,
                    dbm.get_user_language(message.from_user.id) +
                    "_user_return")(message.from_user.first_name, ))
    else:
        dbm.append_in_table(
            ID=message.from_user.id,
            First_Name=message.from_user.first_name,
            # Last_Name=message.from_user.last_name,
            User_language='NONE',
            # Login='******' + message.from_user.username,
            Best_score='NONE',
            Game_comb='NONE',
            Steps='NONE',
            Game_status='NONE',
            Games=0)
        bot.send_message(message.chat.id,
                         text.HELLO_MESSAGE,
                         parse_mode='HTML')
Ejemplo n.º 4
0
def about_author(message: Message):
    bot.send_chat_action(action='typing', chat_id=message.from_user.id)
    if dbm.get_user_language(message.from_user.id) == "NONE" and (
            message.text != "English" and message.text != "Русский"):
        # bot.send_message(message.chat.id, text.UNDEFINED_LANGUAGE)
        bot.reply_to(message, text.UNDEFINED_LANGUAGE)
    else:
        message_text = getattr(
            text,
            dbm.get_user_language(message.from_user.id) + "_about_author")()
        # bot.send_message(message.chat.id, message_text, parse_mode='HTML')
        bot.reply_to(message, message_text, parse_mode='HTML')
Ejemplo n.º 5
0
def set_ENG_language(message: Message):
    bot.send_chat_action(action='typing', chat_id=message.from_user.id)
    if dbm.get_user_language(message.from_user.id) == "Russian":
        # bot.send_message(message.chat.id, "Этот язык уже установлен")
        bot.reply_to(message, "Этот язык уже установлен")
    else:
        dbm.update(user_id=message.from_user.id,
                   item='User_language',
                   new_value='Russian')
        # bot.send_message(message.chat.id, getattr(text, dbm.get_user_language(message.from_user.id) + "_set")())
        bot.reply_to(
            message,
            getattr(text,
                    dbm.get_user_language(message.from_user.id) + "_set")())
Ejemplo n.º 6
0
def set_ENG_language(message: Message):
    bot.send_chat_action(action='typing', chat_id=message.from_user.id)
    if dbm.get_user_language(message.from_user.id) == "English":
        # bot.send_message(message.chat.id, "This language is already set")
        bot.reply_to(message, "This language is already set")
    else:
        dbm.update(user_id=message.from_user.id,
                   item='User_language',
                   new_value='English')
        # bot.send_message(message.chat.id, getattr(text, dbm.get_user_language(message.from_user.id) + "_set")())
        bot.reply_to(
            message,
            getattr(text,
                    dbm.get_user_language(message.from_user.id) + "_set")())
Ejemplo n.º 7
0
def list_of_values(message: Message):
    bot.reply_to(
        message=message,
        text='<b>' + getattr(
            text,
            dbm.get_user_language(message.from_user.id) + "_get_top_three")() +
        '</b>\n' + dbm.get_top_three(message),
        parse_mode='HTML')
Ejemplo n.º 8
0
def list_matches_in_answer(matches: list, message: Message) -> str:
    shuffle(matches)
    answer = ''
    for x in matches:
        if x == '2':
            answer += '⚫'
        elif x == '1':
            answer += '⚪'
    if answer == '⚫⚫⚫⚫':
        answer = getattr(text,
                         dbm.get_user_language(message.from_user.id) +
                         "_won")()

    return answer
Ejemplo n.º 9
0
def main(message: Message):
    bot.send_chat_action(action='typing', chat_id=message.from_user.id)
    if dbm.get_user_language(message.from_user.id) == "NONE" and (
            message.text != "English" and message.text != "Русский"):
        bot.send_message(message.chat.id, text.UNDEFINED_LANGUAGE)
    elif dbm.get_user_game_state(user_id=message.from_user.id) == "gaming" and \
            dbm.get_user_game_combination(user_id=message.from_user.id) != "NONE":
        if RepresentsInt(message.text) and len(message.text) == 4:
            message_out = check_matching(message)
            # bot.send_message(message.chat.id, message_out)
            bot.reply_to(message, message_out)
            step = int(
                dbm.get_user_game_steps(user_id=message.from_user.id)) + 1
            dbm.update(user_id=message.from_user.id,
                       item='Steps',
                       new_value=str(step))
            if message_out == 'You won!' or message_out == 'Ты выиграл!':
                bot.send_sticker(chat_id=message.chat.id,
                                 data=text.get_random_cat_sticker())
                bot.send_document(chat_id=message.chat.id,
                                  data=text.get_random_cat_gif())
                games = int(
                    dbm.get_user_games_number(user_id=message.from_user.id))
                dbm.update(user_id=message.from_user.id,
                           new_value=str(games + 1),
                           item='Games')
                dbm.append_game_in_table(
                    ID=message.from_user.id,
                    Game_number=games + 1,
                    Number_of_steps=dbm.get_user_game_steps(
                        user_id=message.from_user.id))
                dbm.update(user_id=message.from_user.id,
                           new_value='NONE',
                           item='Steps')
                dbm.update(user_id=message.from_user.id,
                           new_value='NONE',
                           item='Game_comb')
                dbm.update(user_id=message.from_user.id,
                           new_value='NONE',
                           item='Game_status')
                if str(dbm.get_user_best_score(
                        user_id=message.from_user.id)) == 'NONE' or step < int(
                            dbm.get_user_best_score(
                                user_id=message.from_user.id)):
                    dbm.update(user_id=message.from_user.id,
                               new_value=str(step),
                               item='Best_score')
                    dbm.update(user_id=message.from_user.id,
                               item='Game_status',
                               new_value=states.NONE)
                    dbm.update(user_id=message.from_user.id,
                               item='Game_comb',
                               new_value=states.NONE)
                    dbm.update(user_id=message.from_user.id,
                               item='Steps',
                               new_value=states.NONE)
        elif RepresentsInt(message.text) and len(message.text) != 4:
            message_text = getattr(
                text,
                dbm.get_user_language(message.from_user.id) +
                "_send_correct_comb")()
            # bot.send_message(message.chat.id, message_text)
            bot.reply_to(message, message_text)
        else:
            message_text = getattr(
                text,
                dbm.get_user_language(message.from_user.id) +
                "_send_your_comb")()
            # bot.send_message(message.chat.id, message_text)
            bot.reply_to(message, message_text)
    else:
        message_text = getattr(
            text,
            dbm.get_user_language(message.from_user.id) + "_undefined_text")()
        #bot.send_message(message.chat.id, message_text)
        bot.reply_to(message, message_text)