فهرست منبع

Added Lyrics Command & Inline

TheHamkerCat 5 سال پیش
والد
کامیت
844df5dc06
3فایلهای تغییر یافته به همراه53 افزوده شده و 8 حذف شده
  1. 11 6
      wbb/modules/inline.py
  2. 20 2
      wbb/modules/music.py
  3. 22 0
      wbb/utils/inlinefuncs.py

+ 11 - 6
wbb/modules/inline.py

@@ -3,7 +3,7 @@ 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
+    torrent_func, youtube_func, lyrics_func
 )
 from pyrogram import filters
 
@@ -19,7 +19,8 @@ __HELP__ = """
 **saavn [SONG_NAME]** - __Get Songs From Saavn.__
 **deezer [SONG_NAME]** - __Get Songs From Deezer.__
 **yt [Query]** - __Youtube Search.__
-**torrent [QUERY]** - __Torrent Search.__"""
+**torrent [QUERY]** - __Torrent Search.__
+**lyrics [Query]** - __Lyrics Search.__"""
 
 
 @app.on_message(filters.command("inline"))
@@ -54,7 +55,6 @@ async def inline_query_handler(client, query):
             await client.answer_inline_query(
                 query.id,
                 results=answerss,
-                cache_time=10
             )
         elif text.split()[0] == "ud":
             tex = text.split(None, 1)[1]
@@ -62,7 +62,6 @@ async def inline_query_handler(client, query):
             await client.answer_inline_query(
                 query.id,
                 results=answerss,
-                cache_time=10
             )
         elif text.split()[0] == "google":
             tex = text.split(None, 1)[1]
@@ -70,7 +69,6 @@ async def inline_query_handler(client, query):
             await client.answer_inline_query(
                 query.id,
                 results=answerss,
-                cache_time=10
             )
         elif text.split()[0] == "webss":
             tex = text.split(None, 1)[1]
@@ -119,7 +117,6 @@ async def inline_query_handler(client, query):
             await client.answer_inline_query(
                 query.id,
                 results=answerss,
-                cache_time=10
             )
 
         elif text.split()[0] == "yt":
@@ -130,5 +127,13 @@ async def inline_query_handler(client, query):
                 results=answerss
             )
 
+        elif text.split()[0] == "lyrics":
+            tex = text.split(None, 1)[1]
+            answerss = await lyrics_func(answers, tex)
+            await client.answer_inline_query(
+                query.id,
+                results=answerss
+            )
+
     except (IndexError, TypeError, KeyError, ValueError):
         return

+ 20 - 2
wbb/modules/music.py

@@ -8,12 +8,13 @@ from random import randint
 from pyrogram import filters
 from wbb import app, SUDOERS, arq, MAIN_CHATS
 from wbb.utils.errors import capture_err
-
+from wbb.utils.pastebin import paste
 
 __MODULE__ = "Music"
 __HELP__ = """/ytmusic [link] To Download Music From Various Websites Including Youtube.
 /saavn [query] To Download Music From Saavn.
-/deezer [query] To Download Music From Deezer."""
+/deezer [query] To Download Music From Deezer.
+/lyrics [query] To Get Lyrics Of A Song."""
 
 ydl_opts = {
     'format': 'bestaudio/best',
@@ -150,3 +151,20 @@ async def deezsong(_, message):
         await m.edit(str(e))
         return
     is_downloading = False
+
+# Lyrics
+
+
+@app.on_message(filters.command("lyrics"))
+async def lyrics_func(_, message):
+    if len(message.command) < 2:
+        await message.reply_text("**Usage:**\n/lyrics [QUERY]")
+        return
+    query = message.text.strip().split(None ,1)[1]
+    song = await arq.lyrics(query)
+    lyrics = song.lyrics
+    if len(lyrics) < 4095:
+        await message.reply_text(f"__{lyrics}__")
+        return
+    lyrics = await paste(lyrics)
+    await message.reply_text(f"**LYRICS_TOO_LONG:** [URL]({lyrics})")

+ 22 - 0
wbb/utils/inlinefuncs.py

@@ -13,6 +13,7 @@ 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 wbb.utils.pastebin import paste
 from pykeyboard import InlineKeyboard
 from sys import version as pyver
 import sys
@@ -359,3 +360,24 @@ async def youtube_func(answers, text):
         except (KeyError, ValueError):
             pass
     return answers
+
+
+async def lyrics_func(answers, text):
+    song = await arq.lyrics(text)
+    lyrics = song.lyrics
+    song = lyrics.splitlines()
+    song_name = song[0]
+    artist = song[1]
+    if len(lyrics) > 4095:
+        lyrics = await paste(lyrics)
+        lyrics = f"**LYRICS_TOO_LONG:** [URL]({lyrics})"
+
+    msg = f"__{lyrics}__"
+
+    answers.append(
+        InlineQueryResultArticle(
+            title=song_name,
+            description=artist,
+            input_message_content=InputTextMessageContent(msg)
+        ))
+    return answers