This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
Telegram/modules/commands/start.py

49 lines
2.4 KiB
Python
Raw Normal View History

2022-12-05 19:49:51 +02:00
from app import app
from pyrogram import filters
2022-12-27 14:36:54 +02:00
from pyrogram.types import ReplyKeyboardMarkup, Message
from pyrogram.client import Client
2022-12-11 20:52:14 +02:00
from modules.utils import locale, logWrite
2023-01-04 20:58:54 +02:00
from modules.database import col_users, col_spoilers
2023-01-03 21:34:13 +02:00
from modules import custom_filters
2023-01-04 20:58:54 +02:00
from bson.objectid import ObjectId
from bson.errors import InvalidId
2022-12-05 19:49:51 +02:00
# Start command ================================================================================================================
2023-01-03 21:34:13 +02:00
@app.on_message(custom_filters.enabled_applications & ~filters.scheduled & filters.private & filters.command(["start"], prefixes=["/"]))
2022-12-27 14:36:54 +02:00
async def cmd_start(app: Client, msg: Message):
2022-12-05 19:49:51 +02:00
2022-12-11 20:52:14 +02:00
user = col_users.find_one({"user": msg.from_user.id})
2022-12-05 19:49:51 +02:00
2022-12-11 20:52:14 +02:00
if user is None:
col_users.insert_one({
"user": msg.from_user.id,
"link": None,
"label": "",
"tg_name": msg.from_user.first_name,
"tg_phone": msg.from_user.phone_number,
"tg_locale": msg.from_user.language_code,
"tg_username": msg.from_user.username
})
logWrite(f"User {msg.from_user.id} started bot interaction")
2022-12-17 01:58:33 +02:00
await msg.reply_text(locale("start", "message", locale=msg.from_user), reply_markup=ReplyKeyboardMarkup(locale("welcome", "keyboard", locale=msg.from_user), resize_keyboard=True))
2023-01-04 20:58:54 +02:00
if len(msg.command) > 1:
try:
spoiler = col_spoilers.find_one( {"_id": ObjectId(msg.command[1])} )
if spoiler["photo"] is not None:
2023-01-07 01:38:53 +02:00
await msg.reply_cached_media(spoiler["photo"], caption=spoiler["caption"])
2023-01-04 20:58:54 +02:00
if spoiler["video"] is not None:
await msg.reply_cached_media(spoiler["video"], caption=spoiler["caption"])
2023-01-10 13:11:29 +02:00
if spoiler["audio"] is not None:
await msg.reply_cached_media(spoiler["audio"], caption=spoiler["caption"])
2023-01-04 20:58:54 +02:00
if spoiler["animation"] is not None:
await msg.reply_cached_media(spoiler["animation"], caption=spoiler["caption"])
2023-01-05 22:15:34 +02:00
if spoiler["document"] is not None:
2023-01-07 01:38:53 +02:00
await msg.reply_cached_media(spoiler["document"], caption=spoiler["caption"])
2023-01-04 20:58:54 +02:00
if spoiler["text"] is not None:
await msg.reply_text(spoiler["text"])
except InvalidId:
await msg.reply_text(f"Got an invalid ID {msg.command[1]}")
2022-12-05 19:49:51 +02:00
# ==============================================================================================================================