Example #1
0
def make_regenerate_keyboard(lang_code):
    keyboard = types.InlineKeyboardMarkup()
    btn = types.InlineKeyboardButton(text=all_strings.get(
        get_language(lang_code)).get("regenerate"),
                                     callback_data="regenerate")
    keyboard.add(btn)
    return keyboard
async def cmd_start(message: types.Message, state: FSMContext):
    # Initialize values for new user or update possible missing values for existing one
    await get_data(state)

    await message.answer(
        texts.all_strings.get(
            texts.get_language(message.from_user.language_code)).get("start"))
async def cmd_settings(message: types.Message, state: FSMContext):
    user_data = await get_data(state)
    keyboard = await kb.make_settings_keyboard_for_user_async(
        state, message.from_user.language_code)
    user_lang = texts.get_language(message.from_user.language_code)
    await message.answer(text=texts.get_settings_string(user_data, user_lang),
                         reply_markup=keyboard)
Example #4
0
async def toggle_separators(call: types.CallbackQuery,
                            callback_data: Dict[str, str], state: FSMContext):
    if callback_data["action"] == "disable":
        await storage.toggle_feature(state, "separators", False)
    elif callback_data["action"] == "enable":
        await storage.toggle_feature(state, "separators", True)
    else:
        return

    keyboard = await kb.make_settings_keyboard_for_user_async(
        state, call.from_user.language_code)
    user_data = await state.get_data()
    user_lang = texts.get_language(call.from_user.language_code)
    try:
        await call.message.edit_text(text=texts.get_settings_string(
            user_data, user_lang),
                                     reply_markup=keyboard)
    except MessageNotModified:
        pass
    await call.answer()
Example #5
0
async def change_wordcount(call: types.CallbackQuery,
                           callback_data: Dict[str, str], state: FSMContext):
    if callback_data["change"] == "minus":
        await storage.change_word_count(state, increase=False)
    elif callback_data["change"] == "plus":
        await storage.change_word_count(state, increase=True)
    else:
        return

    keyboard = await kb.make_settings_keyboard_for_user_async(
        state, call.from_user.language_code)
    user_data = await state.get_data()
    user_lang = texts.get_language(call.from_user.language_code)
    try:
        await call.message.edit_text(text=texts.get_settings_string(
            user_data, user_lang),
                                     reply_markup=keyboard)
    except MessageNotModified:
        pass
    await call.answer()
Example #6
0
async def make_settings_keyboard_for_user_async(
        state: FSMContext, lang_code: str) -> types.InlineKeyboardMarkup:
    kb = types.InlineKeyboardMarkup()
    data = await get_data(state)
    wordcount_buttons = []
    wordcount = data.get(DBKeys.WORDS_COUNT.value)
    if wordcount > app_config.min_words:
        wordcount_buttons.append(
            types.InlineKeyboardButton(
                text=all_strings.get(get_language(lang_code)).get("minusword"),
                callback_data=cb_wordcount.new(change="minus")))
    if wordcount < app_config.max_words:
        wordcount_buttons.append(
            types.InlineKeyboardButton(
                text=all_strings.get(get_language(lang_code)).get("plusword"),
                callback_data=cb_wordcount.new(change="plus")))
    kb.add(*wordcount_buttons)

    if data.get(DBKeys.PREFIXES_SUFFIXES.value, True) is True:
        kb.add(
            types.InlineKeyboardButton(
                text=all_strings.get(get_language(lang_code)).get("minuspref"),
                callback_data=cb_prefixes.new(action="disable")))
    else:
        kb.add(
            types.InlineKeyboardButton(
                text=all_strings.get(get_language(lang_code)).get("pluspref"),
                callback_data=cb_prefixes.new(action="enable")))

    if data.get(DBKeys.SEPARATORS.value, True) is True:
        kb.add(
            types.InlineKeyboardButton(
                text=all_strings.get(get_language(lang_code)).get("minussep"),
                callback_data=cb_separators.new(action="disable")))
    else:
        kb.add(
            types.InlineKeyboardButton(
                text=all_strings.get(get_language(lang_code)).get("plussep"),
                callback_data=cb_separators.new(action="enable")))

    return kb
async def cmd_help(message: types.Message):
    await message.answer(
        texts.all_strings.get(
            texts.get_language(message.from_user.language_code)).get("help"))