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

86 lines
2.9 KiB
Python
Raw Normal View History

2023-02-15 12:13:07 +02:00
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
2023-02-15 12:13:07 +02:00
from modules.utils import configGet, jsonLoad, locale
2023-03-09 17:25:06 +02:00
# Callback sid =================================================================================================================
@app.on_callback_query(filters.regex("sid_[\s\S]*"))
async def callback_query_sid(app: Client, clb: CallbackQuery):
2023-03-09 17:25:06 +02:00
await clb.answer(
url=f'https://t.me/{(await app.get_me()).username}?start={clb.data.split("_")[1]}'
)
# ==============================================================================================================================
2023-03-09 17:25:06 +02:00
# Callback shc =================================================================================================================
@app.on_callback_query(filters.regex("shc_[\s\S]*"))
async def callback_query_shc(app: Client, clb: CallbackQuery):
2023-03-09 17:25:06 +02:00
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,
)
2023-02-15 12:13:07 +02:00
return
2023-03-09 17:25:06 +02:00
spoil = col_spoilers.find_one({"_id": ObjectId(clb.data.split("_")[1])})
if spoil["description"] == "":
2023-03-09 17:25:06 +02:00
desc = locale("spoiler_empty_named", "message", locale=clb.from_user).format(
locale(spoil["category"], "message", "spoiler_categories"),
clb.from_user.first_name,
)
else:
2023-03-09 17:25:06 +02:00
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]}',
)
]
]
),
)
2023-03-09 17:25:06 +02:00
await clb.answer(
locale("spoiler_sent", "callback", locale=clb.from_user), show_alert=True
)
2023-03-09 17:25:06 +02:00
# ==============================================================================================================================