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. @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(result.corrected if result.corrected else "Empty")
  18. IS_ENABLED = False
  19. @app2.on_message(
  20. filters.command("autocorrect", prefixes=USERBOT_PREFIX)
  21. & filters.user(SUDOERS)
  22. )
  23. async def autocorrect_ubot_toggle(_, message: Message):
  24. global IS_ENABLED
  25. if len(message.command) != 2:
  26. return await message.edit("Not enough arguments.")
  27. state = message.text.split(None, 1)[1].strip().lower()
  28. if state == "enable":
  29. IS_ENABLED = True
  30. await message.edit("Enabled!")
  31. elif state == "disable":
  32. IS_ENABLED = False
  33. await message.edit("Disabled!")
  34. else:
  35. return await message.edit("Wrong argument, Pass (ENABLE|DISABLE).")
  36. @app2.on_message(
  37. filters.text & ~filters.edited & filters.user(USERBOT_ID),
  38. group=autocorrect_group,
  39. )
  40. async def autocorrect_ubot(_, message: Message):
  41. if not IS_ENABLED:
  42. return
  43. text = message.text
  44. data = await arq.spellcheck(text)
  45. corrected = data.result.corrected
  46. if corrected == text:
  47. return
  48. await message.edit(corrected)