Prechádzať zdrojové kódy

Added global inline search

TheHamkerCat 5 rokov pred
rodič
commit
214508ce2c

+ 1 - 1
wbb/modules/filters.py

@@ -92,7 +92,7 @@ async def filters_re(_, message):
                 data_type = _filter['type']
                 data = _filter['data']
                 if data_type == "text":
-                    await message.reply_text(data)
+                    await message.reply_text(data, disable_web_page_preview=True)
                 else:
                     await message.reply_sticker(data)
                 return

+ 11 - 1
wbb/modules/inline.py

@@ -5,7 +5,7 @@ from wbb.utils.inlinefuncs import (
     saavn_func, deezer_func, inline_help_func,
     torrent_func, youtube_func, lyrics_func,
     paste_func, eval_func, github_user_func,
-    github_repo_func, calendar_func
+    github_repo_func, calendar_func, tg_search_func
 )
 from pyrogram import filters
 from pyrogram.errors.exceptions.bad_request_400 import QueryIdInvalid
@@ -189,5 +189,15 @@ async def inline_query_handler(client, query):
                 cache_time=2
             )
 
+        elif text.split()[0] == "search":
+            user_id = query.from_user.id
+            tex = text.split(None, 1)[1].strip()
+            answerss = await tg_search_func(answers, tex, user_id)
+            await client.answer_inline_query(
+                query.id,
+                results=answerss,
+                cache_time=2
+            )
+
     except (IndexError, TypeError, KeyError, ValueError, QueryIdInvalid):
         return

+ 1 - 1
wbb/modules/notes.py

@@ -69,7 +69,7 @@ async def get_one_note(_, message):
             await message.reply_text("**No such note.**")
         else:
             if _note["type"] == "text":
-                await message.reply_text(_note["data"])
+                await message.reply_text(_note["data"], disable_web_page_preview=True)
             else:
                 await message.reply_sticker(_note["data"])
 

+ 61 - 7
wbb/utils/inlinefuncs.py

@@ -18,7 +18,7 @@ from pykeyboard import InlineKeyboard
 from sys import version as pyver
 from motor import version as mongover
 from pyrogram import __version__ as pyrover
-from time import time
+from time import time, ctime
 from datetime import datetime
 import calendar
 import aiohttp
@@ -444,7 +444,7 @@ async def github_user_func(answers, text):
     buttons.add(InlineKeyboardButton(
         text="Open On Github",
         url=f"https://github.com/{text}"
-        ))
+    ))
     caption = f"""
 **Info Of {result['name']}**
 **Username:** `{text}`
@@ -477,11 +477,11 @@ async def github_repo_func(answers, text):
         commits += developer['contributions']
     buttons = InlineKeyboard(row_width=1)
     buttons.add(
-            InlineKeyboardButton(
-                'Open On Github',
-                url=f"https://github.com/{text}"
-            )
+        InlineKeyboardButton(
+            'Open On Github',
+            url=f"https://github.com/{text}"
         )
+    )
     caption = f"""
 **Info Of {r['full_name']}**
 **Stars:** `{r['stargazers_count']}`
@@ -504,7 +504,7 @@ async def github_repo_func(answers, text):
             input_message_content=InputTextMessageContent(
                 caption,
                 disable_web_page_preview=True
-                )
+            )
         ))
     return answers
 
@@ -519,3 +519,57 @@ async def calendar_func(answers):
             input_message_content=InputTextMessageContent(msg)
         ))
     return answers
+
+
+async def tg_search_func(answers, text, user_id):
+    if user_id != USERBOT_ID:
+        msg = "**ERROR**\n__THIS FEATURE IS ONLY FOR SUDO USERS__"
+        answers.append(
+            InlineQueryResultArticle(
+                title="ERROR",
+                description="THIS FEATURE IS ONLY FOR SUDO USERS",
+                input_message_content=InputTextMessageContent(msg)
+            ))
+        return answers
+    if str(text)[-1] != ":":
+        msg = "**ERROR**\n__Put A ':' After The Text To Search__"
+        answers.append(
+            InlineQueryResultArticle(
+                title="ERROR",
+                description="Put A ':' After The Text To Search",
+                input_message_content=InputTextMessageContent(msg)
+            ))
+
+        return answers
+    text = text[0:-1]
+    async for message in app2.search_global(text, limit=49):
+        buttons = InlineKeyboard(row_width=2)
+        buttons.add(
+            InlineKeyboardButton(
+                text="Origin",
+                url=message.link if message.link else "https://t.me/telegram"
+            ),
+            InlineKeyboardButton(
+                text="Search again",
+                switch_inline_query_current_chat="search"
+            )
+        )
+        caption = f"""
+**Name:** {message.from_user.mention} [`{message.from_user.id}`]
+**Chat:** {message.chat.title} [`{message.chat.id}`]
+**Date:** {ctime(message.date)}
+**Text:** >>
+
+{message.text.markdown if message.text else message.caption if message.caption else "[NO_TEXT]"}
+"""
+        result = InlineQueryResultArticle(
+            title=message.from_user.first_name,
+            description=message.text if message.text else "[NO_TEXT]",
+            reply_markup=buttons,
+            input_message_content=InputTextMessageContent(
+                caption,
+                disable_web_page_preview=True
+                )
+        )
+        answers.append(result)
+    return answers