소스 검색

Added /anime

TheHamkerCat 5 년 전
부모
커밋
79e5c5e1e5
2개의 변경된 파일과 111개의 추가작업 그리고 1개의 파일을 삭제
  1. 110 0
      wbb/modules/anime.py
  2. 1 1
      wbb/modules/filters.py

+ 110 - 0
wbb/modules/anime.py

@@ -0,0 +1,110 @@
+from wbb import app
+from wbb.utils.errors import capture_err
+from wbb.utils.fetch import fetch
+from pyrogram import filters
+from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup
+
+
+BASE_URL = "https://rgprojectx-gogoanime.herokuapp.com"
+
+
+RESULT_NUMBER = 0
+DATA_LEN = 0
+data = None
+m = None
+initial_keyboard = InlineKeyboardMarkup(
+    [
+        [
+            InlineKeyboardButton(
+                text="<<   Previous",
+                callback_data="previous"
+            ),
+            InlineKeyboardButton(
+                text="Next   >>",
+                callback_data="next"
+            )
+        ],
+        [
+            InlineKeyboardButton(
+                text="📺   More Details   📺",
+                callback_data="more_details"
+            )
+        ]
+    ]
+)
+
+
+@app.on_message(filters.command("anime") & ~filters.edited)
+async def anime_search(_, message):
+    if len(message.command) < 2:
+        await message.reply_text("**Usage:**\n/anime [Query]")
+        return
+    global RESULT_NUMBER, DATA_LEN, data, m
+    RESULT_NUMBER == 0
+    m = await message.reply_text("**Searching....**")
+    anime_name = message.text.split(None, 1)[1]
+    data = await fetch(f"{BASE_URL}/search?name={anime_name}")
+    data = data['response']
+    DATA_LEN = len(data)
+    if DATA_LEN == 0:
+        await message.reply_text("**Found literally nothing.**")
+        return
+    m = await app.send_message(
+        photo=data[RESULT_NUMBER]['thumbnail'],
+        caption=f"**Title:** {data[RESULT_NUMBER]['title']}",
+        reply_markup=initial_keyboard
+    )
+
+
+@app.on_callback_query(filters.regex("previous"))
+async def previous_callbacc(_, CallbackQuery):
+    global RESULT_NUMBER, data, m
+    if RESULT_NUMBER == 0:
+        await CallbackQuery.answer(
+            "Already On 1st Result, Can't go back.",
+            show_alert=True
+        )
+        return
+    RESULT_NUMBER -= 0
+    await m.edit(
+        photo=data[RESULT_NUMBER]['thumbnail'],
+        caption=f"**Title:** {data[RESULT_NUMBER]['title']}",
+        reply_markup=initial_keyboard
+    )
+
+
+@app.on_callback_query(filters.regex("next"))
+async def next_callbacc(_, CallbackQuery):
+    global RESULT_NUMBER, DATA_LEN, data, m
+    if (RESULT_NUMBER + 1) == DATA_LEN:
+        await CallbackQuery.answer(
+            "Nothing on the next page.",
+            show_alert=True
+        )
+        return
+    RESULT_NUMBER += 1
+    await m.edit(
+        photo=data[RESULT_NUMBER]['thumbnail'],
+        caption=f"**Title:** {data[RESULT_NUMBER]['title']}",
+        reply_markup=initial_keyboard
+    )
+
+
+@app.on_callback_query(filters.regex("more_details"))
+async def more_details_callbacc(_, CallbackQuery):
+    global RESULT_NUMBER, data, m
+    SLUG = data[RESULT_NUMBER]['slug']
+    data = await fetch(f"{BASE_URL}/details?slug={SLUG}")
+    data = data['response']
+    caption = f"""
+**Title:** __{data['title']}__
+**Genre:** __{data['genre']}__
+**Release:** __{data['release_year']}__
+**Status:** __{data['status']}__
+**Other Name:** __{data['other_name']}__
+**Episodes:** __{len(data['episodes'])}__
+**Summary:** __{data['summary']}__"""
+    await m.edit(
+        photo=data['thumbnail'],
+        caption=caption,
+        keyboard=InlineKeyboardMarkup([[InlineKeyboardButton(text="Episode", callback_data="hoe")]])

+ 1 - 1
wbb/modules/filters.py

@@ -96,6 +96,6 @@ async def filters_re(_, message):
                         else:
                             await message.reply_sticker(data)
                         return
+    # NOTE When the first letter of the message is an emoji it throws an error, that's why using this
     except Exception:
-        print("Error in filters_re function in filters.py [IGNORE THIS]")
         pass