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

Updates

* Moved some module help pages, check userbot module help.
* Added a .purgeme [N] command
* Added /get_sticker command
TheHamkerCat преди 5 години
родител
ревизия
64939dfd7f
променени са 9 файла, в които са добавени 257 реда и са изтрити 66 реда
  1. 22 13
      wbb/modules/admin.py
  2. 0 9
      wbb/modules/autocorrect.py
  3. 3 1
      wbb/modules/chatbot.py
  4. 1 2
      wbb/modules/devs.py
  5. 49 15
      wbb/modules/misc.py
  6. 123 0
      wbb/modules/purge_me.py
  7. 50 14
      wbb/modules/stickers.py
  8. 9 2
      wbb/modules/sudoers.py
  9. 0 10
      wbb/modules/userbot.py

+ 22 - 13
wbb/modules/admin.py

@@ -145,29 +145,38 @@ async def list_members(group_id):
 )
 @adminsOnly("can_delete_messages")
 async def purgeFunc(client, message: Message):
-    chat_id = message.chat.id
-    message_ids = []
-    if message.chat.type not in ("supergroup", "channel"):
-        return
+    await message.delete()
+
     if not message.reply_to_message:
         return await message.reply_text(
-            "Reply to a message to delete from, don't make fun of yourself!"
+            "Reply to a message to purge from."
         )
-    await message.delete()
-    for a_s_message_id in range(
-        message.reply_to_message.message_id, message.message_id
+
+    message_ids = []
+
+    for message_id in range(
+        message.reply_to_message.message_id,
+        message.message_id,
     ):
-        message_ids.append(a_s_message_id)
+        message_ids.append(message_id)
+
+        # Max message deletion limit is 100
         if len(message_ids) == 100:
-            await client.delete_messages(
+            await app.delete_messages(
                 chat_id=chat_id,
                 message_ids=message_ids,
-                revoke=True,
+                revoke=True,  # For both sides
             )
+
+            # To delete more than 100 messages, start again
             message_ids = []
+
+    # Delete if any messages left
     if len(message_ids) > 0:
-        await client.delete_messages(
-            chat_id=chat_id, message_ids=message_ids, revoke=True
+        await app.delete_messages(
+            chat_id=chat_id,
+            message_ids=message_ids,
+            revoke=True,
         )
 
 

+ 0 - 9
wbb/modules/autocorrect.py

@@ -4,15 +4,6 @@ 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):

+ 3 - 1
wbb/modules/chatbot.py

@@ -35,7 +35,9 @@ from wbb.utils.filter_groups import chatbot_group
 __MODULE__ = "ChatBot"
 __HELP__ = """
 /chatbot [ENABLE|DISABLE] To Enable Or Disable ChatBot In Your Chat.
-.chatbot [ENABLE|DISABLE] To Do The Same For Userbot."""
+
+There's one module of this available for userbot also
+check userbot module help."""
 
 active_chats_bot = []
 active_chats_ubot = []

+ 1 - 2
wbb/modules/devs.py

@@ -20,8 +20,7 @@ from pyrogram.types import (InlineKeyboardButton,
 
 from wbb import SUDOERS, app
 
-__MODULE__ = "Devs"
-__HELP__ = "/eval - Execute Python Code\n/sh - Execute Shell Code"
+# Module help for this is in sudoers.py
 
 
 async def aexec(code, client, message):

+ 49 - 15
wbb/modules/misc.py

@@ -38,21 +38,55 @@ from wbb.utils.pastebin import paste
 
 __MODULE__ = "Misc"
 __HELP__ = """
-/asq - Ask a question
-/commit - Generate Funny Commit Messages
-/runs  - Idk Test Yourself
-/id - Get Chat_ID or User_ID
-/random [Length] - Generate Random Complex Passwords
-/encrypt - Encrypt Text [Can Only Be Decrypted By This Bot]
-/decrypt - Decrypt Text
-/cheat [Language] [Query] - Get Programming Related Help
-/tr [en] - Translate A Message
-/json [URL] - Get JSON Response From An API or Something.
-/arq - Statistics Of ARQ API.
-/webss [URL] - Take A Screenshot Of A Webpage
-/reverse - Reverse search an image.
-/carbon - Make Carbon from code.
-/tts - Convert Text To Speech.
+/asq
+    Ask a question
+
+/commit
+    Generate Funny Commit Messages
+
+/runs
+    Idk Test Yourself
+
+/id
+    Get Chat_ID or User_ID
+
+/random [Length]
+    Generate Random Complex Passwords
+
+/encrypt
+    Encrypt Text [Can Only Be Decrypted By This Bot]
+
+/decrypt
+    Decrypt Text
+
+/cheat [Language] [Query]
+    Get Programming Related Help
+
+/tr [LANGUAGE_CODE]
+    Translate A Message
+    Ex: /tr en
+
+/json [URL]
+    Get parsed JSON response from a rest API.
+
+/arq
+    Statistics Of ARQ API.
+
+/webss [URL]
+    Take A Screenshot Of A Webpage
+
+/reverse
+    Reverse search an image.
+
+/carbon
+    Make Carbon from code.
+
+/tts
+    Convert Text To Speech.
+
+/autocorrect [Reply to a message]
+    Autocorrects the text in replied message.
+
 #RTFM - Tell noobs to read the manual
 """
 

+ 123 - 0
wbb/modules/purge_me.py

@@ -0,0 +1,123 @@
+"""
+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 pyrogram import filters
+from pyrogram.types import Message
+
+from wbb import USERBOT_ID, USERBOT_PREFIX, app2
+
+# Yeah i know this should've been in userbot.py,
+# But i wrote it here for some obvious reasons.
+__MODULE__ = "Userbot"
+__HELP__ = """
+`.alive`
+    Send Alive Message.
+
+`.create (b|s|c) Title`
+        create [basic|super]group & channel
+
+`.chatbot [ENABLE|DISABLE]`
+        Enable chatbot in a chat.
+
+`.autocorrect [ENABLE|DISABLE]`
+        This will autocorrect your messages on the go.
+
+`.purgeme [Number of messages to purge]`
+        Purge your own messages. 
+        Ex: .purgeme 10
+
+`.py [Lines of code]`
+        Execute Python Code.
+`.sh [Some shell code]`
+        Execute Shell Code.
+
+`.approve`
+        Approve a user to PM you.
+`.disapprove`
+        Disapprove a user to PM you.
+`.block`
+        Block a user.
+`.unblock`
+        Unblock a user.
+
+`.anonymize`
+        Change Name/PFP Randomly.
+`.impersonate [User_ID|Username|Reply]`
+        Clone profile of a user.
+
+`.useradd`
+        To add a user in sudoers. 
+        [Don't use it if you don't know what you're doing]
+`.userdel`
+        To remove a user from sudoers.
+`.sudoers`
+        To list sudo users.
+"""
+
+
+@app2.on_message(
+    filters.command("purgeme", prefixes=USERBOT_PREFIX)
+    & filters.user(USERBOT_ID)
+)
+async def purge_me_func(_, message: Message):
+    if len(message.command) != 2:
+        return await message.delete()
+
+    n = message.text.split(None, 1)[1].strip()
+    if not n.isnumeric():
+        return await message.delete()
+
+    n = int(n)
+    if n < 1:
+        return await message.delete()
+
+    chat_id = message.chat.id
+
+    message_ids = [
+        m.message_id
+        async for m in app2.search_messages(
+            chat_id, limit=n, from_user=USERBOT_ID
+        )
+    ]
+
+    if len(message_ids) == 0:
+        return await message.delete()
+
+    # A list containing lists of 100 message chunks
+    # because we can't delete more than 100 messages at once,
+    # we have to do it in chunks of 100, i'll choose 99 just
+    # to be safe.
+    to_delete = list(
+        (
+            message_ids[i : i + 99]
+            for i in range(0, len(message_ids), 99)
+        )
+    )
+
+    for hundred_messages_or_less in to_delete:
+        await app2.delete_messages(
+            chat_id=chat_id,
+            message_ids=hundred_messages_or_less,
+            revoke=True,
+        )

+ 50 - 14
wbb/modules/stickers.py

@@ -23,13 +23,16 @@ SOFTWARE.
 """
 import imghdr
 import os
+from asyncio import gather
 from traceback import format_exc
 
 from pyrogram import filters
-from pyrogram.errors.exceptions.bad_request_400 import (
-    PeerIdInvalid, ShortnameOccupyFailed, StickerEmojiInvalid,
-    StickerPngDimensions, StickerPngNopng, UserIsBlocked)
-from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup
+from pyrogram.errors import (PeerIdInvalid, ShortnameOccupyFailed,
+                             StickerEmojiInvalid,
+                             StickerPngDimensions, StickerPngNopng,
+                             UserIsBlocked)
+from pyrogram.types import (InlineKeyboardButton,
+                            InlineKeyboardMarkup, Message)
 
 from wbb import BOT_USERNAME, app
 from wbb.core.decorators.errors import capture_err
@@ -41,8 +44,13 @@ from wbb.utils.stickerset import (add_sticker_to_set, create_sticker,
                                   get_sticker_set_by_name)
 
 __MODULE__ = "Stickers"
-__HELP__ = """/sticker_id - To Get File ID of A Sticker.
-/kang - To Kang A Sticker or Image."""
+__HELP__ = """
+/sticker_id
+    To get FileID of a Sticker.
+/get_sticker
+    To get sticker as a photo and document.
+/kang
+    To kang a Sticker or an Image."""
 
 MAX_STICKERS = 120  # would be better if we could fetch this limit directly from telegram
 SUPPORTED_TYPES = ["jpeg", "png", "webp"]
@@ -50,18 +58,46 @@ SUPPORTED_TYPES = ["jpeg", "png", "webp"]
 
 @app.on_message(filters.command("sticker_id") & ~filters.edited)
 @capture_err
-async def sticker_id(_, message):
-    if not message.reply_to_message:
-        return await message.reply_text("Reply to a sticker.")
-    if not message.reply_to_message.sticker:
-        return await message.reply_text("Reply to a sticker.")
-    file_id = message.reply_to_message.sticker.file_id
-    await message.reply_text(f"`{file_id}`")
+async def sticker_id(_, message: Message):
+    reply = message.reply_to_message
+
+    if not reply:
+        return await message.reply("Reply to a sticker.")
+
+    if not reply.sticker:
+        return await message.reply("Reply to a sticker.")
+
+    await message.reply_text(f"`{reply.sticker.file_id}`")
+
+
+@app.on_message(filters.command("get_sticker") & ~filters.edited)
+@capture_err
+async def sticker_image(_, message: Message):
+    r = message.reply_to_message
+
+    if not r:
+        return await message.reply("Reply to a sticker.")
+
+    if not r.sticker:
+        return await message.reply("Reply to a sticker.")
+
+    m = await message.reply("Sending..")
+    f = await r.download(f"{r.sticker.file_unique_id}.png")
+
+    await gather(
+        *[
+            message.reply_photo(f),
+            message.reply_document(f),
+        ]
+    )
+
+    await m.delete()
+    os.remove(f)
 
 
 @app.on_message(filters.command("kang") & ~filters.edited)
 @capture_err
-async def kang(client, message):
+async def kang(client, message: Message):
     if not message.reply_to_message:
         return await message.reply_text(
             "Reply to a sticker/image to kang it."

+ 9 - 2
wbb/modules/sudoers.py

@@ -42,13 +42,20 @@ from wbb.utils.functions import (extract_user,
 __MODULE__ = "Sudoers"
 __HELP__ = """
 /stats - To Check System Status.
+
 /gstats - To Check Bot's Global Stats.
+
 /gban - To Ban A User Globally.
+
 /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.
+
+/eval - Execute Python Code
+
+/sh - Execute Shell Code
 """
 
 # Stats Module

+ 0 - 10
wbb/modules/userbot.py

@@ -21,16 +21,6 @@ from wbb import app  # don't remove
 from wbb import SUDOERS, USERBOT_PREFIX, app2, arq
 from wbb.core.decorators.misc import exec_time
 
-__MODULE__ = "Userbot"
-__HELP__ = """
-.alive - Send Alive Message.
-.py - Execute Python Code.
-.sh - Execute Shell Code.
-.approve | .disapprove - Approve Or Disapprove A User To PM You.
-.block | .unblock - Block Or Unblock A User.
-.create (b|s|c) Name - create [basic|super]group & channel
-"""
-
 # Eval and Sh module from nana-remix
 
 m = None