from hikkatl.tl.types import ( ReplyInlineMarkup, KeyboardButtonCallback, KeyboardButtonUrl, ) from .. import utils, loader from hikkatl.tl.patched import Message # meta developer: @sqlmerr_m # meta icon: https://github.com/sqlmerr/hikka_mods/blob/main/assets/icons/quicktools.png?raw=true # meta banner: https://github.com/sqlmerr/sqlmerr/blob/main/assets/hikka_mods/quicktools.png?raw=true @loader.tds class QuickTools(loader.Module): """Module with various quick and useful tools""" strings = { "name": "QuickTools", "id_cmd_text": ( "🆔 Id\n" "· 🫵 Your id: {}\n" "· 💬 Chat id: {}\n" "· 🎈 User id: {}\n" "· 💬 Replied Message id: {}\n" ), "reply_markup_cmd_text": "📌 Buttons:\n{}", "entity_link_cmd_text": "🔗 Your link: {}", "empty": "Empty", "no_reply": " No reply!", "no_args": " No args!", "no_reply_markup": " No reply markup!", } strings_ru = { "id_cmd_text": ( "🆔 Айди\n" "· 🫵 Твой айди: {}\n" "· 💬 Айди чата: {}\n" "· 🎈 Айди пользователя: {}\n" "· 💬 Айди ответного сообщения: {}\n" ), "reply_markup_cmd_text": "📌 Кнопки:\n{}", "entity_link_cmd_text": "🔗 Ваша ссылка: {}", "empty": "Отсутствует", "no_reply": " Вы не ответили на сообщение!", "no_args": " Вы не передали аргументы!", "no_reply_markup": " Вы ответили на сообщение, где нет кнопок!", "_cls_doc": "Модуль с разными быстрыми и полезными инструментами", } @loader.command( ru_doc="<реплай на сообщение> Получить айди пользователя/чата/отправителя/сообщения" ) async def id(self, message: Message) -> None: """ Get user/chat/sender/replied message/message ID""" reply: Message = await message.get_reply_message() sender_id = message.from_id chat_id = message.chat_id user_id = reply.from_id if reply else self.strings("empty") message_id = reply.id if reply else self.strings("empty") text = self.strings("id_cmd_text").format( sender_id, chat_id, user_id, message_id ) await utils.answer(message, text) @loader.command(ru_doc="<реплай на сообщение> Получить текст сообщения") async def text(self, message: Message) -> None: """ Get replied message text""" reply: Message = await message.get_reply_message() text = reply.text if (reply and reply.text) else "" await utils.answer(message, f"
{utils.escape_html(text)}
") @loader.command(ru_doc="<реплай на сообщение> Получить кнопки сообщения") async def reply_markup(self, message: Message) -> None: """ Get replied message reply markup (buttons)""" reply: Message = await message.get_reply_message() if not reply: await utils.answer(message, self.strings("no_reply")) return reply_markup = reply.reply_markup if not reply_markup or not isinstance(reply_markup, ReplyInlineMarkup): await utils.answer(message, self.strings("no_reply_markup")) return buttons = [] for row in reply_markup.rows: buttons.extend(row.buttons) text = "" for button in buttons: if isinstance(button, KeyboardButtonCallback): value = button.data.decode("utf-8") value_type = "data" elif isinstance(button, KeyboardButtonUrl): value = button.url value_type = "url" else: text += f" - {button.text}\n" continue text += f" - {button.text} - {value_type}: {value}\n" await utils.answer(message, self.strings("reply_markup_cmd_text").format(text)) @loader.command() async def entity_link(self, message: Message) -> None: """ - creates link to entity (chat/user)""" args = utils.get_args(message) if len(args) == 0 or not args[0].isdigit() and not args[0].startswith("@"): await utils.answer(message, self.strings("no_args")) return openmessage = bool(args[1]) if len(args) > 1 else False if args[0].startswith("@"): entity = await self.client.get_entity(args[0]) else: entity = await self.client.get_entity(int(args[0])) link = utils.get_entity_url(entity, openmessage) await utils.answer(message, self.strings("entity_link_cmd_text").format(link))