chore: Added translation for the start command, code link made as a button

This commit is contained in:
Danil 2025-05-17 00:34:56 +03:00
parent 6bf8b4c049
commit 722b79b523

View file

@ -1,28 +1,42 @@
from aiogram import types, Router from aiogram import types, Router
from aiogram.filters import CommandStart from aiogram.filters import CommandStart
import re
from bot import bot from bot import bot, db
from i18n.localization import I18n
router = Router() router = Router()
i18n = I18n()
def escape_md_v2(text: str) -> str:
return re.sub(r'([_*\[\]()~#+\-=|{}.!\\])', r'\\\1', text)
@router.message(CommandStart()) @router.message(CommandStart())
async def start(message: types.Message) -> None: async def start(message: types.Message) -> None:
get_bot = await bot.get_me() get_bot = await bot.get_me()
keyboard = types.InlineKeyboardMarkup(inline_keyboard=[ data = await db.fetch(
[ 'SELECT lang FROM users WHERE user_id = $1',
types.InlineKeyboardButton( message.from_user.id
text="Source Code",
url="https://github.com/redume/shirino"
) )
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=button_text,
url="https://github.com/redume/shirino")
] ]
]) ])
await message.reply( await message.reply(
'Shirino is a telegram bot for converting fiat or cryptocurrency. ' text,
'The example of use occurs via inline query:\n' parse_mode="MarkdownV2",
f'`@{get_bot.username} USD RUB` \n'
f'`@{get_bot.username} 12 USD RUB` \n\n',
parse_mode='markdown',
reply_markup=keyboard reply_markup=keyboard
) )