123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- # █ █ ▀ █▄▀ ▄▀█ █▀█ ▀
- # █▀█ █ █ █ █▀█ █▀▄ █
- # © Copyright 2022
- # https://t.me/hikariatama
- #
- # 🔒 Licensed under the GNU AGPLv3
- # 🌐 https://www.gnu.org/licenses/agpl-3.0.html
- # scope: inline
- import logging
- import re
- import string
- from telethon.errors.rpcerrorlist import YouBlockedUserError
- from telethon.tl.functions.contacts import UnblockRequest
- from telethon.tl.types import Message
- from .. import loader, utils
- logger = logging.getLogger(__name__)
- @loader.tds
- class InlineStuffMod(loader.Module):
- """Provides support for inline stuff"""
- strings = {
- "name": "InlineStuff",
- "bot_username_invalid": (
- "🚫 <b>Specified bot username is invalid. It must end with"
- " </b><code>bot</code><b> and contain at least 4 symbols</b>"
- ),
- "bot_username_occupied": "🚫 <b>This username is already occupied</b>",
- "bot_updated": (
- "😌 <b>Config successfully saved. Restart userbot to apply changes</b>"
- ),
- }
- strings_ru = {
- "bot_username_invalid": (
- "🚫 <b>Неправильный ник бота. Он должен заканчиваться на"
- " </b><code>bot</code><b> и быть не короче чем 5 символов</b>"
- ),
- "bot_username_occupied": "🚫 <b>Такой ник бота уже занят</b>",
- "bot_updated": (
- "😌 <b>Настройки сохранены. Для их применения нужно перезагрузить"
- " юзербот</b>"
- ),
- "_cmd_doc_ch_hikka_bot": "<username> - Изменить юзернейм инлайн бота",
- }
- async def watcher(self, message: Message):
- if (
- getattr(message, "out", False)
- and getattr(message, "via_bot_id", False)
- and message.via_bot_id == self.inline.bot_id
- and "This message will be deleted automatically"
- in getattr(message, "raw_text", "")
- ):
- await message.delete()
- return
- if (
- not getattr(message, "out", False)
- or not getattr(message, "via_bot_id", False)
- or message.via_bot_id != self.inline.bot_id
- or "Loading Hikka gallery..." not in getattr(message, "raw_text", "")
- ):
- return
- id_ = re.search(r"#id: ([a-zA-Z0-9]+)", message.raw_text)[1]
- await message.delete()
- m = await message.respond("🌘 <b>Opening gallery... wait</b>")
- await self.inline.gallery(
- message=m,
- next_handler=self.inline._custom_map[id_]["handler"],
- caption=self.inline._custom_map[id_].get("caption", ""),
- force_me=self.inline._custom_map[id_].get("force_me", False),
- disable_security=self.inline._custom_map[id_].get(
- "disable_security", False
- ),
- )
- async def _check_bot(self, username: str) -> bool:
- async with self._client.conversation("@BotFather", exclusive=False) as conv:
- try:
- m = await conv.send_message("/token")
- except YouBlockedUserError:
- await self._client(UnblockRequest(id="@BotFather"))
- m = await conv.send_message("/token")
- r = await conv.get_response()
- await m.delete()
- await r.delete()
- if not hasattr(r, "reply_markup") or not hasattr(r.reply_markup, "rows"):
- return False
- for row in r.reply_markup.rows:
- for button in row.buttons:
- if username != button.text.strip("@"):
- continue
- m = await conv.send_message("/cancel")
- r = await conv.get_response()
- await m.delete()
- await r.delete()
- return True
- async def ch_hikka_botcmd(self, message: Message):
- """<username> - Change your Hikka inline bot username"""
- args = utils.get_args_raw(message).strip("@")
- if (
- not args
- or not args.lower().endswith("bot")
- or len(args) <= 4
- or any(
- litera not in (string.ascii_letters + string.digits + "_")
- for litera in args
- )
- ):
- await utils.answer(message, self.strings("bot_username_invalid"))
- return
- try:
- await self._client.get_entity(f"@{args}")
- except ValueError:
- pass
- else:
- if not await self._check_bot(args):
- await utils.answer(message, self.strings("bot_username_occupied"))
- return
- self._db.set("hikka.inline", "custom_bot", args)
- self._db.set("hikka.inline", "bot_token", None)
- await utils.answer(message, self.strings("bot_updated"))
|