__version__ = (1, 0, 4)
# █ █ ▀ █▄▀ ▄▀█ █▀█ ▀
# █▀█ █ █ █ █▀█ █▀▄ █
# © Copyright 2022
# https://t.me/hikariatama
#
# 🔒 Licensed under the GNU AGPLv3
# 🌐 https://www.gnu.org/licenses/agpl-3.0.html
# meta pic: https://img.icons8.com/external-sketchy-juicy-fish/480/000000/external-anonymous-cryptography-sketchy-sketchy-juicy-fish.png
# meta banner: https://mods.hikariatama.ru/badges/spoilers.jpg
# meta developer: @hikarimods
# scope: inline
# scope: hikka_only
# scope: hikka_min 1.3.3
import logging
from telethon.utils import get_display_name, resolve_inline_message_id
from .. import loader, utils
from ..inline.types import InlineCall, InlineQuery
logger = logging.getLogger(__name__)
@loader.tds
class SpoilersMod(loader.Module):
"""Create spoilers, that can be accessed only by certain users"""
_cache = {}
_msg_cache = {}
strings = {
"name": "Spoilers",
"only_he_can_open": "ℹ Only (s)he will be able to open it",
"message": (
'🫦 Hidden message for {}\nYou can'
" open this message only once!"
),
"user_not_specified": (
"🫦 Hidden message for you!\nYou can"
" open this message only once!"
),
"not4u": "🫦 I won't whisper you",
"open": "👀 Open",
"in_the_end": "Send spoiler to user in reply",
"broken": "🫦 Cats have eaten this whisper. Do not whisper in pm anymore.",
}
strings_ru = {
"only_he_can_open": "ℹ Только он(-а) сможет открыть его",
"message": (
'🫦 Шепот для {}\nСообщение можно'
" открыть только один раз!"
),
"user_not_specified": (
"🫦 Шепот для тебя!\nСообщение можно открыть только один раз!"
),
"not4u": "🫦 Я не буду тебе шептать",
"open": "👀 Открыть",
"in_the_end": "Отправь шепот пользователю в ответе",
"_cls_doc": (
"Создает спойлеры, которые доступны только определенным пользователям"
),
"broken": "🫦 Коты съели этот шепот. Не шепчите в личных сообщениях.",
}
strings_de = {
"only_he_can_open": "ℹ Nur er/sie kann es öffnen",
"message": (
'🫦 Geheimnachricht für {}\nDu'
" kannst diese Nachricht nur einmal öffnen!"
),
"user_not_specified": (
"🫦 Geheimnachricht für dich!\nDu kannst diese Nachricht nur"
" einmal öffnen!"
),
"not4u": "🫦 Ich werde dir nicht flüstern",
"open": "👀 Öffnen",
"in_the_end": "Sende Geheimnachricht an Benutzer als Antwort",
"_cls_doc": (
"Erstellt Geheimnachrichten, die nur bestimmten Benutzern zugänglich sind"
),
"broken": (
"🫦 Die Katzen haben diesen Geheimnachricht gefressen. Flüstern Sie nicht"
" mehr in PM."
),
}
strings_tr = {
"only_he_can_open": "ℹ Sadece onu açabilir",
"message": (
'🫦 {} için gizli mesaj\nBu mesajı'
" yalnızca bir kez açabilirsiniz!"
),
"user_not_specified": (
"🫦 Sana gizli mesaj!\nBu mesajı yalnızca bir kez"
" açabilirsiniz!"
),
"not4u": "🫦 Sana fısıldamayacağım",
"open": "👀 Açmak",
"in_the_end": "Kullanıcıya yanıt olarak gizli mesaj gönder",
"_cls_doc": (
"Sadece belirli kullanıcılara erişilebilen gizli mesajlar oluşturur"
),
"broken": "🫦 Bu gizli mesaj kediler tarafından yendi. PM'de fısıldamayın.",
}
strings_uz = {
"only_he_can_open": "ℹ Faqat u o'ynay oladi",
"message": (
'🫦 {} uchun shifrlangan xabar\nSiz'
" bu xabarni faqat bir marta ochishingiz mumkin!"
),
"user_not_specified": (
"🫦 Siz uchun shifrlangan xabar!\nSiz bu xabarni faqat bir marta"
" ochishingiz mumkin!"
),
"not4u": "🫦 Sizga shifrlashmayman",
"open": "👀 Ochish",
"in_the_end": "Foydalanuvchiga javob sifrlangan xabarini yuborish",
"_cls_doc": (
"Faqat belgilangan foydalanuvchilarga kirish mumkin bo'lgan shifrlangan"
" xabarlar yaratadi"
),
"broken": (
"🫦 Bu shifrlangan xabar moshinalar tomonidan yig'ildi. PM'da"
" shifrlashmayin."
),
}
@loader.inline_handler(
ru_doc="Создать скрытое сообщение",
de_doc="Erstellt eine versteckte Nachricht",
uz_doc="Shifrlangan xabar yaratish",
tr_doc="Gizli mesaj oluştur",
hi_doc="छिपा संदेश बनाएं",
)
async def hide(self, query: InlineQuery):
"""Create hidden message"""
text = query.args
for_user = self.strings("in_the_end")
for_user_id = None
user = None
if len(text.split()) > 1:
try:
possible_entity = text.split()[0]
if possible_entity.isdigit():
possible_entity = int(possible_entity)
user = await self._client.get_entity(possible_entity)
except Exception:
pass
else:
for_user = "Hidden message for " + get_display_name(user)
for_user_id = user.id
text = " ".join(text.split(" ")[1:])
id_ = utils.rand(16)
self._cache[id_] = text
return {
"title": for_user,
"description": self.strings("only_he_can_open"),
"message": (
self.strings("message").format(
for_user_id,
utils.escape_html(get_display_name(user)),
)
if user
else self.strings("user_not_specified").format(id_)
),
"thumb": "https://img.icons8.com/color/48/000000/anonymous-mask.png",
"reply_markup": {
"text": self.strings("open"),
"callback": self._handler,
"args": (text, for_user_id, id_),
"disable_security": True,
},
}
async def _handler(self, call: InlineCall, text: str, for_user: int, id_: str):
"""Process button presses"""
if for_user is None:
if id_ not in self._msg_cache:
message_id, peer, _, _ = resolve_inline_message_id(
call.inline_message_id
)
msg = (await self._client.get_messages(peer, ids=[message_id]))[0]
if msg is None:
await call.answer(self.strings("broken"))
self._msg_cache[id_] = None
return
msg = await msg.get_reply_message()
if msg is None:
await call.answer(self.strings("broken"))
self._msg_cache[id_] = None
return
else:
msg = self._msg_cache[id_]
if msg is None:
await call.answer(self.strings("broken"))
return
for_user = msg.sender_id
self._msg_cache[id_] = msg
if call.from_user.id not in {
for_user,
self._tg_id,
}:
await call.answer(self.strings("not4u"))
return
await call.answer(text, show_alert=True)
if call.from_user.id != self._tg_id:
message_id, peer, _, _ = resolve_inline_message_id(call.inline_message_id)
await self._client.delete_messages(peer, [message_id])