Spaces:
Runtime error
Runtime error
Download app/bot/keyboards/common.py from cipher-attacks/Dbu-central-bot: direct link, hf CLI and curl.
- Browser
- Download file 2.19 kB
-
https://huggingface.co/spaces/cipher-attacks/Dbu-central-bot/resolve/main/app/bot/keyboards/common.py
- Command line
-
hf download hf://spaces/cipher-attacks/Dbu-central-bot/app/bot/keyboards/common.py
-
curl -L -o common.py https://huggingface.co/spaces/cipher-attacks/Dbu-central-bot/resolve/main/app/bot/keyboards/common.py
2.19 kB
| from aiogram.types import ( | |
| InlineKeyboardButton, | |
| InlineKeyboardMarkup, | |
| KeyboardButton, | |
| ReplyKeyboardMarkup, | |
| WebAppInfo, | |
| ) | |
| from app.config import get_settings | |
| from app.core.catalog import STREAMS, YEARS | |
| from app.core.i18n import t | |
| def gate_kb(lang: str, missing: list[str]) -> InlineKeyboardMarkup: | |
| rows = [ | |
| [InlineKeyboardButton(text=t(lang, "gate_join_one", name=h), url=f"https://t.me/{h.lstrip('@')}")] | |
| for h in missing | |
| ] | |
| rows.append([InlineKeyboardButton(text=t(lang, "gate_check_btn"), callback_data="gate:check")]) | |
| return InlineKeyboardMarkup(inline_keyboard=rows) | |
| def share_kb(lang: str, url: str) -> InlineKeyboardMarkup: | |
| """One tap opens Telegram's own "send to..." picker with a ready message.""" | |
| return InlineKeyboardMarkup(inline_keyboard=[[InlineKeyboardButton(text=t(lang, "share_btn"), url=url)]]) | |
| def open_bot_kb(link: str) -> InlineKeyboardMarkup: | |
| return InlineKeyboardMarkup(inline_keyboard=[[InlineKeyboardButton(text=t("en", "inline_open_bot"), url=link)]]) | |
| def stream_kb(lang: str) -> InlineKeyboardMarkup: | |
| return InlineKeyboardMarkup( | |
| inline_keyboard=[ | |
| [InlineKeyboardButton(text=t(lang, f"stream_{s}"), callback_data=f"ob:stream:{s}")] | |
| for s in STREAMS | |
| ] | |
| ) | |
| def year_kb(lang: str) -> InlineKeyboardMarkup: | |
| buttons = [ | |
| InlineKeyboardButton(text=t(lang, "year_label", n=y), callback_data=f"ob:year:{y}") | |
| for y in YEARS | |
| ] | |
| return InlineKeyboardMarkup(inline_keyboard=[buttons[:3], buttons[3:]]) | |
| def main_menu(lang: str) -> ReplyKeyboardMarkup: | |
| def b(key: str) -> KeyboardButton: | |
| return KeyboardButton(text=t(lang, key)) | |
| mini_app_url = get_settings().telegram_webapp_url | |
| quiz_button = ( | |
| KeyboardButton(text=t(lang, "btn_quiz"), web_app=WebAppInfo(url=mini_app_url)) | |
| if mini_app_url | |
| else b("btn_quiz") | |
| ) | |
| return ReplyKeyboardMarkup( | |
| keyboard=[ | |
| [b("btn_library"), b("btn_contribute")], | |
| [quiz_button, b("btn_profile")], | |
| [b("btn_top")], | |
| [b("btn_gpa"), b("btn_invite")], | |
| ], | |
| resize_keyboard=True, | |
| ) | |