TheHamkerCat 5 سال پیش
والد
کامیت
ff52bdc4cd
3فایلهای تغییر یافته به همراه171 افزوده شده و 80 حذف شده
  1. 157 53
      wbb/core/types/InlineQueryResult.py
  2. 4 10
      wbb/modules/inline.py
  3. 10 17
      wbb/utils/inlinefuncs.py

+ 157 - 53
wbb/core/types/InlineQueryResult.py

@@ -16,116 +16,220 @@
 #  You should have received a copy of the GNU Lesser General Public License
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with Pyrogram.  If not, see <http://www.gnu.org/licenses/>.
 #  along with Pyrogram.  If not, see <http://www.gnu.org/licenses/>.
 
 
-from typing import Union
-
-from pyrogram import raw
-from pyrogram import types
+from typing import Optional, List, Union
+import pyrogram
+from pyrogram import raw, types, utils
+from pyrogram.file_id import FileType
 from pyrogram.parser import Parser
 from pyrogram.parser import Parser
 from pyrogram.types import InlineQueryResult
 from pyrogram.types import InlineQueryResult
 
 
 
 
-"https://github.com/JollyGoal/pyrogram/blob/add-inline-query-audio/pyrogram/types/inline_mode/inline_query_result_audio.py"
-
-
 class InlineQueryResultAudio(InlineQueryResult):
 class InlineQueryResultAudio(InlineQueryResult):
-    """Link to an audio file.
-    By default, this audio file will be sent by the user with optional caption.
-    Alternatively, you can use *input_message_content* to send a message with the specified content instead of the
-    audio.
+    """Link to an audio.
+    By default, this audio will be sent by the user with optional caption.
+    Alternatively, you can use *input_message_content* to send a message 
+    with the specified content instead of the audio.
     Parameters:
     Parameters:
         audio_url (``str``):
         audio_url (``str``):
-            A valid URL for the audio file.
+            A valid URL for the embedded audio player or audio file.
+
+        thumb_url (``str``):
+            URL of the thumbnail (jpeg only) for the audio.
+
         title (``str``):
         title (``str``):
             Title for the result.
             Title for the result.
-        duration (``int``, *optional*):
-            Duration of the audio in second.
-        voice (``bool``, *optional*):
-            Whether this file should be sent as voice message (default=False).
-        performer (``str``, *optional*):
-            Audio artist.
-        thumb_url (``str``, *optional*):
-            URL of the static thumbnail for the result (jpeg or gif)
-            Defaults to the value passed in *animation_url*.
+
+        mime_type (``str``):
+            Mime type of the content of audio url, “text/html” or “audio/mp3”.
+        
         id (``str``, *optional*):
         id (``str``, *optional*):
             Unique identifier for this result, 1-64 bytes.
             Unique identifier for this result, 1-64 bytes.
             Defaults to a randomly generated UUID4.
             Defaults to a randomly generated UUID4.
+
+        voice (``bool``, *optional*):
+            True if the audio is a voice note, defaults to False.
+
         description (``str``, *optional*):
         description (``str``, *optional*):
             Short description of the result.
             Short description of the result.
+
         caption (``str``, *optional*):
         caption (``str``, *optional*):
-            Caption of the photo to be sent, 0-1024 characters.
+            Caption of the audio to be sent, 0-1024 characters.
+
+        performer (``str``, *optional*):
+            Performer.
+
+        duration (``int``, *optional*):
+            Audio duration in seconds.
+
         parse_mode (``str``, *optional*):
         parse_mode (``str``, *optional*):
             By default, texts are parsed using both Markdown and HTML styles.
             By default, texts are parsed using both Markdown and HTML styles.
             You can combine both syntaxes together.
             You can combine both syntaxes together.
             Pass "markdown" or "md" to enable Markdown-style parsing only.
             Pass "markdown" or "md" to enable Markdown-style parsing only.
             Pass "html" to enable HTML-style parsing only.
             Pass "html" to enable HTML-style parsing only.
             Pass None to completely disable style parsing.
             Pass None to completely disable style parsing.
+
+        caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
+            List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
+        
         reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*):
         reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*):
             An InlineKeyboardMarkup object.
             An InlineKeyboardMarkup object.
+        
         input_message_content (:obj:`~pyrogram.types.InputMessageContent`):
         input_message_content (:obj:`~pyrogram.types.InputMessageContent`):
-            Content of the message to be sent instead of the photo.
+            Content of the message to be sent instead of the audio. This field is required if InlineQueryResultAudio is
+            used to send an HTML-page as a result.
     """
     """
 
 
     def __init__(
     def __init__(
-            self,
-            audio_url: str,
-            title: str,
-            duration: int = 0,
-            voice: bool = False,
-            performer: str = "",
-            thumb_url: str = None,
-            id: str = None,
-            description: str = None,
-            caption: str = "",
-            parse_mode: Union[str, None] = object,
-            reply_markup: "types.InlineKeyboardMarkup" = None,
-            input_message_content: "types.InputMessageContent" = None
+        self,
+        audio_url: str,
+        thumb_url: str,
+        title: str,
+        mime_type: str,
+        id: str = None,
+        voice: bool = False,
+        description: str = None,
+        caption: str = "",
+        performer: str = "",
+        duration: int = 0,
+        parse_mode: Optional[str] = object,
+        caption_entities: List["types.MessageEntity"] = None,
+        reply_markup: "types.InlineKeyboardMarkup" = None,
+        input_message_content: "types.InputMessageContent" = None
     ):
     ):
         super().__init__("audio", id, input_message_content, reply_markup)
         super().__init__("audio", id, input_message_content, reply_markup)
 
 
         self.audio_url = audio_url
         self.audio_url = audio_url
         self.thumb_url = thumb_url
         self.thumb_url = thumb_url
+        self.voice = voice
         self.title = title
         self.title = title
-        self.description = description
         self.caption = caption
         self.caption = caption
+        self.description = description
+        self.mime_type = mime_type
         self.parse_mode = parse_mode
         self.parse_mode = parse_mode
+        self.performer = performer
+        self.duration = duration
+        self.caption_entities = caption_entities
         self.reply_markup = reply_markup
         self.reply_markup = reply_markup
         self.input_message_content = input_message_content
         self.input_message_content = input_message_content
-        self.duration = duration
-        self.voice = voice
-        self.performer = performer
+        
+        if mime_type == "text/html" and input_message_content is None:
+            raise ValueError("input_message_content is required for audio with `text/html` mime type")
 
 
-    async def write(self):
+
+    async def write(self, client: "pyrogram.Client"):
         audio = raw.types.InputWebDocument(
         audio = raw.types.InputWebDocument(
             url=self.audio_url,
             url=self.audio_url,
             size=0,
             size=0,
-            mime_type="audio/ogg",
+            mime_type=self.mime_type,
+            attributes=[]
+        )
+
+        thumb = raw.types.InputWebDocument(
+            url=self.thumb_url,
+            size=0,
+            mime_type="image/jpeg",
             attributes=[raw.types.DocumentAttributeAudio(
             attributes=[raw.types.DocumentAttributeAudio(
                 duration=self.duration,
                 duration=self.duration,
                 voice=self.voice,
                 voice=self.voice,
                 title=self.title,
                 title=self.title,
                 performer=self.performer,
                 performer=self.performer,
-                # waveform=idk wtf is that...
-            )],
+            )]
         )
         )
 
 
+        message, entities = (await utils.parse_text_entities(
+            client, self.caption, self.parse_mode, self.caption_entities
+        )).values()
+
         return raw.types.InputBotInlineResult(
         return raw.types.InputBotInlineResult(
             id=self.id,
             id=self.id,
             type=self.type,
             type=self.type,
             title=self.title,
             title=self.title,
             description=self.description,
             description=self.description,
-            thumb=raw.types.InputWebDocument(
-                url=self.thumb_url,
-                size=0,
-                mime_type="image/jpeg",
-                attributes=[]
-            ) if self.thumb_url else None,
+            thumb=thumb,
             content=audio,
             content=audio,
             send_message=(
             send_message=(
-                self.input_message_content.write(self.reply_markup)
+                await self.input_message_content.write(client, self.reply_markup)
+                if self.input_message_content
+                else raw.types.InputBotInlineMessageMediaAuto(
+                    reply_markup=await self.reply_markup.write(client) if self.reply_markup else None,
+                    message=message,
+                    entities=entities)
+            )
+        )
+
+
+class InlineQueryResultCachedAudio(InlineQueryResult):
+    """Represents a link to an MP3 audio file stored on the Telegram servers.
+
+    By default, this audio file will be sent by the user.
+    Alternatively, you can use input_message_content to send a message with the specified content instead of the audio.    
+    
+    Parameters:
+        file_id (``str``):
+            A valid file identifier for the audio file
+            
+        id (``str``, *optional*):
+            Unique identifier for this result, 1-64 bytes.
+            Defaults to a randomly generated UUID4.
+            
+        caption (``str``, *optional*):
+            Caption, 0-1024 characters after entities parsing.
+
+        parse_mode (``str``, *optional*):
+            By default, texts are parsed using both Markdown and HTML styles.
+            You can combine both syntaxes together.
+            Pass "markdown" or "md" to enable Markdown-style parsing only.
+            Pass "html" to enable HTML-style parsing only.
+            Pass None to completely disable style parsing.
+
+        caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
+                List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
+            
+        reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*):
+            Inline keyboard attached to the message.
+            
+        input_message_content (:obj:`~pyrogram.types.InputMessageContent`):
+            Content of the message to be sent.
+    """
+
+    def __init__(
+        self,
+        file_id: str,
+        id: str = None,
+        caption: str = "",
+        parse_mode: Optional[str] = object,
+        caption_entities: List["types.MessageEntity"] = None,
+        reply_markup: "types.InlineKeyboardMarkup" = None,
+        input_message_content: "types.InputMessageContent" = None
+    ):
+        super().__init__("audio", id, input_message_content, reply_markup)
+
+        self.file_id = file_id
+        self.caption = caption
+        self.parse_mode = parse_mode
+        self.caption_entities = caption_entities
+        self.reply_markup = reply_markup
+        self.input_message_content = input_message_content
+
+
+    async def write(self, client: "pyrogram.Client"):
+        audio = utils.get_input_media_from_file_id(self.file_id, FileType.AUDIO)
+
+        message, entities = (await utils.parse_text_entities(
+            client, self.caption, self.parse_mode, self.caption_entities
+        )).values()
+        print(audio)
+        return raw.types.InputBotInlineResultDocument(
+            id=self.id,
+            type=self.type,
+            document=audio,
+            send_message=(
+                await self.input_message_content.write(client, self.reply_markup)
                 if self.input_message_content
                 if self.input_message_content
                 else raw.types.InputBotInlineMessageMediaAuto(
                 else raw.types.InputBotInlineMessageMediaAuto(
-                    reply_markup=self.reply_markup.write() if self.reply_markup else None,
-                    **await(Parser(None)).parse(self.caption, self.parse_mode)
+                    reply_markup=await self.reply_markup.write(client) if self.reply_markup else None,
+                    message=message,
+                    entities=entities
                 )
                 )
             )
             )
         )
         )

+ 4 - 10
wbb/modules/inline.py

@@ -1,12 +1,5 @@
 from wbb import app
 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, inline_help_func,
-    torrent_func, youtube_func, lyrics_func,
-    eval_func, github_user_func, github_repo_func,
-    tg_search_func, deezaudio_func
-)
+from wbb.utils.inlinefuncs import *
 from pyrogram import filters
 from pyrogram import filters
 from pyrogram.errors.exceptions.bad_request_400 import QueryIdInvalid
 from pyrogram.errors.exceptions.bad_request_400 import QueryIdInvalid
 
 
@@ -302,12 +295,13 @@ async def inline_query_handler(client, query):
             )
             )
 
 
         elif text.split()[0] == "audio":
         elif text.split()[0] == "audio":
-            answerss = await deezaudio_func(answers)
+            answerss = await cached_audio_test_func(answers)
             await client.answer_inline_query(
             await client.answer_inline_query(
                 query.id,
                 query.id,
                 results=answerss,
                 results=answerss,
                 cache_time=2
                 cache_time=2
             )
             )
 
 
-    except (IndexError, TypeError, KeyError, ValueError, QueryIdInvalid):
+    except (IndexError, TypeError, KeyError, ValueError, QueryIdInvalid) as e:
+        print(e + "InLine")
         return
         return

+ 10 - 17
wbb/utils/inlinefuncs.py

@@ -23,23 +23,7 @@ from wbb import (
     arq, app, app2, USERBOT_USERNAME,
     arq, app, app2, USERBOT_USERNAME,
     BOT_USERNAME, LOG_GROUP_ID, USERBOT_ID
     BOT_USERNAME, LOG_GROUP_ID, USERBOT_ID
 )
 )
-from wbb.core.types.InlineQueryResult import InlineQueryResultAudio
-
-
-async def deezaudio_func(answers):
-    msg = "a"
-    answers.append(
-        InlineQueryResultAudio(
-            audio_url="https://masstamilan2019download.com/tamil/2019%20Tamil%20Mp3/Oh%20My%20Kadavule/Kadhaippoma-Masstamilan.In.mp3",
-            title="a",
-            description="desc",
-            input_message_content=InputTextMessageContent(msg)
-        )
-    )
-    return answers
-
-
-
+from wbb.core.types.InlineQueryResult import InlineQueryResultAudio, InlineQueryResultCachedAudio
 
 
 
 
 async def inline_help_func(__HELP__):
 async def inline_help_func(__HELP__):
@@ -579,3 +563,12 @@ async def tg_search_func(answers, text, user_id):
         )
         )
         answers.append(result)
         answers.append(result)
     return answers
     return answers
+
+
+async def cached_audio_test_func(answers):
+    answers.append(
+        InlineQueryResultCachedAudio(
+            file_id="CQACAgUAAx0EWIlO9AABA5N3YH0yxW2M9qTAMATvsj2-hkXv7NUAAn4CAAL2U-hXv1yOjFTFTiweBA"
+        )
+    )
+    return answers