Jelajahi Sumber

Added /report and sed

TheHamkerCat 5 tahun lalu
induk
melakukan
d33d63702d
3 mengubah file dengan 137 tambahan dan 3 penghapusan
  1. 18 1
      wbb/modules/admin.py
  2. 2 2
      wbb/modules/karma.py
  3. 117 0
      wbb/modules/regex.py

+ 18 - 1
wbb/modules/admin.py

@@ -18,7 +18,8 @@ __HELP__ = '''/ban - Ban A User
 /pin - Pin A Message
 /mute - Mute A User
 /unmute - Unmute A User
-/ban_ghosts - Ban Deleted Accounts'''
+/ban_ghosts - Ban Deleted Accounts
+/report | @admins - Report A Message To Admins.'''
 
 
 async def list_admins(group_id):
@@ -479,3 +480,19 @@ async def check_warns(_, message):
         await message.reply_text(f"{mention__from_user} have {warns}/3 warnings.")
     except Exception as e:
         await message.reply_text(str(e))
+
+# Report
+
+
+@app.on_message(filters.command(["report", "admins"], prefixes=["@", "/"]) & ~filters.edited)
+@capture_err
+async def report_user(_, message):
+    if not message.reply_to_message:
+        await message.reply_text("Reply to a message to report user.")
+        return
+    list_of_admins = await list_admins(message.chat.id)
+    user_mention = message.reply_to_message.from_user.mention
+    text = f"Reported {user_mention} to admins."
+    for admin in list_of_admins:
+        text += f"[\u2063](tg://user?id={admin})"
+    await message.reply_text(text)

+ 2 - 2
wbb/modules/karma.py

@@ -90,11 +90,11 @@ async def karma(_, message):
             user_name = (await app.get_users(user_id)).username
             karma_dicc[user_name] = user_karma
             
-            karma_arranged = dict(sorted(karma_dicc.items(), key=operator.itemgetter(0)))
+            karma_arranged = dict(sorted(karma_dicc.items(), key=lambda item: item[1], reverse=True))
         for username, karma_count in karma_arranged.items():
             if limit > 9:
                 break
-            msg += f"{username} - `{karma_count}`\n"
+            msg += f"{username} : `{karma_count}`\n"
             limit += 1
         await message.reply_text(msg)
     else:

+ 117 - 0
wbb/modules/regex.py

@@ -0,0 +1,117 @@
+import re
+import sre_constants
+from wbb import app
+from pyrogram import filters
+
+
+__MODULE__ = "Sed"
+__HELP__ = "**Usage:**\ns/foo/bar"
+
+
+DELIMITERS = ("/", ":", "|", "_")
+
+
+@app.on_message(filters.regex(r"s([{}]).*?\1.*".format("".join(DELIMITERS))), group=7)
+async def sed(_, message):
+    sed_result = separate_sed(message.text)
+    if message.reply_to_message:
+        if message.reply_to_message.text:
+            to_fix = message.reply_to_message.text
+        elif message.reply_to_message.caption:
+            to_fix = message.reply_to_message.caption
+        else:
+            return
+        repl, repl_with, flags = sed_result
+
+        if not repl:
+            await message.reply_text(
+                "You're trying to replace... " "nothing with something?"
+            )
+            return
+
+        try:
+
+            if infinite_checker(repl) == True:
+                await message.reply_text("Nice try -_-")
+                return
+
+            if "i" in flags and "g" in flags:
+                text = re.sub(repl, repl_with, to_fix, flags=re.I).strip()
+            elif "i" in flags:
+                text = re.sub(repl, repl_with, to_fix,
+                              count=1, flags=re.I).strip()
+            elif "g" in flags:
+                text = re.sub(repl, repl_with, to_fix).strip()
+            else:
+                text = re.sub(repl, repl_with, to_fix, count=1).strip()
+        except sre_constants.error:
+            return
+
+        # empty string errors -_-
+        if len(text) >= 4096:
+            await message.reply_text(
+                "The result of the sed command was too long for \
+                                                 telegram!"
+            )
+        elif text:
+            await message.reply_to_message.reply_text(text)
+
+
+def infinite_checker(repl):
+    regex = [
+        r"\((.{1,}[\+\*]){1,}\)[\+\*].",
+        r"[\(\[].{1,}\{\d(,)?\}[\)\]]\{\d(,)?\}",
+        r"\(.{1,}\)\{.{1,}(,)?\}\(.*\)(\+|\* |\{.*\})",
+    ]
+    for match in regex:
+        status = re.search(match, repl)
+        if status:
+            return True
+        else:
+            return False
+
+
+def separate_sed(sed_string):
+    if (
+        len(sed_string) >= 3
+        and sed_string[1] in DELIMITERS
+        and sed_string.count(sed_string[1]) >= 2
+    ):
+        delim = sed_string[1]
+        start = counter = 2
+        while counter < len(sed_string):
+            if sed_string[counter] == "\\":
+                counter += 1
+
+            elif sed_string[counter] == delim:
+                replace = sed_string[start:counter]
+                counter += 1
+                start = counter
+                break
+
+            counter += 1
+
+        else:
+            return None
+
+        while counter < len(sed_string):
+            if (
+                sed_string[counter] == "\\"
+                and counter + 1 < len(sed_string)
+                and sed_string[counter + 1] == delim
+            ):
+                sed_string = sed_string[:counter] + sed_string[counter + 1:]
+
+            elif sed_string[counter] == delim:
+                replace_with = sed_string[start:counter]
+                counter += 1
+                break
+
+            counter += 1
+        else:
+            return replace, sed_string[start:], ""
+
+        flags = ""
+        if counter < len(sed_string):
+            flags = sed_string[counter:]
+        return replace, replace_with, flags.lower()