Преглед на файлове

Added .anonymize and .impersonate

TheHamkerCat преди 5 години
родител
ревизия
937ab4f8e6
променени са 8 файла, в които са добавени 158 реда и са изтрити 42 реда
  1. 32 19
      wbb/core/keyboard.py
  2. 2 2
      wbb/modules/admin.py
  3. 101 0
      wbb/modules/anonymize.py
  4. 1 1
      wbb/modules/log.py
  5. 10 16
      wbb/modules/proxy.py
  6. 2 0
      wbb/modules/sudoers.py
  7. 6 4
      wbb/modules/userbot.py
  8. 4 0
      wbb/utils/functions.py

+ 32 - 19
wbb/core/keyboard.py

@@ -21,22 +21,35 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 SOFTWARE.
 """
-from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup
-
-from wbb.utils.functions import get_urls_from_text
-
-
-def btn(text, data, type=None):
-    type = "url" if get_urls_from_text(data) else "callback_data"
-    return InlineKeyboardButton(text, **{type: data})
-
-
-def ikb(keyboard: list):
-    lines = []
-    for row in keyboard:
-        line = []
-        for button in row:
-            button = btn(*button)  # InlineKeyboardButton
-            line.append(button)
-        lines.append(line)
-    return InlineKeyboardMarkup(inline_keyboard=lines)
+from pykeyboard import InlineKeyboard
+from pyrogram.types import InlineKeyboardButton as Ikb
+
+from wbb.utils.functions import get_urls_from_text as is_url
+
+
+def keyboard(buttons_list, row_width: int = 2):
+    """
+    Buttons builder, pass buttons in a list and it will
+    return pyrogram.types.IKB object
+    Ex: keyboard([["click here", "https://google.com"]])
+    if theres, a url, it will make url button, else callback button
+    """
+    buttons = InlineKeyboard(row_width=row_width)
+    data = [
+        (
+            Ikb(text=i[0], callback_data=i[1])
+            if not is_url(i[1])
+            else Ikb(text=i[0], url=i[1])
+        )
+        for i in buttons_list
+    ]
+    buttons.add(*data)
+    return buttons
+
+
+def ikb(data: dict, row_width: int = 2):
+    """
+    Converts a dict to pyrogram buttons
+    Ex: dict_to_keyboard({"click here": "this is callback data"})
+    """
+    return keyboard(data.items(), row_width=2)

+ 2 - 2
wbb/modules/admin.py

@@ -415,7 +415,7 @@ async def mute(_, message: Message):
         user_id, permissions=ChatPermissions()
     )
     mention = (await app.get_users(user_id)).mention
-    keyboard = ikb([[("🚨   Unmute   🚨", f"unmute_{user_id}")]])
+    keyboard = ikb({"🚨   Unmute   🚨": f"unmute_{user_id}"})
     msg = (
         f"**Muted User:** {mention}\n"
         f"**Muted By:** {message.from_user.mention if message.from_user else 'Anon'}\n"
@@ -522,7 +522,7 @@ async def warn_user(_, message: Message):
         get_warn(chat_id, await int_to_alpha(user_id)),
     )
     mention = user.mention
-    keyboard = ikb([[("🚨  Remove Warn  🚨", f"unwarn_{user_id}")]])
+    keyboard = ikb({"🚨  Remove Warn  🚨": f"unwarn_{user_id}"})
     if warns:
         warns = warns["warns"]
     else:

+ 101 - 0
wbb/modules/anonymize.py

@@ -0,0 +1,101 @@
+"""
+MIT License
+
+Copyright (c) 2021 TheHamkerCat
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+"""
+from asyncio import gather
+from io import BytesIO
+from json import loads
+from os import remove
+from random import choice
+from traceback import format_exc
+
+from pyrogram import filters
+from pyrogram.types import Chat, Message
+
+from wbb import LOG_GROUP_ID, SUDOERS, USERBOT_ID, USERBOT_PREFIX
+from wbb import aiohttpsession as session
+from wbb import app, app2
+from wbb.modules.userbot import edit_or_reply as eor
+from wbb.utils.functions import extract_user
+
+
+@app2.on_message(
+    filters.command("anonymize", prefixes=USERBOT_PREFIX)
+    & filters.user(SUDOERS)
+)
+async def change_profile(_, message: Message):
+    m = await eor(message, text="Anonymizing...")
+    try:
+        image_resp, name_resp = await gather(
+            session.get("https://thispersondoesnotexist.com/image"),
+            session.get(
+                "https://raw.githubusercontent.com/dominictarr/"
+                + "random-name/master/first-names.json"
+            ),
+        )
+        image = BytesIO(await image_resp.read())
+        image.name = "a.png"
+        name = choice(loads(await name_resp.text()))
+        await gather(
+            app2.set_profile_photo(photo=image),
+            app2.update_profile(first_name=name),
+        )
+    except Exception as e:
+        e = format_exc()
+        err = await app.send_message(LOG_GROUP_ID, text=f"`{e}`")
+        return await m.edit(f"**Error**: {err.link}")
+    await m.edit(f"[Anonymized.](tg://user?id={USERBOT_ID})")
+
+
+@app2.on_message(
+    filters.command("impersonate", prefixes=USERBOT_PREFIX)
+    & filters.user(SUDOERS)
+)
+async def impersonate(_, message: Message):
+    user_id = await extract_user(message)
+
+    if not user_id:
+        return await eor(
+            message, text="Can't impersonate an anonymous user."
+        )
+    if user_id == USERBOT_ID:
+        return eor(message, text="Can't impersonate myself.")
+
+    m = await eor(message, text="Processing...")
+
+    try:
+        user: Chat = await app2.get_chat(user_id)
+        fname = user.first_name
+        lname = user.last_name or ""
+        bio = user.bio or ""
+        pfp, _ = await gather(
+            app2.download_media(user.photo.big_file_id),
+            app2.update_profile(fname, lname, bio),
+        )
+        await app2.set_profile_photo(photo=pfp)
+        remove(pfp)
+    except Exception as e:
+        e = format_exc()
+        err = await app.send_message(LOG_GROUP_ID, text=f"`{e}`")
+        return await m.edit(f"**Error**: {err.link}")
+
+    await m.edit(f"[Done](tg://user?id={USERBOT_ID})")

+ 1 - 1
wbb/modules/log.py

@@ -13,7 +13,7 @@ callback = "log_paste"
 
 @app.on_message(filters.command("logs") & filters.user(SUDOERS))
 async def logs_chat(_, message):
-    keyboard = ikb([[("📎   Pastebin   📎", callback)]])
+    keyboard = ikb({"📎   Pastebin   📎": callback})
     time = (datetime.now()).strftime("%d/%m/%Y %H:%M:%S")
     caption = f"""
 **Time:** `{time}`

+ 10 - 16
wbb/modules/proxy.py

@@ -42,13 +42,11 @@ async def proxy_func(_, message: Message):
     proxy = proxies[0].proxy
     url = url_from_proxy(proxy)
     keyb = ikb(
-        [
-            [("Connect", url)],
-            [
-                ("←", "proxy_arq_-1"),
-                ("→", "proxy_arq_1"),
-            ],
-        ]
+        {
+            "←": "proxy_arq_-1",
+            "→": "proxy_arq_1",
+            "Connect": url,
+        }
     )
     await message.reply_text(
         f"""
@@ -69,15 +67,11 @@ async def proxy_callback_func(_, cq: CallbackQuery):
     proxy = proxies[index].proxy
     url = url_from_proxy(proxy)
     keyb = ikb(
-        [
-            [
-                ("Connect", url),
-            ],
-            [
-                ("←", f"proxy_arq_{index-1}"),
-                ("→", f"proxy_arq_{index+1}"),
-            ],
-        ]
+        {
+            "←": f"proxy_arq_{index-1}",
+            "→": f"proxy_arq_{index+1}",
+            "Connect": url,
+        }
     )
     await cq.message.edit(
         f"""

+ 2 - 0
wbb/modules/sudoers.py

@@ -47,6 +47,8 @@ __HELP__ = """
 /clean_db - Clean database.
 /broadcast - To Broadcast A Message To All Groups.
 /update - To Update And Restart The Bot
+.anonymize - Change Name/PFP Randomly.
+.impersonate [User_ID|Username|Reply] - Clone profile of a user.
 """
 
 # Stats Module

+ 6 - 4
wbb/modules/userbot.py

@@ -52,7 +52,9 @@ async def aexec(code, 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})
+    return await func(
+        **{k: v for k, v in kwargs.items() if k in spec}
+    )
 
 
 @app2.on_message(
@@ -125,7 +127,7 @@ async def shellrunner(client, message: Message):
         return await edit_or_reply(
             message, text="**Usage:**\n/sh git pull"
         )
-    
+
     if message.reply_to_message:
         r = message.reply_to_message
         if r.reply_markup:
@@ -234,7 +236,7 @@ async def sendFile(message: Message, text: str):
 async def c_cpp_eval(_, message: Message):
     if len(message.command) < 2:
         return await message.edit("Write Some Code..")
-    
+
     if message.reply_to_message:
         r = message.reply_to_message
         if r.reply_markup:
@@ -277,7 +279,7 @@ async def c_cpp_eval(_, message: Message):
 async def goval(_, message: Message):
     if len(message.command) < 2:
         return await message.edit("Write Some Code...")
-    
+
     if message.reply_to_message:
         r = message.reply_to_message
         if r.reply_markup:

+ 4 - 0
wbb/utils/functions.py

@@ -212,6 +212,10 @@ async def time_converter(message: Message, time_value: str) -> int:
 
 
 async def extract_userid(message, text: str):
+    """
+    NOT TO BE USED OUTSIDE THIS FILE
+    """
+
     def is_int(text: str):
         try:
             int(text)