Grinse commited on
Commit
40e2f6f
·
verified ·
1 Parent(s): 7c28b1a

Upload 2 files

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