TheHamkerCat преди 5 години
родител
ревизия
8ebf980a43
променени са 3 файла, в които са добавени 55 реда и са изтрити 20 реда
  1. 1 1
      app.json
  2. 14 0
      wbb/modules/inline.py
  3. 40 19
      wbb/utils/inlinefuncs.py

+ 1 - 1
app.json

@@ -72,7 +72,7 @@
             "required": true
         },
         "ARQ_API_KEY": {
-            "description": "Get this from @ARQRoboto.",
+            "description": "Get this from @ARQRobot.",
             "required": true
         }
     }

+ 14 - 0
wbb/modules/inline.py

@@ -347,6 +347,20 @@ async def inline_query_handler(client, query):
             tex = text.split()[1].strip()
             answerss = await chat_info_inline_func(answers, tex)
             await client.answer_inline_query(query.id, results=answerss, cache_time=2)
+
+        elif text.split()[0] == "tmdb":
+            if len(text.split()) < 2:
+                answerss = await tmdb_func(answers, "")
+                await client.answer_inline_query(
+                    query.id,
+                    results=answerss,
+                    switch_pm_text="TMDB Search | tmdb [QUERY]",
+                    switch_pm_parameter="inline",
+                )
+                return
+            tex = text.split()[1].strip()
+            answerss = await tmdb_func(answers, tex)
+            await client.answer_inline_query(query.id, results=answerss, cache_time=2)
     except Exception as e:
         e = traceback.format_exc()
         print(e, " InLine")

+ 40 - 19
wbb/utils/inlinefuncs.py

@@ -77,6 +77,7 @@ keywords_list = [
     "carbon",
     "info",
     "chat_info",
+    "tmdb"
 ]
 
 
@@ -180,12 +181,8 @@ async def urban_func(answers, text):
             )
         )
         return answers
-    results = results.result
-    limit = 0
+    results = results.result[0:48]
     for i in results:
-        if limit > 48:
-            break
-        limit += 1
         msg = f"""
 **Query:** {text}
 
@@ -241,12 +238,8 @@ async def wall_func(answers, text):
             )
         )
         return answers
-    limit = 0
-    results = results.result
+    results = results.result[0:48]
     for i in results:
-        if limit > 48:
-            break
-        limit += 1
         answers.append(
             InlineQueryResultPhoto(
                 photo_url=i.url_image,
@@ -373,11 +366,8 @@ async def torrent_func(answers, text):
             )
         )
         return answers
-    limit = 0
-    results = results.result
+    results = results.result[0:48]
     for i in results:
-        if limit > 48:
-            break
         title = i.name
         size = i.size
         seeds = i.seeds
@@ -418,12 +408,8 @@ async def youtube_func(answers, text):
             )
         )
         return answers
-    limit = 0
-    results = results.result
+    results = results.result[0: 48]
     for i in results:
-        if limit > 48:
-            break
-        limit += 1
         buttons = InlineKeyboard(row_width=1)
         video_url = f"https://youtube.com{i.url_suffix}"
         buttons.add(InlineKeyboardButton("Watch", url=video_url))
@@ -942,3 +928,38 @@ async def chat_info_inline_func(answers, chat):
         )
     )
     return answers
+
+
+async def tmdb_func(answers, query):
+    response = await arq.tmdb(query)
+    if not response.ok:
+        answers.append(
+            InlineQueryResultArticle(
+                title="Error",
+                description=response.result,
+                input_message_content=InputTextMessageContent(response.result),
+            )
+        )
+        return answers
+    results = response.result[0:48]
+    for result in results 
+        caption = f"""
+**{result.title}**
+**Type:** {result.type}
+**Rating:** {result.rating}
+**Genre:** {" | ".join(result.genre) if result.genre else None}
+**Release Date:** {result.releaseDate}
+**Description:** __{result.overview}__
+"""
+        buttons = InlineKeyboard(row_width=1)
+        buttons.add(
+                InlineKeyboardButton("Search Again", switch_inline_query_current_chat="tmdb")
+                )
+        answers.append(
+                InlineQueryResultPhoto(
+                    photo_url=result.backdrop if result.backdrop else result.poster if result.poster else "https://cdn.hipwallpaper.com/i/82/99/EoKmFw.jpg",
+                    caption=caption,
+                    reply_markup=buttons
+                    )
+                )
+    return answers