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/callbacks/spoiler.py
2023-03-09 16:31:39 +01:00

78 lines
2.4 KiB
Python

from os import path
from app import app
from pyrogram.types import CallbackQuery, InlineKeyboardMarkup, InlineKeyboardButton
from pyrogram.client import Client
from pyrogram import filters
from modules.database import col_spoilers
from bson.objectid import ObjectId
from modules.utils import configGet, jsonLoad, locale
@app.on_callback_query(filters.regex("sid_[\s\S]*"))
async def callback_query_sid(app: Client, clb: CallbackQuery):
await clb.answer(
url=f'https://t.me/{(await app.get_me()).username}?start={clb.data.split("_")[1]}'
)
@app.on_callback_query(filters.regex("shc_[\s\S]*"))
async def callback_query_shc(app: Client, clb: CallbackQuery):
if clb.from_user.id not in jsonLoad(
path.join(configGet("cache", "locations"), "group_members")
):
await clb.answer(
locale("spoiler_forbidden", "callback", locale=clb.from_user),
show_alert=True,
)
return
spoil = col_spoilers.find_one({"_id": ObjectId(clb.data.split("_")[1])})
if spoil["description"] == "":
desc = locale("spoiler_empty_named", "message", locale=clb.from_user).format(
locale(spoil["category"], "message", "spoiler_categories"),
clb.from_user.first_name,
)
else:
desc = locale(
"spoiler_described_named", "message", locale=clb.from_user
).format(
locale(spoil["category"], "message", "spoiler_categories"),
clb.from_user.first_name,
spoil["description"],
)
await app.send_message(
configGet("users", "groups"),
desc,
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
locale("spoiler_view", "button", locale=clb.from_user),
callback_data=f'sid_{clb.data.split("_")[1]}',
)
]
]
),
)
await app.send_message(
configGet("admin", "groups"),
desc,
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
locale("spoiler_view", "button", locale=clb.from_user),
callback_data=f'sid_{clb.data.split("_")[1]}',
)
]
]
),
)
await clb.answer(
locale("spoiler_sent", "callback", locale=clb.from_user), show_alert=True
)