-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstart.py
More file actions
57 lines (40 loc) · 1.35 KB
/
start.py
File metadata and controls
57 lines (40 loc) · 1.35 KB
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
import os
import dotenv
import logging
import signal
from Secret import Secret
from telegram import Update
from telegram.ext import (
CommandHandler,
MessageHandler,
filters,
Application,
ContextTypes,
)
dotenv.load_dotenv()
# Enable logging
logging.basicConfig(
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO
)
logging.getLogger("httpx").setLevel(logging.WARNING)
# Define the start command handler
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
chat_id = update.message.chat_id
await context.bot.send_message(
chat_id=chat_id,
text=f"Your chat ID has been saved. You can now start using the store. Your chat ID is: <code>{chat_id}</code>",
parse_mode="HTML",
)
secret = Secret()
secret["chat_id"] = chat_id
os.kill(os.getpid(), signal.SIGINT)
async def echo(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
await update.message.reply_text("Unknown command. Please use /start to begin.")
def main() -> None:
"""Start the bot."""
application = Application.builder().token(Secret()["token"]).build()
application.add_handler(CommandHandler("start", start))
application.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, echo))
application.run_polling()
if __name__ == "__main__":
main()