autocorrect.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 & ~filters.edited & filters.user(USERBOT_ID),
  48. group=autocorrect_group,
  49. )
  50. async def autocorrect_ubot(_, message: Message):
  51. if not IS_ENABLED:
  52. return
  53. text = message.text
  54. data = await arq.spellcheck(text)
  55. corrected = data.result.corrected
  56. if corrected == text:
  57. return
  58. await message.edit(corrected)