thehamkercat 5 жил өмнө
parent
commit
9cfc4d9af9

+ 16 - 16
wbb/modules/inline.py

@@ -2,21 +2,21 @@ from wbb import app
 from wbb.utils.inlinefuncs import (
         google_search_func, urban_func, translate_func,
         alive_function, webss, shortify, wall_func,
-        saavn_func, deezer_func
+        saavn_func, deezer_func, inline_help_func
         )
 from pyrogram import filters
 
 __MODULE__ = "Inline"
 __HELP__ = """
-alive - Check Bot's Stats.
-tr [LANGUAGE_CODE] [QUERY] - Translate Text.
-ud [QUERY] - Urban Dictionary Query.
-google [Query] - Google Search.
-webss [URL] - Take Screenshot Of A Website.
-bitly [URL] - Shorten A Link.
-wall [Query] - Find Wallpapers.
-saavn [SONG_NAME] - Get Songs From Saavn.
-deezer [SONG_NAME]- Get Songs From Deezer."""
+**alive** - __Check Bot's Stats.__
+**tr [LANGUAGE_CODE] [QUERY]** - __Translate Text.__
+**ud [QUERY]** - __Urban Dictionary Query.__
+**google [Query]** - __Google Search.__
+**webss [URL]** - __Take Screenshot Of A Website.__
+**bitly [URL]** - __Shorten A Link.__
+**wall [Query]** - __Find Wallpapers.__
+**saavn [SONG_NAME]** - __Get Songs From Saavn.__
+**deezer [SONG_NAME]** - __Get Songs From Deezer.__"""
 
 
 @app.on_message(filters.command("inline"))
@@ -29,13 +29,13 @@ async def inline_query_handler(client, query):
     try:
         text = query.query.lower()
         answers = []
-        if text == '':
+        if text.strip() == '':
+            answerss = await inline_help_func(__HELP__)
             await client.answer_inline_query(
-                query.id,
-                results=answers,
-                switch_pm_text='Click here for help',
-                switch_pm_parameter='inline',
-            )
+                    query.id,
+                    results=answerss,
+                    cache_time=10
+                    )
             return
         elif text.split()[0] == "alive":
             answerss = await alive_function(answers)

+ 10 - 0
wbb/utils/formatter.py

@@ -20,3 +20,13 @@ def get_readable_time(seconds: int) -> str:
     time_list.reverse()
     ping_time += ":".join(time_list)
     return ping_time
+
+
+# Convert seconds to mm:ss
+async def convert_seconds_to_minutes(seconds: int):
+    seconds = int(seconds)
+    seconds = seconds % (24 * 3600)
+    seconds %= 3600
+    minutes = seconds // 60
+    seconds %= 60
+    return "%02d:%02d" % (minutes, seconds)

+ 85 - 14
wbb/utils/inlinefuncs.py

@@ -1,6 +1,7 @@
 from wbb import (
         arq, app, app2, USERBOT_USERNAME,
-        BOT_USERNAME, LOG_GROUP_ID)
+        BOT_USERNAME, LOG_GROUP_ID
+        )
 from pyrogram.types import (
     InlineQueryResultArticle,
     InputTextMessageContent,
@@ -11,6 +12,7 @@ from googletrans import Translator
 from search_engine_parser import GoogleSearch
 from time import time
 from wbb.utils.fetch import fetch
+from wbb.utils.formatter import convert_seconds_to_minutes as time_convert
 from pykeyboard import InlineKeyboard
 from sys import version as pyver
 import sys
@@ -20,11 +22,46 @@ import aiohttp
 import json
 
 
+async def inline_help_func(__HELP__):
+    buttons = InlineKeyboard(row_width=2)
+    buttons.add(
+            InlineKeyboardButton(
+                'Get More Help.',
+                url=f"t.me/{BOT_USERNAME}?start=start"
+            ),
+            InlineKeyboardButton(
+                "Go Inline!",
+                switch_inline_query_current_chat=""
+            )
+            )
+    answerss = [
+                InlineQueryResultArticle(
+                    title="Inline Commands",
+                    description="Help Related To Inline Usage.",
+                    input_message_content=InputTextMessageContent(__HELP__),
+                    reply_markup=buttons
+                    )
+                ]
+    answerss = await alive_function(answerss)
+    return answerss
+
+
+
 async def alive_function(answers):
-    buttons = InlineKeyboard(row_width=1)
+    buttons = InlineKeyboard(row_width=2)
     bot_state = 'Dead' if not await app.get_me() else 'Alive'
     ubot_state = 'Dead' if not await app2.get_me() else 'Alive'
-    buttons.add(InlineKeyboardButton('Stats', callback_data='stats_callback'))
+    buttons.add(
+            InlineKeyboardButton(
+                'Stats',
+                callback_data='stats_callback'
+            ),
+            InlineKeyboardButton(
+                "Go Inline!",
+                switch_inline_query_current_chat=""
+            )
+            )
+            
     msg = f"""
 **[William✨](https://github.com/thehamkercat/WilliamButcherBot):**
 **MainBot:** `{bot_state}`
@@ -126,20 +163,37 @@ async def wall_func(answers, text):
 
 
 async def saavn_func(answers, text):
+    buttons_list = []
     results = await arq.saavn(text)
     for i in results:
+        buttons = InlineKeyboard(row_width=1)
+        buttons.add(
+                InlineKeyboardButton(
+                    'Download | Play',
+                    url=results[i].media_url
+                    )
+                )
+        buttons_list.append(buttons)
+        duration = await time_convert(results[i].duration)
         caption = f"""
 **Title:** {results[i].song}
 **Album:** {results[i].album}
-**Duration:** {results[i].duration} Seconds
+**Duration:** {duration}
 **Release:** {results[i].year}
-**Singers:** {results[i].singers}
-**Link:** [Here]({results[i].media_url})"""
+**Singers:** {results[i].singers}"""
+        description = f"{results[i].album} | {duration} " \
+                       + f"| {results[i].singers} ({results[i].year})"
         try:
             answers.append(
-                InlineQueryResultPhoto(
-                    photo_url=results[i].image,
-                    caption=caption,
+                InlineQueryResultArticle(
+                    title=results[i].song,
+                    input_message_content=InputTextMessageContent(
+                        caption,
+                        disable_web_page_preview=True
+                        ),
+                    description=description,
+                    thumb_url=results[i].image,
+                    reply_markup=buttons_list[i]
                 ))
         except KeyError:
             pass
@@ -147,18 +201,35 @@ async def saavn_func(answers, text):
 
 
 async def deezer_func(answers, text):
+    buttons_list = []
     results = await arq.deezer(text, 5)
     for i in results:
+        buttons = InlineKeyboard(row_width=1)
+        buttons.add(
+                InlineKeyboardButton(
+                    'Download | Play',
+                    url=results[i].url
+                    )
+                )
+        buttons_list.append(buttons)
+        duration = await time_convert(results[i].duration)
         caption = f"""
 **Title:** {results[i].title}
-**Duration:** {results[i].duration} Seconds
 **Artist:** {results[i].artist}
-**Link:** [Here]({results[i].url})"""
+**Duration:** {duration}
+**Source:** [Deezer]({results[i].source})"""
+        description = f"{results[i].artist} | {duration}"
         try:
             answers.append(
-                InlineQueryResultPhoto(
-                    photo_url=results[i].thumbnail,
-                    caption=caption,
+                InlineQueryResultArticle(
+                    title=results[i].title,
+                    thumb_url=results[i].thumbnail,
+                    description=description,
+                    input_message_content=InputTextMessageContent(
+                        caption,
+                        disable_web_page_preview=True
+                        ),
+                    reply_markup=buttons_list[i]
                 ))
         except KeyError:
             pass