autocorrect.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. from pyrogram import filters
  2. from pyrogram.types import Message
  3. from wbb import SUDOERS, USERBOT_ID, USERBOT_PREFIX, app, app2, arq
  4. from wbb.utils.filter_groups import autocorrect_group
  5. from wbb.modules.userbot import eor
  6. @app.on_message(filters.command("autocorrect"))
  7. async def autocorrect_bot(_, message: Message):
  8. if not message.reply_to_message:
  9. return await message.reply_text("Reply to a text message.")
  10. reply = message.reply_to_message
  11. text = reply.text or reply.caption
  12. if not text:
  13. return await message.reply_text("Reply to a text message.")
  14. data = await arq.spellcheck(text)
  15. if not data.ok:
  16. return await message.reply_text("Something wrong happened.")
  17. result = data.result
  18. await message.reply_text(result.corrected if result.corrected else "Empty")
  19. IS_ENABLED = False
  20. @app2.on_message(
  21. filters.command("autocorrect", prefixes=USERBOT_PREFIX)
  22. & SUDOERS
  23. )
  24. async def autocorrect_ubot_toggle(_, message: Message):
  25. global IS_ENABLED
  26. if len(message.command) != 2:
  27. return await eor(message, text="Not enough arguments.")
  28. state = message.text.split(None, 1)[1].strip().lower()
  29. if state == "enable":
  30. IS_ENABLED = True
  31. await eor(message, text="Enabled!")
  32. elif state == "disable":
  33. IS_ENABLED = False
  34. await eor(message, text="Disabled!")
  35. else:
  36. return await eor(message, text="Wrong argument, Pass (ENABLE|DISABLE).")
  37. @app2.on_message(
  38. filters.text & ~filters.edited & filters.user(USERBOT_ID),
  39. group=autocorrect_group,
  40. )
  41. async def autocorrect_ubot(_, message: Message):
  42. if not IS_ENABLED:
  43. return
  44. text = message.text
  45. data = await arq.spellcheck(text)
  46. corrected = data.result.corrected
  47. if corrected == text:
  48. return
  49. await message.edit(corrected)