autocorrect.py 1.8 KB

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