Просмотр исходного кода

Fixed shit (#114)

- Fix /tmute (it used to mute the user even with incorrect time like /tmute 3y)
- Blacklisted words will only mute for 1h now instead of forever.
- Added .id,  .paste, .help in userbot
- Fixed karma leaderboard
- Moved userbot commands help to telegraph
- Added /telegraph command to bot.
Akshay Rajput 5 лет назад
Родитель
Сommit
e23e0b0400
8 измененных файлов с 139 добавлено и 71 удалено
  1. 1 0
      requirements.txt
  2. 4 0
      wbb/__init__.py
  3. 0 1
      wbb/modules/admin.py
  4. 9 5
      wbb/modules/blacklist.py
  5. 1 1
      wbb/modules/karma.py
  6. 29 8
      wbb/modules/paste.py
  7. 68 56
      wbb/modules/purge_me.py
  8. 27 0
      wbb/modules/telegraph.py

+ 1 - 0
requirements.txt

@@ -23,3 +23,4 @@ feedparser
 pyromod
 pyromod
 fuzzysearch
 fuzzysearch
 img2pdf
 img2pdf
+telegraph

+ 4 - 0
wbb/__init__.py

@@ -33,6 +33,7 @@ from pyrogram import Client
 from pyrogram.types import Message
 from pyrogram.types import Message
 from pyromod import listen
 from pyromod import listen
 from Python_ARQ import ARQ
 from Python_ARQ import ARQ
+from telegraph import Telegraph
 
 
 is_config = path.exists("config.py")
 is_config = path.exists("config.py")
 
 
@@ -118,6 +119,9 @@ USERBOT_DC_ID = y.dc_id
 if USERBOT_ID not in SUDOERS:
 if USERBOT_ID not in SUDOERS:
     SUDOERS.append(USERBOT_ID)
     SUDOERS.append(USERBOT_ID)
 
 
+telegraph = Telegraph()
+telegraph.create_account(short_name=BOT_USERNAME)
+
 
 
 async def eor(msg: Message, **kwargs):
 async def eor(msg: Message, **kwargs):
     func = msg.edit_text if msg.from_user.is_self else msg.reply
     func = msg.edit_text if msg.from_user.is_self else msg.reply

+ 0 - 1
wbb/modules/admin.py

@@ -416,7 +416,6 @@ async def mute(_, message: Message):
         return await message.reply_text(
         return await message.reply_text(
             "I can't mute an admin, You know the rules, so do i."
             "I can't mute an admin, You know the rules, so do i."
         )
         )
-    await message.chat.restrict_member(user_id, permissions=ChatPermissions())
     mention = (await app.get_users(user_id)).mention
     mention = (await app.get_users(user_id)).mention
     keyboard = ikb({"🚨   Unmute   🚨": f"unmute_{user_id}"})
     keyboard = ikb({"🚨   Unmute   🚨": f"unmute_{user_id}"})
     msg = (
     msg = (

+ 9 - 5
wbb/modules/blacklist.py

@@ -22,6 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 SOFTWARE.
 SOFTWARE.
 """
 """
 import re
 import re
+from time import time
 
 
 from pyrogram import filters
 from pyrogram import filters
 from pyrogram.types import ChatPermissions
 from pyrogram.types import ChatPermissions
@@ -111,12 +112,15 @@ async def blacklist_filters_re(_, message):
             if user.id in await list_admins(chat_id):
             if user.id in await list_admins(chat_id):
                 return
                 return
             try:
             try:
-                await message.chat.restrict_member(user.id, ChatPermissions())
+                await message.chat.restrict_member(
+                    user.id,
+                    ChatPermissions(),
+                    until_date=(time() + 3600),
+                )
             except Exception:
             except Exception:
                 return
                 return
-            await app.send_message(
+            return await app.send_message(
                 chat_id,
                 chat_id,
-                f"Muted {user.mention} [`{user.id}`] due to a blacklist "
-                + f"match on {word}.",
+                f"Muted {user.mention} [`{user.id}`] for 1 hour "
+                + f"due to a blacklist match on {word}.",
             )
             )
-            return

+ 1 - 1
wbb/modules/karma.py

@@ -159,7 +159,7 @@ async def command_karma(_, message):
             if int(user_idd) not in list(userdb.keys()):
             if int(user_idd) not in list(userdb.keys()):
                 continue
                 continue
             username = userdb[int(user_idd)]
             username = userdb[int(user_idd)]
-            karma[karma_count] = ["@" + username]
+            karma["@" + username] = ["**" + str(karma_count) + "**"]
             limit += 1
             limit += 1
         await m.edit(section(msg, karma))
         await m.edit(section(msg, karma))
     else:
     else:

+ 29 - 8
wbb/modules/paste.py

@@ -26,8 +26,9 @@ import re
 
 
 import aiofiles
 import aiofiles
 from pyrogram import filters
 from pyrogram import filters
+from pyrogram.types import Message
 
 
-from wbb import app
+from wbb import SUDOERS, USERBOT_PREFIX, app, app2, eor
 from wbb.core.decorators.errors import capture_err
 from wbb.core.decorators.errors import capture_err
 from wbb.core.keyboard import ikb
 from wbb.core.keyboard import ikb
 from wbb.utils.pastebin import paste
 from wbb.utils.pastebin import paste
@@ -37,34 +38,54 @@ __HELP__ = "/paste - To Paste Replied Text Or Document To A Pastebin"
 pattern = re.compile(r"^text/|json$|yaml$|xml$|toml$|x-sh$|x-shellscript$")
 pattern = re.compile(r"^text/|json$|yaml$|xml$|toml$|x-sh$|x-shellscript$")
 
 
 
 
+@app2.on_message(
+    filters.command("paste", prefixes=USERBOT_PREFIX) & filters.user(SUDOERS)
+)
 @app.on_message(filters.command("paste") & ~filters.edited)
 @app.on_message(filters.command("paste") & ~filters.edited)
 @capture_err
 @capture_err
-async def paste_func(_, message):
+async def paste_func(_, message: Message):
     if not message.reply_to_message:
     if not message.reply_to_message:
-        return await message.reply("Reply To A Message With /paste")
+        return await eor(message, text="Reply To A Message With /paste")
     r = message.reply_to_message
     r = message.reply_to_message
 
 
     if not r.text and not r.document:
     if not r.text and not r.document:
-        return await message.reply("Only text and documents are supported.")
+        return await eor(
+            message, text="Only text and documents are supported."
+        )
 
 
-    m = await message.reply("Pasting...")
+    m = await eor(message, text="Pasting...")
 
 
     if r.text:
     if r.text:
         content = str(r.text)
         content = str(r.text)
     elif r.document:
     elif r.document:
         if r.document.file_size > 40000:
         if r.document.file_size > 40000:
             return await m.edit("You can only paste files smaller than 40KB.")
             return await m.edit("You can only paste files smaller than 40KB.")
+
         if not pattern.search(r.document.mime_type):
         if not pattern.search(r.document.mime_type):
             return await m.edit("Only text files can be pasted.")
             return await m.edit("Only text files can be pasted.")
+
         doc = await message.reply_to_message.download()
         doc = await message.reply_to_message.download()
+
         async with aiofiles.open(doc, mode="r") as f:
         async with aiofiles.open(doc, mode="r") as f:
             content = await f.read()
             content = await f.read()
+
         os.remove(doc)
         os.remove(doc)
 
 
     link = await paste(content)
     link = await paste(content)
     kb = ikb({"Paste Link": link})
     kb = ikb({"Paste Link": link})
     try:
     try:
-        await message.reply_photo(photo=link, quote=False, reply_markup=kb)
+        if m.from_user.is_bot:
+            await message.reply_photo(
+                photo=link,
+                quote=False,
+                reply_markup=kb,
+            )
+        else:
+            await message.reply_photo(
+                photo=link,
+                quote=False,
+                caption=f"**Paste Link:** [Here]({link})",
+            )
+        await m.delete()
     except Exception:
     except Exception:
-        await message.reply("Here's your paste", reply_markup=kb)
-    await m.delete()
+        await m.edit("Here's your paste", reply_markup=kb)

+ 68 - 56
wbb/modules/purge_me.py

@@ -25,65 +25,77 @@ SOFTWARE.
 from pyrogram import filters
 from pyrogram import filters
 from pyrogram.types import Message
 from pyrogram.types import Message
 
 
-from wbb import USERBOT_ID, USERBOT_PREFIX, app2, eor
+from wbb import USERBOT_ID, USERBOT_PREFIX, app2, eor, telegraph
 
 
-# Yeah i know this should've been in userbot.py,
-# But i wrote it here for some obvious reasons.
 __MODULE__ = "Userbot"
 __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
-
-`.eval [Lines of code]`
-        Execute Python Code.
-`.lsTasks`
-        List running tasks (eval)
-`.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.
-
-`.download [URL or reply to a file]`
-        Download a file from TG or URL
-`.upload [URL or File Path]`
-        Upload a file from local or URL
-
-`.parse_preview [REPLY TO A MESSAGE]`
-        Parse a web_page(link) preview
+TEXT = """
+<code>alive</code>  →  Send Alive Message.<br>
+
+<code>create (b|s|c) Title</code>  →  create [basic|super]group & channel<br>
+
+<code>chatbot [ENABLE|DISABLE]</code>  →  Enable chatbot in a chat.<br>
+
+<code>autocorrect [ENABLE|DISABLE]</code>  →  This will autocorrect your messages on the go.<br>
+
+<code>purgeme [Number of messages to purge]</code>  →  Purge your own messages.<br>
+
+<code>eval [Lines of code]</code>  →  Execute Python Code.<br>
+
+<code>lsTasks</code>  →  List running tasks (eval)<br>
+
+<code>sh [Some shell code]</code>  →  Execute Shell Code.<br>
+
+<code>approve</code>  →  Approve a user to PM you.<br>
+
+<code>disapprove</code>  →  Disapprove a user to PM you.<br>
+
+<code>block</code>  →  Block a user.<br>
+
+<code>unblock</code>  →  Unblock a user.<br>
+
+<code>anonymize</code>  →  Change Name/PFP Randomly.<br>
+
+<code>impersonate [User_ID|Username|Reply]</code> → Clone profile of a user.<br>
+
+<code>useradd</code>  →  To add a user in sudoers. [UNSAFE]<br>
+
+<code>userdel</code>  → To remove a user from sudoers.<br>
+
+<code>sudoers</code>  →  To list sudo users.<br>
+
+<code>download [URL or reply to a file]</code>  →  Download a file from TG or URL<br>
+
+<code>upload [URL or File Path]</code>  →  Upload a file from local or URL<br>
+
+<code>parse_preview [REPLY TO A MESSAGE]</code>  →  Parse a web_page(link) preview<br>
+
+<code>id</code>  →  Same as /id but for Ubot<br>
+
+<code>paste</code> → Paste shit on batbin.<br>
+
+<code>help</code> → Get link to this page.
+
+<code>kang</code> → Kang stickers.
 """
 """
+print("[INFO]: Pasting userbot commands on telegraph")
+
+__HELP__ = f"""**Commands:** {telegraph.create_page(
+        "Userbot Commands",
+        html_content=TEXT,
+    )['url']}"""
+
+print("[INFO]: Done pasting userbot commands on telegraph")
+
+
+@app2.on_message(
+    filters.command("help", prefixes=USERBOT_PREFIX) & filters.user(USERBOT_ID)
+)
+async def get_help(_, message: Message):
+    await eor(
+        message,
+        text=__HELP__,
+        disable_web_page_preview=True,
+    )
 
 
 
 
 @app2.on_message(
 @app2.on_message(

+ 27 - 0
wbb/modules/telegraph.py

@@ -0,0 +1,27 @@
+from pyrogram import filters
+from pyrogram.types import Message
+
+from wbb import app, telegraph
+from wbb.core.decorators.errors import capture_err
+
+__MODULE__ = "Telegraph"
+__HELP__ = "/telegraph [Page name]: Paste styled text on telegraph."
+
+
+@app.on_message(filters.command("telegraph"))
+@capture_err
+async def paste(_, message: Message):
+    reply = message.reply_to_message
+
+    if not reply or not reply.text:
+        return await message.reply("Reply to a text message")
+
+    if len(message.command) < 2:
+        return await message.reply("**Usage:**\n /telegraph [Page name]")
+
+    page_name = message.text.split(None, 1)[1]
+    page = telegraph.create_page(page_name, html_content=reply.text.html)
+    return await message.reply(
+        f"**Posted:** {page['url']}",
+        disable_web_page_preview=True,
+    )