autocorrect.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. __MODULE__ = "Autocorrect"
  6. __HELP__ = """
  7. /autocorrect [Reply to a message] - Autocorrects the text in replied message.
  8. .autocorrect [ENABLE|DISABLE] - Enable or disable autocorrect in userbot [ONLY FOR DEVS]
  9. This will autocorrect your messages on the go.
  10. """
  11. @app.on_message(filters.command("autocorrect"))
  12. async def autocorrect_bot(_, message: Message):
  13. if not message.reply_to_message:
  14. return await message.reply_text("Reply to a text message.")
  15. reply = message.reply_to_message
  16. text = reply.text or reply.caption
  17. if not text:
  18. return await message.reply_text("Reply to a text message.")
  19. data = await arq.spellcheck(text)
  20. if not data.ok:
  21. return await message.reply_text("Something wrong happened.")
  22. result = data.result
  23. await message.reply_text(
  24. result.corrected if result.corrected else "Empty"
  25. )
  26. IS_ENABLED = False
  27. @app2.on_message(
  28. filters.command("autocorrect", prefixes=USERBOT_PREFIX)
  29. & filters.user(SUDOERS)
  30. )
  31. async def autocorrect_ubot_toggle(_, message: Message):
  32. global IS_ENABLED
  33. if len(message.command) != 2:
  34. return await message.edit("Not enough arguments.")
  35. state = message.text.split(None, 1)[1].strip().lower()
  36. if state == "enable":
  37. IS_ENABLED = True
  38. await message.edit("Enabled!")
  39. elif state == "disable":
  40. IS_ENABLED = False
  41. await message.edit("Disabled!")
  42. else:
  43. return await message.edit(
  44. "Wrong argument, Pass (ENABLE|DISABLE)."
  45. )
  46. @app2.on_message(
  47. filters.text
  48. & ~filters.edited
  49. & filters.user(USERBOT_ID),
  50. group=autocorrect_group
  51. )
  52. async def autocorrect_ubot(_, message: Message):
  53. if not IS_ENABLED:
  54. return
  55. text = message.text
  56. data = await arq.spellcheck(text)
  57. corrected = data.result.corrected
  58. if corrected == text:
  59. return
  60. await message.edit(corrected)