Jelajahi Sumber

Added /sh and /covid

TheHamkerCat 5 tahun lalu
induk
melakukan
a299c8fa7f
4 mengubah file dengan 174 tambahan dan 77 penghapusan
  1. 26 0
      wbb/modules/covid.py
  2. 147 0
      wbb/modules/devs.py
  3. 0 76
      wbb/modules/eval.py
  4. 1 1
      wbb/modules/sudoers.py

+ 26 - 0
wbb/modules/covid.py

@@ -0,0 +1,26 @@
+from wbb import app
+from wbb.utils.errors import capture_err
+from wbb.utils.json_prettify import json_prettify
+from wbb.utils.fetch import fetch
+from pyrogram import filters
+
+
+__MODULE__ = "Covid"
+__HELP__ = """/covid - To Get Global Stats of Covid.
+/covid [COUNTRY] - To Get Stats of A Single Country."""
+
+
+@app.on_message(filters.command("covid") & ~filters.edited)
+@capture_err
+async def covid(_, message):
+    if len(message.command) == 1:
+        data = await fetch("https://corona.lmao.ninja/v2/all")
+        data = await json_prettify(data)
+        await app.send_message(message.chat.id, text=data)
+        return
+    if len(message.command) != 1:
+        country = message.text.split(None, 1)[1].strip()
+        country = country.replace(" ", "")
+        data = await fetch(f"https://corona.lmao.ninja/v2/countries/{country}")
+        await app.send_message(message.chat.id, text=data)
+        return

+ 147 - 0
wbb/modules/devs.py

@@ -0,0 +1,147 @@
+import sys
+import traceback
+from io import StringIO
+import os
+from inspect import getfullargspec
+from wbb import app, OWNER_ID
+from pyrogram import filters
+from pyrogram.types import Message
+
+__MODULE__ = "Devs"
+__HELP__ = "/eval - Execute Python Code\n/sh - Execute Shell Code"
+
+
+# Eval and Sh module from nana-remix
+
+async def aexec(code, client, message):
+    exec(
+        "async def __aexec(client, message): "
+        + "".join(f"\n {a}" for a in code.split("\n"))
+    )
+    return await locals()["__aexec"](client, message)
+
+
+async def edit_or_reply(msg: Message, **kwargs):
+    func = msg.edit_text if msg.from_user.is_self else msg.reply
+    spec = getfullargspec(func.__wrapped__).args
+    await func(**{k: v for k, v in kwargs.items() if k in spec})
+
+
+@app.on_message(filters.user(OWNER_ID) & ~filters.forwarded & ~filters.via_bot & filters.command("eval"))
+async def executor(client, message):
+    try:
+        cmd = message.text.split(" ", maxsplit=1)[1]
+    except IndexError:
+        await message.delete()
+        return
+    reply_to_id = message.message_id
+    if message.reply_to_message:
+        reply_to_id = message.reply_to_message.message_id
+    old_stderr = sys.stderr
+    old_stdout = sys.stdout
+    redirected_output = sys.stdout = StringIO()
+    redirected_error = sys.stderr = StringIO()
+    stdout, stderr, exc = None, None, None
+    try:
+        await aexec(cmd, client, message)
+    except Exception:
+        exc = traceback.format_exc()
+    stdout = redirected_output.getvalue()
+    stderr = redirected_error.getvalue()
+    sys.stdout = old_stdout
+    sys.stderr = old_stderr
+    evaluation = ""
+    if exc:
+        evaluation = exc
+    elif stderr:
+        evaluation = stderr
+    elif stdout:
+        evaluation = stdout
+    else:
+        evaluation = "Success"
+    final_output = (f"**OUTPUT**:\n```{evaluation.strip()}```")
+    if len(final_output) > 4096:
+        filename = "output.txt"
+        with open(filename, "w+", encoding="utf8") as out_file:
+            out_file.write(str(evaluation.strip()))
+        await message.reply_document(
+            document=filename,
+            caption=cmd,
+            disable_notification=True,
+            reply_to_message_id=reply_to_id,
+        )
+        os.remove(filename)
+        await message.delete()
+    else:
+        await edit_or_reply(message, text=final_output)
+
+
+@app.on_message(
+    filters.user(OWNER_ID)
+    & ~filters.forwarded
+    & ~filters.via_bot
+    & filters.command('sh'),
+)
+async def shellrunner(client, message):
+    if len(message.command) < 2:
+        await message.reply_text(message, text='**Usage:**\n/sh git pull')
+        return
+    text = message.text.split(None, 1)[1]
+    if '\n' in text:
+        code = text.split('\n')
+        output = ''
+        for x in code:
+            shell = re.split(""" (?=(?:[^'"]|'[^']*'|"[^"]*")*$)""", x)
+            try:
+                process = subprocess.Popen(
+                    shell, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
+                )
+            except Exception as err:
+                print(err)
+                await message.reply_text(
+                    message,
+                    text=f"**Error:**\n```{err}```")
+            output += f'**{code}**\n'
+            output += process.stdout.read()[:-1].decode('utf-8')
+            output += '\n'
+    else:
+        shell = re.split(""" (?=(?:[^'"]|'[^']*'|"[^"]*")*$)""", text)
+        for a in range(len(shell)):
+            shell[a] = shell[a].replace('"', '')
+        try:
+            process = subprocess.Popen(
+                shell, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
+            )
+        except Exception as err:
+            print(err)
+            exc_type, exc_obj, exc_tb = sys.exc_info()
+            errors = traceback.format_exception(
+                etype=exc_type, value=exc_obj, tb=exc_tb,
+            )
+            await message.reply_text(
+                message,
+                text="**Error:**\n```{''.join(errors)}```")
+            return
+        output = process.stdout.read()[:-1].decode('utf-8')
+    if str(output) == '\n':
+        output = None
+    if output:
+        if len(output) > 4096:
+            with open('output.txt', 'w+') as file:
+                file.write(output)
+            await app.send_document(
+                message.chat.id,
+                'output.txt',
+                reply_to_message_id=message.message_id,
+                caption='`Output`',
+            )
+            os.remove('output.txt')
+            return
+        await message.reply_text(
+            message,
+            text="**Output:**\n```{output}```"
+        )
+    else:
+        await message.reply_text(
+            message,
+            text='**Output: **\n`No output`')

+ 0 - 76
wbb/modules/eval.py

@@ -1,76 +0,0 @@
-import sys
-import traceback
-from io import StringIO
-import os
-from inspect import getfullargspec
-from wbb import app, OWNER_ID
-from pyrogram import filters
-from pyrogram.types import Message
-
-__MODULE__ = "Eval"
-__HELP__ = "/eval - You know what this does lol"
-
-
-# Eval module from nana-remix
-
-async def aexec(code, client, message):
-    exec(
-        "async def __aexec(client, message): "
-        + "".join(f"\n {a}" for a in code.split("\n"))
-    )
-    return await locals()["__aexec"](client, message)
-
-
-async def edit_or_reply(msg: Message, **kwargs):
-    func = msg.edit_text if msg.from_user.is_self else msg.reply
-    spec = getfullargspec(func.__wrapped__).args
-    await func(**{k: v for k, v in kwargs.items() if k in spec})
-
-
-@app.on_message(filters.user(OWNER_ID) & ~filters.forwarded & ~filters.via_bot & filters.command("eval"))
-async def executor(client, message):
-    try:
-        cmd = message.text.split(" ", maxsplit=1)[1]
-    except IndexError:
-        await message.delete()
-        return
-    reply_to_id = message.message_id
-    if message.reply_to_message:
-        reply_to_id = message.reply_to_message.message_id
-    old_stderr = sys.stderr
-    old_stdout = sys.stdout
-    redirected_output = sys.stdout = StringIO()
-    redirected_error = sys.stderr = StringIO()
-    stdout, stderr, exc = None, None, None
-    try:
-        await aexec(cmd, client, message)
-    except Exception:
-        exc = traceback.format_exc()
-    stdout = redirected_output.getvalue()
-    stderr = redirected_error.getvalue()
-    sys.stdout = old_stdout
-    sys.stderr = old_stderr
-    evaluation = ""
-    if exc:
-        evaluation = exc
-    elif stderr:
-        evaluation = stderr
-    elif stdout:
-        evaluation = stdout
-    else:
-        evaluation = "Success"
-    final_output = (f"**OUTPUT**:\n```{evaluation.strip()}```")
-    if len(final_output) > 4096:
-        filename = "output.txt"
-        with open(filename, "w+", encoding="utf8") as out_file:
-            out_file.write(str(evaluation.strip()))
-        await message.reply_document(
-            document=filename,
-            caption=cmd,
-            disable_notification=True,
-            reply_to_message_id=reply_to_id,
-        )
-        os.remove(filename)
-        await message.delete()
-    else:
-        await edit_or_reply(message, text=final_output)

+ 1 - 1
wbb/modules/sudoers.py

@@ -191,7 +191,7 @@ async def unban_globally(_, message):
 
 
 @app.on_message(
-    filters.command("/broadcast")
+    filters.command("broadcast")
     & filters.user(SUDOERS)
     & ~filters.edited
 )