|
| 1 | +# Moon-Userbot - telegram userbot |
| 2 | +# Copyright (C) 2020-present Moon Userbot Organization |
| 3 | +# |
| 4 | +# This program is free software: you can redistribute it and/or modify |
| 5 | +# it under the terms of the GNU General Public License as published by |
| 6 | +# the Free Software Foundation, either version 3 of the License, or |
| 7 | +# (at your option) any later version. |
| 8 | + |
| 9 | +# This program is distributed in the hope that it will be useful, |
| 10 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +# GNU General Public License for more details. |
| 13 | + |
| 14 | +# You should have received a copy of the GNU General Public License |
| 15 | +# along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +from pyrogram import Client, filters |
| 18 | +from pyrogram.types import Message |
| 19 | + |
| 20 | +from utils.misc import modules_help, prefix |
| 21 | + |
| 22 | + |
| 23 | +from utils.scripts import import_library |
| 24 | + |
| 25 | +libgen_api = import_library("libgen_api", "libgen-api") |
| 26 | +from libgen_api import LibgenSearch |
| 27 | + |
| 28 | + |
| 29 | +@Client.on_message(filters.command("ebook", prefix) & filters.me) |
| 30 | +async def ebook_search(_, message: Message): |
| 31 | + if len(message.command) < 2: |
| 32 | + return await message.edit("Give me something to search for!") |
| 33 | + text = message.text.split(maxsplit=1)[1] |
| 34 | + m = await message.edit("Searching...") |
| 35 | + s = LibgenSearch() |
| 36 | + results = s.search_title_filtered( |
| 37 | + text, |
| 38 | + { |
| 39 | + "Extension": "epub", |
| 40 | + "Language": "English", |
| 41 | + }, |
| 42 | + ) |
| 43 | + await m.edit( |
| 44 | + f"<b>Search Query:</b>\n<code>{text}</code>\n\n<b>Results:</b>\n{''.join([f'<a href="{i['Mirror_1']}">{i['Title']}</a>\n\n' for i in results])}", |
| 45 | + disable_web_page_preview=True, |
| 46 | + ) |
| 47 | + |
| 48 | + |
| 49 | +modules_help["ebook"] = { |
| 50 | + "ebook": "Search for ebooks on libgen.rs" |
| 51 | + f"\n<b>Example:</b> <code>{prefix}ebook Pride and Prejudice</code>", |
| 52 | +} |
0 commit comments