|
1 | 1 | # Ultroid - UserBot
|
2 |
| -# Copyright (C) 2020 TeamUltroid |
| 2 | +# Copyright (C) 2021 TeamUltroid |
3 | 3 | #
|
4 | 4 | # This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
|
5 | 5 | # PLease read the GNU Affero General Public License in
|
6 | 6 | # <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
|
7 | 7 |
|
8 | 8 | import base64
|
| 9 | +import os |
| 10 | +import urllib |
9 | 11 | from random import choice
|
10 | 12 | from re import compile as re_compile
|
11 | 13 | from re import findall
|
12 |
| -from urllib.request import urlopen |
13 | 14 |
|
14 | 15 | import requests
|
15 | 16 | from bs4 import BeautifulSoup
|
|
19 | 20 | from telethon import Button
|
20 | 21 | from telethon.tl.types import InputWebDocument as wb
|
21 | 22 |
|
| 23 | +from plugins._inline import SUP_BUTTONS |
| 24 | + |
22 | 25 | from . import *
|
23 | 26 | from . import humanbytes as hb
|
24 | 27 |
|
@@ -153,15 +156,7 @@ async def repo(e):
|
153 | 156 | description="Userbot | Telethon",
|
154 | 157 | thumb=wb(ultpic, 0, "image/jpeg", []),
|
155 | 158 | text="• **ULTROID USERBOT** •",
|
156 |
| - buttons=[ |
157 |
| - [ |
158 |
| - Button.url("Repo", url="https://github.com/TeamUltroid/Ultroid"), |
159 |
| - Button.url( |
160 |
| - "Addons", url="https://github.com/TeamUltroid/UltroidAddons" |
161 |
| - ), |
162 |
| - ], |
163 |
| - [Button.url("Support", url="t.me/UltroidSupport")], |
164 |
| - ], |
| 159 | + buttons=SUP_BUTTONS, |
165 | 160 | ),
|
166 | 161 | ]
|
167 | 162 | await e.answer(res, switch_pm="Ultroid Repo.", switch_pm_param="start")
|
@@ -426,22 +421,75 @@ async def _(e):
|
426 | 421 | await e.answer(modss, switch_pm="Search Mod Applications.", switch_pm_param="start")
|
427 | 422 |
|
428 | 423 |
|
429 |
| -@in_pattern("clipart") |
| 424 | +@in_pattern("ebooks") |
430 | 425 | @in_owner
|
431 | 426 | async def clip(e):
|
432 | 427 | try:
|
433 | 428 | quer = e.text.split(" ", maxsplit=1)[1]
|
434 | 429 | except IndexError:
|
435 |
| - await e.answer([], switch_pm="ClipArt Search.", switch_pm_param="start") |
| 430 | + await e.answer( |
| 431 | + [], switch_pm="Enter Query to Look for EBook", switch_pm_param="start" |
| 432 | + ) |
| 433 | + return |
436 | 434 | quer = quer.replace(" ", "+")
|
437 |
| - sear = f"https://clipartix.com/search/{quer}" |
438 |
| - html = urlopen(sear) |
439 |
| - bs = BeautifulSoup(html, "html.parser", from_encoding="utf-8") |
440 |
| - resul = bs.find_all("img", "attachment-full size-full") |
| 435 | + sear = f"http://www.gutenberg.org/ebooks/search/?query={quer}&submit_search=Go%21" |
| 436 | + magma = requests.get(sear).content |
| 437 | + bs = BeautifulSoup(magma, "html.parser", from_encoding="utf-8") |
| 438 | + out = bs.find_all("img") |
| 439 | + Alink = bs.find_all("a", "link") |
| 440 | + if len(out) == 0: |
| 441 | + return await e.answer( |
| 442 | + [], switch_pm="No Results Found !", switch_pm_param="start" |
| 443 | + ) |
441 | 444 | buil = e.builder
|
| 445 | + dont_take = [ |
| 446 | + "Authors", |
| 447 | + "Did you mean", |
| 448 | + "Sort Alpha", |
| 449 | + "Sort by", |
| 450 | + "Subjects", |
| 451 | + "Bookshelves", |
| 452 | + ] |
442 | 453 | hm = []
|
443 |
| - for res in resul: |
444 |
| - hm += [buil.photo(include_media=True, file=res["src"])] |
445 |
| - await e.answer( |
446 |
| - hm, gallery=True, switch_pm="Clipart Searcher.", switch_pm_param="start" |
447 |
| - ) |
| 454 | + titles = [] |
| 455 | + for num in Alink: |
| 456 | + try: |
| 457 | + rt = num.find("span", "title").text |
| 458 | + if not rt.startswith(tuple(dont_take)): |
| 459 | + titles.append(rt) |
| 460 | + except BaseException: |
| 461 | + pass |
| 462 | + for rs in range(len(out)): |
| 463 | + if "/cache/epub" in out[rs]["src"]: |
| 464 | + link = out[rs]["src"] |
| 465 | + num = link.split("/")[3] |
| 466 | + hm.append( |
| 467 | + buil.document( |
| 468 | + title=titles[rs], |
| 469 | + description="GutenBerg Search", |
| 470 | + file="https://gutenberg.org" + link.replace("small", "medium"), |
| 471 | + text=f"**• Ebook Search**\n\n->> `{titles[rs]}`", |
| 472 | + buttons=Button.inline("Get as Doc", data=f"ebk_{num}"), |
| 473 | + ) |
| 474 | + ) |
| 475 | + await e.answer(hm, switch_pm="Ebooks Search", switch_pm_param="start") |
| 476 | + |
| 477 | + |
| 478 | +@callback(re_compile("ebk_(.*)")) |
| 479 | +async def eupload(event): |
| 480 | + match = event.pattern_match.group(1).decode("utf-8") |
| 481 | + await event.answer("Uploading..") |
| 482 | + try: |
| 483 | + await event.edit( |
| 484 | + file=f"https://www.gutenberg.org/files/{match}/{match}-pdf.pdf" |
| 485 | + ) |
| 486 | + except BaseException: |
| 487 | + book = "Ultroid-Book.epub" |
| 488 | + urllib.request.urlretrieve( |
| 489 | + "https://www.gutenberg.org/ebooks/132.epub.images", book |
| 490 | + ) |
| 491 | + fn, media, _ = await asst._file_to_media( |
| 492 | + book, thumb="resources/extras/ultroid.jpg" |
| 493 | + ) |
| 494 | + await event.edit(file=media) |
| 495 | + os.remove(book) |
0 commit comments