autocorrect.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. """
  2. MIT License
  3. Copyright (c) present TheHamkerCat
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in all
  11. copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  18. SOFTWARE.
  19. """
  20. from pyrogram import filters
  21. from pyrogram.types import Message
  22. from wbb import SUDOERS, USERBOT_ID, USERBOT_PREFIX, app, app2, arq
  23. from wbb.modules.userbot import eor
  24. from wbb.utils.filter_groups import autocorrect_group
  25. @app.on_message(
  26. filters.command("autocorrect")
  27. )
  28. async def autocorrect_bot(_, message: Message):
  29. if not message.reply_to_message:
  30. return await message.reply_text("Reply to a text message.")
  31. reply = message.reply_to_message
  32. text = reply.text or reply.caption
  33. if not text:
  34. return await message.reply_text("Reply to a text message.")
  35. data = await arq.spellcheck(text)
  36. if not data.ok:
  37. return await message.reply_text("Something wrong happened.")
  38. result = data.result
  39. await message.reply_text(result.corrected if result.corrected else "Empty")
  40. IS_ENABLED = False
  41. @app2.on_message(
  42. filters.command("autocorrect", prefixes=USERBOT_PREFIX)
  43. & SUDOERS
  44. )
  45. async def autocorrect_ubot_toggle(_, message: Message):
  46. global IS_ENABLED
  47. if len(message.command) != 2:
  48. return await eor(message, text="Not enough arguments.")
  49. state = message.text.split(None, 1)[1].strip().lower()
  50. if state == "enable":
  51. IS_ENABLED = True
  52. await eor(message, text="Enabled!")
  53. elif state == "disable":
  54. IS_ENABLED = False
  55. await eor(message, text="Disabled!")
  56. else:
  57. return await eor(
  58. message, text="Wrong argument, Pass (ENABLE|DISABLE)."
  59. )
  60. @app2.on_message(
  61. filters.text
  62. & filters.user(USERBOT_ID),
  63. group=autocorrect_group,
  64. )
  65. async def autocorrect_ubot(_, message: Message):
  66. if not IS_ENABLED:
  67. return
  68. text = message.text
  69. data = await arq.spellcheck(text)
  70. corrected = data.result.corrected
  71. if corrected == text:
  72. return
  73. await message.edit(corrected)