autocorrect.py 1.8 KB

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