anime.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. from wbb import app
  2. from wbb.utils.errors import capture_err
  3. from wbb.utils.fetch import fetch
  4. from pyrogram import filters
  5. from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup, InputMediaPhoto
  6. BASE_URL = "https://rgprojectx-gogoanime.herokuapp.com"
  7. RESULT_NUMBER = 0
  8. DATA_LEN = 0
  9. data = None
  10. m = None
  11. initial_keyboard = InlineKeyboardMarkup(
  12. [
  13. [
  14. InlineKeyboardButton(
  15. text="<< Previous",
  16. callback_data="previous"
  17. ),
  18. InlineKeyboardButton(
  19. text="Next >>",
  20. callback_data="next"
  21. )
  22. ],
  23. [
  24. InlineKeyboardButton(
  25. text="📺 More Details 📺",
  26. callback_data="more_details"
  27. )
  28. ]
  29. ]
  30. )
  31. @app.on_message(filters.command("anime") & ~filters.edited)
  32. async def anime_search(_, message):
  33. if len(message.command) < 2:
  34. await message.reply_text("**Usage:**\n/anime [Query]")
  35. return
  36. global RESULT_NUMBER, DATA_LEN, data, m
  37. RESULT_NUMBER == 0
  38. m = await message.reply_text("**Searching....**")
  39. anime_name = message.text.split(None, 1)[1]
  40. data = await fetch(f"{BASE_URL}/search?name={anime_name}")
  41. data = data['response']
  42. DATA_LEN = len(data)
  43. if DATA_LEN == 0:
  44. await message.reply_text("**Found literally nothing.**")
  45. return
  46. await m.delete()
  47. m = await app.send_photo(
  48. message.chat.id,
  49. photo=data[RESULT_NUMBER]['thumbnail'],
  50. caption=f"**Title:** {data[RESULT_NUMBER]['title']}",
  51. reply_markup=initial_keyboard
  52. )
  53. @app.on_callback_query(filters.regex("previous"))
  54. async def previous_callbacc(_, CallbackQuery):
  55. global RESULT_NUMBER, data, m
  56. if RESULT_NUMBER == 0:
  57. await CallbackQuery.answer(
  58. "Already On 1st Result, Can't go back.",
  59. show_alert=True
  60. )
  61. return
  62. RESULT_NUMBER -= 1
  63. await m.edit_media(media=InputMediaPhoto(data[RESULT_NUMBER]['thumbnail']))
  64. await m.edit(
  65. f"**Title:** {data[RESULT_NUMBER]['title']}",
  66. reply_markup=initial_keyboard
  67. )
  68. @app.on_callback_query(filters.regex("next"))
  69. async def next_callbacc(_, CallbackQuery):
  70. global RESULT_NUMBER, DATA_LEN, data, m
  71. if (RESULT_NUMBER + 1) == DATA_LEN:
  72. await CallbackQuery.answer(
  73. "Nothing on the next page.",
  74. show_alert=True
  75. )
  76. return
  77. RESULT_NUMBER += 1
  78. await m.edit_media(media=InputMediaPhoto(data[RESULT_NUMBER]['thumbnail']))
  79. await m.edit(
  80. f"**Title:** {data[RESULT_NUMBER]['title']}",
  81. reply_markup=initial_keyboard
  82. )
  83. @app.on_callback_query(filters.regex("more_details"))
  84. async def more_details_callbacc(_, CallbackQuery):
  85. global RESULT_NUMBER, data, m
  86. SLUG = data[RESULT_NUMBER]['slug']
  87. data = await fetch(f"{BASE_URL}/details?slug={SLUG}")
  88. data = data['response']
  89. caption = f"""
  90. **Title:** __{data['title']}__
  91. **Genre:** __{data['genre']}__
  92. **Release:** __{data['release_year']}__
  93. **Status:** __{data['status']}__
  94. **Other Name:** __{data['other_name']}__
  95. **Episodes:** __{len(data['episodes'])}__
  96. **Summary:** __{data['summary']}__"""
  97. await m.edit_media(media=InputMediaPhoto(data['thumbnail']))
  98. await m.edit(
  99. caption,
  100. reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton(text="Delete", callback_data="delete_message")]]))
  101. @app.on_callback_query(filters.regex("delete_message"))
  102. async def delete_callbacc(_, CallbackQuery):
  103. global RESULT_NUMBER, data, DATA_LEN, m
  104. RESULT_NUMBER = 0
  105. data = None
  106. DATA_LEN = 0
  107. await m.delete()