瀏覽代碼

Added autocorrect

TheHamkerCat 5 年之前
父節點
當前提交
aa7f0814d7
共有 6 個文件被更改,包括 83 次插入 和 7 次删除
  1. 69 0
      wbb/modules/autocorrect.py
  2. 1 1
      wbb/modules/pmpermit.py
  3. 10 4
      wbb/modules/spam.py
  4. 1 1
      wbb/modules/webss.py
  5. 1 0
      wbb/utils/filter_groups.py
  6. 1 1
      wbb/utils/functions.py

+ 69 - 0
wbb/modules/autocorrect.py

@@ -0,0 +1,69 @@
+from pyrogram import filters
+from pyrogram.types import Message
+
+from wbb import SUDOERS, USERBOT_ID, USERBOT_PREFIX, app, app2, arq
+from wbb.utils.filter_groups import autocorrect_group
+
+__MODULE__ = "Autocorrect"
+__HELP__ = """
+/autocorrect [Reply to a message] - Autocorrects the text in replied message.
+
+
+.autocorrect [ENABLE|DISABLE] - Enable or disable autocorrect in userbot [ONLY FOR DEVS]
+This will autocorrect your messages on the go.
+"""
+
+
+@app.on_message(filters.command("autocorrect"))
+async def autocorrect_bot(_, message: Message):
+    if not message.reply_to_message:
+        return await message.reply_text("Reply to a text message.")
+    reply = message.reply_to_message
+    text = reply.text or reply.caption
+    if not text:
+        return await message.reply_text("Reply to a text message.")
+    data = await arq.spellcheck(text)
+    if not data.ok:
+        return await message.reply_text("Something wrong happened.")
+    result = data.result
+    await message.reply_text(
+        result.corrected if result.corrected else "Empty"
+    )
+
+
+IS_ENABLED = False
+
+
+@app2.on_message(
+    filters.command("autocorrect", prefixes=USERBOT_PREFIX)
+    & filters.user(SUDOERS)
+)
+async def autocorrect_ubot_toggle(_, message: Message):
+    global IS_ENABLED
+    if len(message.command) != 2:
+        return await message.edit("Not enough arguments.")
+    state = message.text.split(None, 1)[1].strip().lower()
+    if state == "enable":
+        IS_ENABLED = True
+        await message.edit("Enabled!")
+    elif state == "disable":
+        IS_ENABLED = False
+        await message.edit("Enabled!")
+    else:
+        return await message.edit(
+            "Wrong argument, Pass (ENABLE|DISABLE)."
+        )
+
+
+@app2.on_message(
+    filters.text & filters.user(USERBOT_ID), group=autocorrect_group
+)
+async def autocorrect_ubot(_, message: Message):
+    if not IS_ENABLED:
+        return
+    text = message.text
+    data = await arq.spellcheck(text)
+    corrected = data.result.corrected
+    if corrected == text:
+        return
+    await message.edit(corrected)

+ 1 - 1
wbb/modules/pmpermit.py

@@ -171,7 +171,7 @@ async def pmpermit_cq(_, cq):
         return await app.edit_inline_text(
             cq.inline_message_id, "User Has Been Approved To PM."
         )
-    
+
     if data == "block":
         if user_id != USERBOT_ID:
             return await cq.answer("This Button Is Not For You")

+ 10 - 4
wbb/modules/spam.py

@@ -25,7 +25,7 @@ from pyrogram import filters
 from pyrogram.types import (CallbackQuery, InlineKeyboardButton,
                             InlineKeyboardMarkup, Message)
 
-from wbb import LOG_GROUP_ID, SUDOERS, app, app2, arq, USERBOT_PREFIX
+from wbb import LOG_GROUP_ID, SUDOERS, USERBOT_PREFIX, app, app2, arq
 from wbb.core.decorators.permissions import adminsOnly
 from wbb.modules.admin import list_admins, member_permissions
 from wbb.modules.trust import get_spam_data
@@ -214,15 +214,21 @@ async def spam_toggle(_, message: Message):
             "Unknown Suffix, Use /spam_detection [ENABLE|DISABLE]"
         )
 
+
 @app.on_message(filters.command("spam_scan"))
-@app2.on_message(filters.command("spam_scan", prefixes=USERBOT_PREFIX) & filters.user(SUDOERS))
+@app2.on_message(
+    filters.command("spam_scan", prefixes=USERBOT_PREFIX)
+    & filters.user(SUDOERS)
+)
 async def scanNLP(_, message: Message):
     if not message.reply_to_message:
-        return await edit_or_reply(message, text="Reply to a message to scan it.")
+        return await edit_or_reply(
+            message, text="Reply to a message to scan it."
+        )
     r = message.reply_to_message
     text = r.text or r.caption
     if not text:
-       return await edit_or_reply(message, text="Can't scan that")
+        return await edit_or_reply(message, text="Can't scan that")
     data = await arq.nlp(text)
     data = data.result[0]
     msg = f"""

+ 1 - 1
wbb/modules/webss.py

@@ -22,10 +22,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 SOFTWARE.
 """
 from pyrogram import filters
+from pyrogram.types import Message
 
 from wbb import app
 from wbb.core.decorators.errors import capture_err
-from pyrogram.types import Message
 
 __MODULE__ = "WebSS"
 __HELP__ = "/webss | .webss [URL] - Take A Screenshot Of A Webpage"

+ 1 - 0
wbb/utils/filter_groups.py

@@ -36,3 +36,4 @@ chat_watcher_group = 12
 trust_group = 13
 flood_group = 14
 spam_protection_group = 15
+autocorrect_group = 16

+ 1 - 1
wbb/utils/functions.py

@@ -255,7 +255,7 @@ async def test_ARQ(message):
         "pornhub": arq.pornhub("something"),
         "proxy": arq.proxy(),
         "pypi": arq.pypi("python-arq"),
-        "reddit": arq.reddit("porn"),
+        "reddit": arq.reddit("badcode"),
         "quotly": arq.quotly(message),
         "saavn": arq.saavn("attention"),
         "stats": arq.stats(),