From 722b79b52341ace833fc9f13d7de3016a586048c Mon Sep 17 00:00:00 2001 From: Redume Date: Sat, 17 May 2025 00:34:56 +0300 Subject: [PATCH] chore: Added translation for the start command, code link made as a button --- commands/start.py | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/commands/start.py b/commands/start.py index 1d970c2..9ec6687 100644 --- a/commands/start.py +++ b/commands/start.py @@ -1,28 +1,42 @@ from aiogram import types, Router from aiogram.filters import CommandStart +import re -from bot import bot +from bot import bot, db +from i18n.localization import I18n router = Router() +i18n = I18n() + +def escape_md_v2(text: str) -> str: + return re.sub(r'([_*\[\]()~#+\-=|{}.!\\])', r'\\\1', text) @router.message(CommandStart()) async def start(message: types.Message) -> None: get_bot = await bot.get_me() + data = await db.fetch( + 'SELECT lang FROM users WHERE user_id = $1', + message.from_user.id + ) + + locale = i18n.get_locale(data.get('lang')) + + raw_template = locale.get("start_message") + raw_text = raw_template.format(bot_username=get_bot.username) + text = escape_md_v2(raw_text) + + button_text = locale.get("source_code_button") + keyboard = types.InlineKeyboardMarkup(inline_keyboard=[ - [ - types.InlineKeyboardButton( - text="Source Code", - url="https://github.com/redume/shirino" - ) + [types.InlineKeyboardButton( + text=button_text, + url="https://github.com/redume/shirino") ] ]) await message.reply( - 'Shirino is a telegram bot for converting fiat or cryptocurrency. ' - 'The example of use occurs via inline query:\n' - f'`@{get_bot.username} USD RUB` \n' - f'`@{get_bot.username} 12 USD RUB` \n\n', - parse_mode='markdown', + text, + parse_mode="MarkdownV2", reply_markup=keyboard )