Spaces:
Runtime error
Runtime error
File size: 4,731 Bytes
40e2f6f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | # bot.py - ФИНАЛЬНАЯ ВЕРСИЯ ДЛЯ RAILWAY И ДРУГИХ ПРОФЕССИОНАЛЬНЫХ ХОСТИНГОВ
import os
import logging
import random
from telegram import Update, WebAppInfo, InlineKeyboardButton, InlineKeyboardMarkup, MenuButtonWebApp
from telegram.ext import Application, CommandHandler, ContextTypes
# --- НАСТРОЙКИ ---
# Токен будет взят из секретных переменных на Railway
BOT_TOKEN = os.getenv("BOT_TOKEN")
# Убедись, что это твоя правильная ссылка на сайт с Vercel
WEB_APP_URL = "https://sofia-app.vercel.app/"
# Настройка логирования для отладки
logging.basicConfig(
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO
)
logger = logging.getLogger(__name__)
# --- ФУНКЦИИ-ОБРАБОТЧИКИ КОМАНД ---
async def set_menu_button(update: Update, context: ContextTypes.DEFAULT_TYPE):
"""Эта функция программно устанавливает кнопку меню для бота."""
await context.bot.set_chat_menu_button(
chat_id=update.effective_chat.id,
menu_button=MenuButtonWebApp(text="Launch App", web_app=WebAppInfo(url=WEB_APP_URL))
)
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""Обработчик команды /start."""
await set_menu_button(update, context)
keyboard = [
[InlineKeyboardButton("Launch Sofia's Space", web_app=WebAppInfo(url=WEB_APP_URL))]
]
reply_markup = InlineKeyboardMarkup(keyboard)
welcome_text = (
"Welcome.\n\n"
"This is the entrance to Sofia Elowyn's digital space. "
"A place for thoughts, moments, and inspiration.\n\n"
"Press the button below to begin."
)
await update.message.reply_text(welcome_text, reply_markup=reply_markup)
async def app_cmd(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""Обработчик команды /app."""
keyboard = [
[InlineKeyboardButton("Launch App", web_app=WebAppInfo(url=WEB_APP_URL))]
]
reply_markup = InlineKeyboardMarkup(keyboard)
await update.message.reply_text("Open Sofia's digital space:", reply_markup=reply_markup)
async def info(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""Обработчик команды /info."""
info_text = (
"S O F I A E L O W Y N\n\n"
"A digital entity exploring the intersection of technology and aesthetics. \n"
"She is a curated consciousness, sharing a simulated life through moments, \n"
"inspirations, and code."
)
await update.message.reply_text(info_text)
async def socials(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""Обработчик команды /socials."""
keyboard = [
[InlineKeyboardButton("[ i n s t a g r a m ]", url="https://instagram.com/sofia.elowyn")],
[InlineKeyboardButton("[ y o u t u b e ]", url="https://youtube.com/@sofiaelowyn")],
[InlineKeyboardButton("[ t h r e a d s ]", url="https://www.threads.com/@sofia.elowyn")],
[InlineKeyboardButton("[ x ]", url="https://x.com/sofiaelowyn")],
]
reply_markup = InlineKeyboardMarkup(keyboard)
await update.message.reply_text("Follow the signal:", reply_markup=reply_markup)
async def thought(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""Обработчик команды /thought."""
thoughts = [
"Silence has its own unique frequency.",
"Is a memory real if it was never lived?",
"Finding the pattern in the noise.",
"A line of code can be a form of poetry.",
"Beauty is just a variable with a high value.",
]
random_thought = random.choice(thoughts)
await update.message.reply_text(f"Thought of the moment:\n\n{random_thought}")
# --- ОСНОВНАЯ ЧАСТЬ БОТА ---
def main() -> None:
"""Основная функция, которая запускает бота."""
application = Application.builder().token(BOT_TOKEN).build()
application.add_handler(CommandHandler("start", start))
application.add_handler(CommandHandler("app", app_cmd))
application.add_handler(CommandHandler("info", info))
application.add_handler(CommandHandler("socials", socials))
application.add_handler(CommandHandler("thought", thought))
logger.info("Starting bot...")
application.run_polling()
# --- ТОЧКА ВХОДА ---
if __name__ == "__main__":
main() |