Quellcode durchsuchen

Added inline eval

TheHamkerCat vor 5 Jahren
Ursprung
Commit
ff46fd901f

+ 1 - 1
wbb/modules/antiservice.py

@@ -44,5 +44,5 @@ async def delete_service(_, message):
         if await is_antiservice_on(chat_id):
             await message.delete()
             return
-    except Exception as e:
+    except Exception:
         pass

+ 6 - 5
wbb/modules/genstr.py

@@ -30,9 +30,10 @@ async def genstr(_, message):
         if "y" in confirm.text.lower():
             break
     try:
-        temp_client = Client(":memory:", api_id=6, api_hash="eb06d4abfb49dc3eeb1aeb98ae0f581e")
+        temp_client = Client(":memory:", api_id=6,
+                             api_hash="eb06d4abfb49dc3eeb1aeb98ae0f581e")
     except Exception as e:
-        await app.send_message(chat.id ,f"**ERROR:** `{str(e)}`")
+        await app.send_message(chat.id, f"**ERROR:** `{str(e)}`")
         return
     try:
         await temp_client.connect()
@@ -66,7 +67,7 @@ async def genstr(_, message):
     except SessionPasswordNeeded:
         try:
             two_step_code = await app.ask(
-                chat.id, 
+                chat.id,
                 "Your account have Two-Step Verification.\nPlease enter your Password.",
                 timeout=300
             )
@@ -80,12 +81,12 @@ async def genstr(_, message):
             await message.reply_text(f"**ERROR:** `{str(e)}`")
             return
     except Exception as e:
-        await app.send_message(chat.id ,f"**ERROR:** `{str(e)}`")
+        await app.send_message(chat.id, f"**ERROR:** `{str(e)}`")
         return
     try:
         session_string = await temp_client.export_session_string()
         await temp_client.disconnect()
         await app.send_message(chat.id, text=f"**HERE IS YOUR STRING SESSION:**\n```{session_string}```")
     except Exception as e:
-        await app.send_message(chat.id ,f"**ERROR:** `{str(e)}`")
+        await app.send_message(chat.id, f"**ERROR:** `{str(e)}`")
         return

+ 7 - 4
wbb/modules/greetings.py

@@ -1,6 +1,7 @@
 """ Kang with proper credits or /gbun """
 
-import asyncio, os
+import asyncio
+import os
 from wbb import app, WELCOME_DELAY_KICK_SEC, SUDOERS
 from wbb.modules.admin import member_permissions
 from wbb.utils.errors import capture_err
@@ -46,7 +47,8 @@ async def welcome(_, message: Message):
                     f"Solve this captcha in {WELCOME_DELAY_KICK_SEC} seconds or you'll be kicked.")
         except ChatAdminRequired:
             break
-        captcha = generate_captcha() # Generate a captcha image, answers and some wrong answers
+        # Generate a captcha image, answers and some wrong answers
+        captcha = generate_captcha()
         captcha_image = captcha[0]
         captcha_answer = captcha[1]
         wrong_answers = captcha[2]  # This consists of 7 wrong answers
@@ -79,8 +81,9 @@ async def welcome(_, message: Message):
             "keyboard": keyboard
         }
         keyboard = InlineKeyboardMarkup(keyboard)
-        answers_dicc.append(verification_data)  # Append user info, correct answer and 
-                                                # keyboard for later use with callback query
+        # Append user info, correct answer and
+        answers_dicc.append(verification_data)
+        # keyboard for later use with callback query
         button_message = await message.reply_photo(
             photo=captcha_image,
             caption=text,

+ 1 - 2
wbb/modules/images.py

@@ -1,9 +1,8 @@
 import urllib.request
 import json
 import asyncio
-from random import randint
 from pyrogram import filters
-from wbb import app, arq
+from wbb import app
 from wbb.utils.errors import capture_err
 
 __MODULE__ = "Images"

+ 27 - 19
wbb/modules/inline.py

@@ -4,29 +4,27 @@ from wbb.utils.inlinefuncs import (
     alive_function, webss, shortify, wall_func,
     saavn_func, deezer_func, inline_help_func,
     torrent_func, youtube_func, lyrics_func,
-    paste_func
+    paste_func, eval_func
 )
 from pyrogram import filters
 
 __MODULE__ = "Inline"
-__HELP__ = '''```+===============================================================+
-|            Query            |           Function              |
-+===============================================================+
-|  alive                      |  Check Bot's Stats.             |
-|  tr [LANGUAGE_CODE] [QUERY] |  Translate Text.                |
-|  ud      [QUERY]            |  Urban Dictionary Query.        |
-|  google  [QUERY]            |  Google Search.                 |
-|  webss   [URL]              |  Take Screenshot Of A Website.  |
-|  bitly   [URL]              |  Shorten A Link.                |
-|  wall    [QUERY]            |  Find Wallpapers.               |
-|  saavn   [SONG_NAME]        |  Get Songs From Saavn.          |
-|  deezer  [SONG_NAME]        |  Get Songs From Deezer.         |
-|  yt      [Query]            |  Youtube Search.                |
-|  torrent [QUERY]            |  Torrent Search.                |
-|  lyrics  [QUERY]            |  Lyrics Search.                 |
-|  paste   [TEXT]             |  Pase Text On Pastebin. <=500   |
-+===============================================================+
-```'''
+__HELP__ = '''
+- alive - Check Bot's Stats.
+- tr [LANG] [QUERY] - Translate Text.
+- ud [QUERY] - Urban Dictionary Query.
+- google [QUERY] - Google Search.
+- webss [URL] - Take Screenshot Of A Website.
+- bitly [URL] - Shorten A Link.
+- wall [QUERY] - Find Wallpapers.
+- saavn [SONG_NAME] - Get Songs From Saavn.
+- deezer [SONG_NAME] - Get Songs From Deezer.
+- yt [Query] - Youtube Search.
+- torrent [QUERY] - Torrent Search.
+- lyrics [QUERY] - Lyrics Search.
+- eval [CODE] - Execute Python Code.
+- paste [TEXT] - Paste Text On Pastebin. <=500
+'''
 
 
 @app.on_message(filters.command("inline"))
@@ -150,5 +148,15 @@ async def inline_query_handler(client, query):
                 cache_time=2
             )
 
+        elif text.split()[0] == "eval":
+            user_id = query.from_user.id
+            tex = text.split(None, 1)[1]
+            answerss = await eval_func(answers, tex, user_id)
+            await client.answer_inline_query(
+                query.id,
+                results=answerss,
+                cache_time=2
+            )
+
     except (IndexError, TypeError, KeyError, ValueError):
         return

+ 1 - 1
wbb/modules/music.py

@@ -160,7 +160,7 @@ async def lyrics_func(_, message):
     if len(message.command) < 2:
         await message.reply_text("**Usage:**\n/lyrics [QUERY]")
         return
-    await message.reply_text("**Searching**")
+    m = await message.reply_text("**Searching**")
     query = message.text.strip().split(None, 1)[1]
     song = await arq.lyrics(query)
     lyrics = song.lyrics

+ 38 - 0
wbb/modules/userbot.py

@@ -149,3 +149,41 @@ async def shellrunner(client, message):
         await edit_or_reply(
             message,
             text=f'**INPUT:**\n```{text}```\n\n**OUTPUT: **\n`No output`')
+
+""" The code below is for inline eval"""
+
+
+async def aexec2(code, client):
+    exec(
+        "async def __aexecc(client): "
+        + "".join(f"\n {a}" for a in code.split("\n"))
+    )
+    return await locals()["__aexecc"](client)
+
+
+async def eval_executor_func(code):
+    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 aexec2(code, app)
+    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"**INPUT:**\n```{code}```\n\n**OUTPUT**:\n```{evaluation.strip()}```")
+    return final_output

+ 1 - 1
wbb/modules/webss.py

@@ -1,4 +1,4 @@
-from wbb import app, app2, SUDOERS
+from wbb import app
 from wbb.utils.errors import capture_err
 from wbb.utils.fetch import fetch
 from pyrogram import filters

+ 11 - 10
wbb/utils/functions.py

@@ -6,24 +6,25 @@ def generate_captcha():
     # Generate one letter
     def gen_letter():
         return chr(randint(65, 90))
-    
+
     def rndColor():
         return (randint(64, 255), randint(64, 255), randint(64, 255))
+
     def rndColor2():
         return (randint(32, 127), randint(32, 127), randint(32, 127))
-    
+
     # Generate a 4 letter word
     def gen_wrong_answer():
         word = ""
         for _ in range(4):
             word += gen_letter()
-        return word 
+        return word
 
     # Generate 7 wrong captcha answers
     wrong_answers = []
     for _ in range(7):
         wrong_answers.append(gen_wrong_answer())
-    
+
     width = 120 * 4
     height = 120
     correct_answer = ""
@@ -31,7 +32,7 @@ def generate_captcha():
     file = f"assets/{randint(1000, 9999)}.jpg"
     image = Image.new('RGB', (width, height), (255, 255, 255))
     draw = ImageDraw.Draw(image)
-    
+
     # Draw random points on image
     for x in range(width):
         for y in range(height):
@@ -41,11 +42,11 @@ def generate_captcha():
         letter = gen_letter()
         correct_answer += letter
         draw.text(
-                (120 * t + 32, 3),
-                letter,
-                font=font,
-                fill=rndColor2()
-                )
+            (120 * t + 32, 3),
+            letter,
+            font=font,
+            fill=rndColor2()
+        )
     image = image.filter(ImageFilter.BLUR)
     image.save(file, 'jpeg')
     return [file, correct_answer, wrong_answers]

+ 37 - 2
wbb/utils/inlinefuncs.py

@@ -1,6 +1,6 @@
 from wbb import (
     arq, app, app2, USERBOT_USERNAME,
-    BOT_USERNAME, LOG_GROUP_ID
+    BOT_USERNAME, LOG_GROUP_ID, USERBOT_ID
 )
 from pyrogram.types import (
     InlineQueryResultArticle,
@@ -11,6 +11,7 @@ from pyrogram.types import (
 from googletrans import Translator
 from search_engine_parser import GoogleSearch
 from time import time
+from wbb.modules.userbot import eval_executor_func
 from wbb.utils.fetch import fetch
 from wbb.utils.formatter import convert_seconds_to_minutes as time_convert
 from wbb.utils.pastebin import paste
@@ -344,7 +345,7 @@ async def youtube_func(answers, text):
 **Uploaded:** {results[i].publish_time}
 **Description:** {results[i].long_desc}"""
         description = f"{results[i].views} | {results[i].channel} | " \
-                       + f"{results[i].duration} | {results[i].publish_time}"
+            + f"{results[i].duration} | {results[i].publish_time}"
         try:
             answers.append(
                 InlineQueryResultArticle(
@@ -395,3 +396,37 @@ async def paste_func(answers, text):
             input_message_content=InputTextMessageContent(msg)
         ))
     return answers
+
+
+async def eval_func(answers, text, user_id):
+    if user_id != USERBOT_ID:
+        msg = "**ERROR**\n__THIS FEATURE IS ONLY FOR SUDO USERS__"
+        answers.append(
+            InlineQueryResultArticle(
+                title="ERROR",
+                description="THIS FEATURE IS ONLY FOR SUDO USERS",
+                input_message_content=InputTextMessageContent(msg)
+            ))
+        return answers
+    if str(text)[-1] != ":":
+        msg = "**ERROR**\n__Put A ':' After The Code To Execute It__"
+        answers.append(
+            InlineQueryResultArticle(
+                title="ERROR",
+                description="Put A ':' After The Code To Execute It",
+                input_message_content=InputTextMessageContent(msg)
+            ))
+
+        return answers
+    text = text[0:-1]
+    start_time = time()
+    result = await eval_executor_func(text)
+    msg = f"{result}"
+    end_time = time()
+    answers.append(
+        InlineQueryResultArticle(
+            title="Success",
+            description=f"Executed In {round(end_time - start_time)} Seconds.",
+            input_message_content=InputTextMessageContent(msg)
+        ))
+    return answers