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. @capture_err
  33. async def anime_search(_, message):
  34. if len(message.command) < 2:
  35. await message.reply_text("**Usage:**\n/anime [Query]")
  36. return
  37. global RESULT_NUMBER, DATA_LEN, data, m
  38. RESULT_NUMBER == 0
  39. m = await message.reply_text("**Searching....**")
  40. anime_name = message.text.split(None, 1)[1]
  41. data = await fetch(f"{BASE_URL}/search?name={anime_name}")
  42. data = data['response']
  43. DATA_LEN = len(data)
  44. if DATA_LEN == 0:
  45. await message.reply_text("**Found literally nothing.**")
  46. return
  47. await m.delete()
  48. m = await app.send_photo(
  49. message.chat.id,
  50. photo=data[RESULT_NUMBER]['thumbnail'],
  51. caption=f"**Title:** {data[RESULT_NUMBER]['title']}",
  52. reply_markup=initial_keyboard
  53. )
  54. @app.on_callback_query(filters.regex("previous"))
  55. async def previous_callbacc(_, CallbackQuery):
  56. global RESULT_NUMBER, data, m
  57. if RESULT_NUMBER == 0:
  58. await CallbackQuery.answer(
  59. "Already On 1st Result, Can't go back.",
  60. show_alert=True
  61. )
  62. return
  63. RESULT_NUMBER -= 1
  64. await m.edit_media(media=InputMediaPhoto(data[RESULT_NUMBER]['thumbnail']))
  65. await m.edit(
  66. f"**Title:** {data[RESULT_NUMBER]['title']}",
  67. reply_markup=initial_keyboard
  68. )
  69. @app.on_callback_query(filters.regex("next"))
  70. async def next_callbacc(_, CallbackQuery):
  71. global RESULT_NUMBER, DATA_LEN, data, m
  72. if (RESULT_NUMBER + 1) == DATA_LEN:
  73. await CallbackQuery.answer(
  74. "Nothing on the next page.",
  75. show_alert=True
  76. )
  77. return
  78. RESULT_NUMBER += 1
  79. await m.edit_media(media=InputMediaPhoto(data[RESULT_NUMBER]['thumbnail']))
  80. await m.edit(
  81. f"**Title:** {data[RESULT_NUMBER]['title']}",
  82. reply_markup=initial_keyboard
  83. )
  84. @app.on_callback_query(filters.regex("more_details"))
  85. async def more_details_callbacc(_, CallbackQuery):
  86. global RESULT_NUMBER, data, m
  87. SLUG = data[RESULT_NUMBER]['slug']
  88. data = await fetch(f"{BASE_URL}/details?slug={SLUG}")
  89. data = data['response']
  90. caption = f"""
  91. **Title:** __{data['title']}__
  92. **Genre:** __{data['genre']}__
  93. **Release:** __{data['release_year']}__
  94. **Status:** __{data['status']}__
  95. **Other Name:** __{data['other_name']}__
  96. **Episodes:** __{len(data['episodes'])}__
  97. **Summary:** __{data['summary']}__"""
  98. await m.edit_media(media=InputMediaPhoto(data['thumbnail']))
  99. await m.edit(
  100. caption,
  101. reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton(text="Delete", callback_data="delete_message")]]))
  102. @app.on_callback_query(filters.regex("delete_message"))
  103. async def delete_callbacc(_, CallbackQuery):
  104. global RESULT_NUMBER, data, DATA_LEN, m
  105. RESULT_NUMBER = 0
  106. data = None
  107. DATA_LEN = 0
  108. await m.delete()