autocorrect.py 1.8 KB

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