Просмотр исходного кода

Added image search & removed useless inline stuff

thehamkercat 5 лет назад
Родитель
Сommit
795c02ab7a

+ 1 - 1
wbb/__main__.py

@@ -29,7 +29,7 @@ import uvloop
 from pyrogram import filters, idle
 from pyrogram import filters, idle
 from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup
 from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup
 
 
-from wbb import BOT_NAME, BOT_USERNAME, USERBOT_NAME, aiohttpsession, app, app2
+from wbb import BOT_NAME, BOT_USERNAME, USERBOT_NAME, aiohttpsession, app
 from wbb.modules import ALL_MODULES
 from wbb.modules import ALL_MODULES
 from wbb.modules.sudoers import bot_sys_stats
 from wbb.modules.sudoers import bot_sys_stats
 from wbb.utils import paginate_modules
 from wbb.utils import paginate_modules

+ 1 - 3
wbb/core/decorators/misc.py

@@ -12,8 +12,6 @@ def exec_time(func):
             t2 = time()
             t2 = time()
             total = t2 - t1
             total = t2 - t1
             total = round(total, 3)
             total = round(total, 3)
-            print(
-                f"{func.__name__} Took: {total} Seconds"
-            )
+            print(f"{func.__name__} Took: {total} Seconds")
 
 
     return _time_it
     return _time_it

+ 0 - 2
wbb/modules/chat_watcher.py

@@ -21,8 +21,6 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 SOFTWARE.
 SOFTWARE.
 """
 """
-from pyrogram import filters
-
 from wbb import app
 from wbb import app
 from wbb.utils.dbfunctions import (add_served_chat, add_served_user,
 from wbb.utils.dbfunctions import (add_served_chat, add_served_user,
                                    blacklisted_chats, is_served_chat,
                                    blacklisted_chats, is_served_chat,

+ 8 - 74
wbb/modules/inline.py

@@ -116,31 +116,7 @@ async def inline_query_handler(client, query):
                 )
                 )
             tex = text.split(None, 1)[1].strip()
             tex = text.split(None, 1)[1].strip()
             answerss = await wall_func(answers, tex)
             answerss = await wall_func(answers, tex)
-            await client.answer_inline_query(query.id, results=answerss)
-
-        elif text.split()[0] == "saavn":
-            if len(text.split()) < 2:
-                return await client.answer_inline_query(
-                    query.id,
-                    results=answers,
-                    switch_pm_text="JioSaavn Search | saavn [QUERY]",
-                    switch_pm_parameter="inline",
-                )
-            tex = text.split(None, 1)[1].strip()
-            answerss = await saavn_func(answers, tex)
-            await client.answer_inline_query(query.id, results=answerss)
-
-        elif text.split()[0] == "deezer":
-            if len(text.split()) < 2:
-                return await client.answer_inline_query(
-                    query.id,
-                    results=answers,
-                    switch_pm_text="Deezer Search | deezer [QUERY]",
-                    switch_pm_parameter="inline",
-                )
-            tex = text.split(None, 1)[1].strip()
-            answerss = await deezer_func(answers, tex)
-            await client.answer_inline_query(query.id, results=answerss)
+            await client.answer_inline_query(query.id, results=answerss, cache_time=2)
 
 
         elif text.split()[0] == "torrent":
         elif text.split()[0] == "torrent":
             if len(text.split()) < 2:
             if len(text.split()) < 2:
@@ -258,34 +234,6 @@ async def inline_query_handler(client, query):
                 query.id, results=answerss, cache_time=2
                 query.id, results=answerss, cache_time=2
             )
             )
 
 
-        elif text.split()[0] == "paste":
-            if len(text.split()) < 2:
-                return await client.answer_inline_query(
-                    query.id,
-                    results=answers,
-                    switch_pm_text="Pastebin | paste [TG_MESSAGE_LINK]",
-                    switch_pm_parameter="inline",
-                )
-            link = text.strip().split()[1]
-            answerss = await pastebin_func(answers, link)
-            await client.answer_inline_query(
-                query.id, results=answerss, cache_time=2
-            )
-
-        elif text.split()[0] == "carbon":
-            if len(text.split()) < 2:
-                return await client.answer_inline_query(
-                    query.id,
-                    results=answers,
-                    switch_pm_text="Carbon | carbon [TG_MESSAGE_LINK]",
-                    switch_pm_parameter="inline",
-                )
-            link = text.split()[1]
-            answerss = await carbon_inline_func(answers, link)
-            await client.answer_inline_query(
-                query.id, results=answerss, cache_time=2
-            )
-
         elif text.split()[0] == "pmpermit":
         elif text.split()[0] == "pmpermit":
             user_id = query.from_user.id
             user_id = query.from_user.id
             victim = text.split()[1]
             victim = text.split()[1]
@@ -300,20 +248,6 @@ async def inline_query_handler(client, query):
                 query.id, results=answerss, cache_time=2
                 query.id, results=answerss, cache_time=2
             )
             )
 
 
-        elif text.split()[0] == "nsfw_scan":
-            if len(text.split()) < 2:
-                return await client.answer_inline_query(
-                    query.id,
-                    results=answers,
-                    switch_pm_text="NSFW Scan | nsfw_scan [url]",
-                    switch_pm_parameter="inline",
-                )
-            tex = text.split(None, 1)[1].strip()
-            answerss = await nsfw_scan_func(answers, tex)
-            await client.answer_inline_query(
-                query.id, results=answerss, cache_time=2
-            )
-
         elif text.split()[0] == "ytmusic":
         elif text.split()[0] == "ytmusic":
             if len(text.split()) < 2:
             if len(text.split()) < 2:
                 return await client.answer_inline_query(
                 return await client.answer_inline_query(
@@ -385,19 +319,19 @@ async def inline_query_handler(client, query):
                 query.id, results=answerss, cache_time=2
                 query.id, results=answerss, cache_time=2
             )
             )
 
 
-        elif text.split()[0] == "audio":
+        elif text.split()[0] == "image":
             if len(text.split()) < 2:
             if len(text.split()) < 2:
                 return await client.answer_inline_query(
                 return await client.answer_inline_query(
                     query.id,
                     query.id,
                     results=answers,
                     results=answers,
-                    switch_pm_text="Random Audio Search | audio [Query]",
+                    is_gallery=True,
+                    switch_pm_text="Image Search | image [QUERY]",
                     switch_pm_parameter="inline",
                     switch_pm_parameter="inline",
                 )
                 )
-            tex = text.split()[1].strip()
-            answerss = await randomAudioFunc(answers, tex)
-            await client.answer_inline_query(
-                query.id, results=answerss, cache_time=2
-            )
+            tex = text.split(None, 1)[1].strip()
+            answerss = await image_func(answers, tex)
+            await client.answer_inline_query(query.id, results=answerss, cache_time=3600)
+
     except Exception as e:
     except Exception as e:
         e = traceback.format_exc()
         e = traceback.format_exc()
         print(e, " InLine")
         print(e, " InLine")

+ 1 - 3
wbb/modules/karma.py

@@ -42,9 +42,7 @@ Reply to a message with /karma to check a user's karma
 Send /karma without replying to any message to chek karma list of top 10 users"""
 Send /karma without replying to any message to chek karma list of top 10 users"""
 
 
 
 
-regex_upvote = (
-    r"^(\+|\+\+|\+1|thx|tnx|ty|thank you|thanx|thanks|pro|cool|good|👍|\+\+ .+)$"
-)
+regex_upvote = r"^(\+|\+\+|\+1|thx|tnx|ty|thank you|thanx|thanks|pro|cool|good|👍|\+\+ .+)$"
 regex_downvote = r"^(-|--|-1|👎|-- .+)$"
 regex_downvote = r"^(-|--|-1|👎|-- .+)$"
 
 
 
 

+ 0 - 8
wbb/modules/pipes.py

@@ -86,14 +86,6 @@ async def pipes_worker_bot(_, message: Message):
             await message.forward(pipe["to_chat_id"])
             await message.forward(pipe["to_chat_id"])
 
 
 
 
-@app2.on_message(~filters.me, group=pipes_group)
-@capture_err
-async def pipes_worker_userbot(_, message: Message):
-    for pipe in pipes_list_userbot:
-        if pipe["from_chat_id"] == message.chat.id:
-            await message.forward(pipe["to_chat_id"])
-
-
 @app2.on_message(~filters.me, group=pipes_group)
 @app2.on_message(~filters.me, group=pipes_group)
 @capture_err
 @capture_err
 async def pipes_worker_userbot(_, message: Message):
 async def pipes_worker_userbot(_, message: Message):

+ 2 - 1
wbb/modules/userbot.py

@@ -13,7 +13,6 @@ import traceback
 from html import escape
 from html import escape
 from inspect import getfullargspec
 from inspect import getfullargspec
 from io import StringIO
 from io import StringIO
-from time import time
 
 
 import aiofiles
 import aiofiles
 from pyrogram import filters
 from pyrogram import filters
@@ -36,6 +35,8 @@ __HELP__ = """
 m = None
 m = None
 p = print
 p = print
 r = None
 r = None
+exec_time = exec_time
+arq = arq
 
 
 
 
 async def aexec(code, client, message):
 async def aexec(code, client, message):

+ 23 - 220
wbb/utils/inlinefuncs.py

@@ -29,7 +29,6 @@ from random import randint
 from sys import version as pyver
 from sys import version as pyver
 from time import ctime, time
 from time import ctime, time
 
 
-import aiofiles
 from motor import version as mongover
 from motor import version as mongover
 from pykeyboard import InlineKeyboard
 from pykeyboard import InlineKeyboard
 from pyrogram import __version__ as pyrover
 from pyrogram import __version__ as pyrover
@@ -42,14 +41,11 @@ from search_engine_parser import GoogleSearch
 from wbb import (BOT_USERNAME, MESSAGE_DUMP_CHAT, SUDOERS, USERBOT_ID,
 from wbb import (BOT_USERNAME, MESSAGE_DUMP_CHAT, SUDOERS, USERBOT_ID,
                  USERBOT_NAME, USERBOT_USERNAME, aiohttpsession, app, app2,
                  USERBOT_NAME, USERBOT_USERNAME, aiohttpsession, app, app2,
                  arq)
                  arq)
-from wbb.core.types import (InlineQueryResultAudio,
-                            InlineQueryResultCachedDocument)
+from wbb.core.types import InlineQueryResultCachedDocument
 from wbb.modules.info import get_chat_info, get_user_info
 from wbb.modules.info import get_chat_info, get_user_info
 from wbb.modules.music import download_youtube_audio
 from wbb.modules.music import download_youtube_audio
-from wbb.modules.paste import isPreviewUp
 from wbb.utils.fetch import fetch
 from wbb.utils.fetch import fetch
-from wbb.utils.formatter import convert_seconds_to_minutes as time_convert
-from wbb.utils.functions import make_carbon, test_speedtest
+from wbb.utils.functions import test_speedtest
 from wbb.utils.pastebin import paste
 from wbb.utils.pastebin import paste
 
 
 keywords_list = [
 keywords_list = [
@@ -66,19 +62,15 @@ keywords_list = [
     "wiki",
     "wiki",
     "speedtest",
     "speedtest",
     "music",
     "music",
-    "saavn",
-    "deezer",
     "gh_repo",
     "gh_repo",
     "gh_user",
     "gh_user",
     "search",
     "search",
-    "paste",
-    "nsfw_scan",
     "ytmusic",
     "ytmusic",
-    "carbon",
     "info",
     "info",
     "chat_info",
     "chat_info",
     "tmdb",
     "tmdb",
     "pypi",
     "pypi",
+    "image",
 ]
 ]
 
 
 
 
@@ -266,84 +258,7 @@ async def wall_func(answers, text):
     return answers
     return answers
 
 
 
 
-async def saavn_func(answers, text):
-    buttons_list = []
-    results = await arq.saavn(text)
-    if not results.ok:
-        answers.append(
-            InlineQueryResultArticle(
-                title="Error",
-                description=results.result,
-                input_message_content=InputTextMessageContent(results.result),
-            )
-        )
-        return answers
-    results = results.result
-    for count, i in enumerate(results):
-        buttons = InlineKeyboard(row_width=1)
-        buttons.add(InlineKeyboardButton("Download | Play", url=i.media_url))
-        buttons_list.append(buttons)
-        duration = await time_convert(i.duration)
-        caption = f"""
-**Title:** {i.song}
-**Album:** {i.album}
-**Duration:** {duration}
-**Release:** {i.year}
-**Singers:** {i.singers}"""
-        description = f"{i.album} | {duration} " + f"| {i.singers} ({i.year})"
-        answers.append(
-            InlineQueryResultArticle(
-                title=i.song,
-                input_message_content=InputTextMessageContent(
-                    caption, disable_web_page_preview=True
-                ),
-                description=description,
-                thumb_url=i.image,
-                reply_markup=buttons_list[count],
-            )
-        )
-    return answers
-
-
-async def deezer_func(answers, text):
-    buttons_list = []
-    results = await arq.deezer(text, 5)
-    if not results.ok:
-        answers.append(
-            InlineQueryResultArticle(
-                title="Error",
-                description=results.result,
-                input_message_content=InputTextMessageContent(results.result),
-            )
-        )
-        return answers
-    results = results.result
-    for count, i in enumerate(results):
-        buttons = InlineKeyboard(row_width=1)
-        buttons.add(InlineKeyboardButton("Download | Play", url=i.url))
-        buttons_list.append(buttons)
-        duration = await time_convert(i.duration)
-        caption = f"""
-**Title:** {i.title}
-**Artist:** {i.artist}
-**Duration:** {duration}
-**Source:** [Deezer]({i.source})"""
-        description = f"{i.artist} | {duration}"
-        answers.append(
-            InlineQueryResultArticle(
-                title=i.title,
-                thumb_url=i.thumbnail,
-                description=description,
-                input_message_content=InputTextMessageContent(
-                    caption, disable_web_page_preview=True
-                ),
-                reply_markup=buttons_list[count],
-            )
-        )
-    return answers
-
-
-# Used my api key here, don't fuck with it
+# Used my api key here, don't fuck it
 async def shortify(url):
 async def shortify(url):
     if "." not in url:
     if "." not in url:
         return
         return
@@ -746,46 +661,6 @@ async def test_speedtest_cq(_, cq):
     await app.edit_inline_text(inline_message_id, msg)
     await app.edit_inline_text(inline_message_id, msg)
 
 
 
 
-async def pastebin_func(answers, link):
-    link = link.split("/")
-    if link[3] == "c":
-        chat, message_id = int("-100" + link[4]), int(link[5])
-    else:
-        chat, message_id = link[3], link[4]
-    m = await app.get_messages(chat, message_ids=int(message_id))
-    if not m.text and not m.document:
-        m = await app2.get_messages(chat, message_ids=int(message_id))
-    if m.text:
-        content = m.text
-    else:
-        if m.document.file_size > 1048576:
-            answers.append(
-                InlineQueryResultArticle(
-                    title="DOCUMENT TOO BIG",
-                    description="Maximum supported size is 1MB",
-                    input_message_content=InputTextMessageContent(
-                        "DOCUMENT TOO BIG"
-                    ),
-                )
-            )
-            return answers
-        doc = await m.download()
-        async with aiofiles.open(doc, mode="r") as f:
-            content = await f.read()
-        os.remove(doc)
-    link = await paste(content)
-    preview = link + "/preview.png"
-    if not await isPreviewUp(preview):
-        return []
-    await app.send_photo(MESSAGE_DUMP_CHAT, preview)  # To Pre-cache the media
-    buttons = InlineKeyboard(row_width=1)
-    buttons.add(InlineKeyboardButton(text="Paste Link", url=link))
-    answers.append(
-        InlineQueryResultPhoto(photo_url=preview, reply_markup=buttons)
-    )
-    return answers
-
-
 async def pmpermit_func(answers, user_id, victim):
 async def pmpermit_func(answers, user_id, victim):
     if user_id != USERBOT_ID:
     if user_id != USERBOT_ID:
         return
         return
@@ -830,40 +705,6 @@ async def ping_func(answers):
     return answers
     return answers
 
 
 
 
-async def nsfw_scan_func(answers, url: str):
-    t1 = time()
-    data = await arq.nsfw_scan(url)
-    if not data.ok:
-        answers.append(
-            InlineQueryResultArticle(
-                title="Error",
-                description=data.result,
-                input_message_content=InputTextMessageContent(data.result),
-            )
-        )
-        return answers
-    t2 = time()
-    tt = round(t2 - t1, 4)
-    data = data.result
-    content = f"""
-**Scanned [Image]({url}) In {tt} Seconds.**
-
-**Drawings:** `{data.drawings} %`
-**Neutral:** `{data.neutral} %`
-**Hentai:** `{data.hentai} %`
-**Porn:** `{data.porn} %`
-**Sexy:** `{data.sexy} %`
-    """
-    answers.append(
-        InlineQueryResultArticle(
-            title="Scanned",
-            description=f"Took {tt} Seconds.",
-            input_message_content=InputTextMessageContent(content),
-        )
-    )
-    return answers
-
-
 async def yt_music_func(answers, url):
 async def yt_music_func(answers, url):
     if "http" not in url:
     if "http" not in url:
         url = (await arq.youtube(url)).result[0]
         url = (await arq.youtube(url)).result[0]
@@ -903,50 +744,6 @@ async def yt_music_func(answers, url):
     return answers
     return answers
 
 
 
 
-async def carbon_inline_func(answers, link):
-    link = link.split("/")
-    if link[3] == "c":
-        chat, message_id = int("-100" + link[4]), int(link[5])
-    else:
-        chat, message_id = link[3], link[4]
-    m = await app.get_messages(chat, message_ids=int(message_id))
-    if not m.text and not m.document:
-        m = await app2.get_messages(chat, message_ids=int(message_id))
-    if m.text:
-        content = m.text
-    else:
-        if m.document.file_size > 1048576:
-            answers.append(
-                InlineQueryResultArticle(
-                    title="DOCUMENT TOO BIG",
-                    description="Maximum supported size is 1MB",
-                    input_message_content=InputTextMessageContent(
-                        "DOCUMENT TOO BIG"
-                    ),
-                )
-            )
-            return answers
-        doc = await m.download()
-        async with aiofiles.open(doc, mode="r") as f:
-            content = await f.read()
-        os.remove(doc)
-    image = await make_carbon(content)
-    link = await paste(content)
-    # To Pre-cache the media
-    carbon = await app.send_document(MESSAGE_DUMP_CHAT, image)
-    os.remove(image)
-    buttons = InlineKeyboard(row_width=1)
-    buttons.add(InlineKeyboardButton(text="Paste Link", url=link))
-    answers.append(
-        InlineQueryResultCachedDocument(
-            file_id=carbon.document.file_id,
-            title="Carbon",
-            reply_markup=buttons,
-        )
-    )
-    return answers
-
-
 async def user_info_inline_func(answers, user):
 async def user_info_inline_func(answers, user):
     caption, photo_id = await get_user_info(user)
     caption, photo_id = await get_user_info(user)
     answers.append(
     answers.append(
@@ -1075,18 +872,24 @@ async def pypiSearchFunc(answers: list, query: str) -> list:
     return answers
     return answers
 
 
 
 
-async def randomAudioFunc(answers: list, query: str) -> list:
-    url = f"https://www.zedge.net/api-zedge-web/browse/search?query={query}&contentType=ringtones"
-    async with aiohttpsession.get(url) as resp:
-        data = await resp.json()
-    items = data["items"]
-    answers = [
-        InlineQueryResultAudio(
-            audio_url=audio["audioUrl"],
-            thumb_url="https://tweety.drk1.workers.dev/0:/image_2021-05-22_20-56-47.png",
-            title=audio["title"],
-            mime_type="audio/mp3",
+async def image_func(answers, query):
+    results = await arq.image(query)
+    if not results.ok:
+        answers.append(
+            InlineQueryResultArticle(
+                title="Error",
+                description=results.result,
+                input_message_content=InputTextMessageContent(results.result),
+            )
+        )
+        return answers
+    results = results.result[0:48]
+    for i in results:
+        answers.append(
+            InlineQueryResultPhoto(
+                title=i.title,
+                photo_url=i.url,
+                thumb_url=i.url,
+            )
         )
         )
-        for audio in items
-    ]
     return answers
     return answers