Bladeren bron

Gban, gstats and some other fixes

Co-authored-by: Cypher Izumi <85168398+IzumiCypherX@users.noreply.github.com>
Co-authored-by: iamajneya <87112487+iamajneya@users.noreply.github.com>
TheHamkerCat 5 jaren geleden
bovenliggende
commit
acb2b3ec9d

+ 1 - 1
README.md

@@ -11,7 +11,7 @@
 ![Repository Size](https://img.shields.io/github/repo-size/thehamkercat/WilliamButcherBot?style=for-the-badge&logo=appveyor)
 
 
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;![Python Version](https://img.shields.io/badge/python-3.8-green?style=for-the-badge&logo=appveyor)&nbsp;
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;![Python Version](https://img.shields.io/badge/python-3.9-green?style=for-the-badge&logo=appveyor)&nbsp;
 ![Issues](https://img.shields.io/github/issues/thehamkercat/WilliamButcherBot?style=for-the-badge&logo=appveyor)&nbsp;
 ![Forks](https://img.shields.io/github/forks/thehamkercat/WilliamButcherBot?style=for-the-badge&logo=appveyor)&nbsp;
 ![Stars](https://img.shields.io/github/stars/thehamkercat/WilliamButcherBot?style=for-the-badge&logo=appveyor)

+ 7 - 6
app.json

@@ -11,12 +11,8 @@
     "telegram-bot",
     "pyrogram"
     ],
+    "repository": "https://github.com/TheHamkerCat/WilliamButcherBot",
     "stack": "container",
-    "buildpacks": [
-        {
-            "url": "heroku/python"
-        }     
-    ],
     "env": {
         "BOT_TOKEN": {
             "description": "Obtain a Telegram bot token by contacting @BotFather",
@@ -82,7 +78,12 @@
         },
         "RSS_DELAY": {
             "description": "Delay in which RSS will send updates in chat",
-            "value": 300,
+            "value": "300",
+            "required": true
+        },
+        "PM_PERMIT":{
+            "description": "Pm permit, fill 1 to enable or 0 to disable it.",
+            "value": "1",
             "required": true
         }
     }

+ 2 - 0
sample_config.env

@@ -31,3 +31,5 @@ ARQ_API_KEY=your_api_key # Get it from @ARQRobot
 LOG_MENTIONS=0 # Make It 1 if you want to enable it
 
 RSS_DELAY=300 # In seconds
+
+PM_PERMIT=1 # fill 0 to disable it

+ 4 - 2
sample_config.py

@@ -29,16 +29,17 @@ if HEROKU:
     ARQ_API_KEY = environ.get("ARQ_API_KEY", None)
     LOG_MENTIONS = bool(int(environ.get("LOG_MENTIONS", None)))
     RSS_DELAY = int(environ.get("RSS_DELAY", None))
+    PM_PERMIT = bool(int(environ.get("PM_PERMIT", None)))
 else:
     BOT_TOKEN = "467677575:YZfaakjwd545dfg-N6JStihhuw5gQeZHntc"
     API_ID = 123456
     API_HASH = "dfxcgs5s12hdcxfgdfz"
     USERBOT_PREFIX = "."
-    PHONE_NUMBER = "+916969696969"  # Need for Helper Userbot
+    PHONE_NUMBER = "+916969696969"  # Need for Userbot
     SUDO_USERS_ID = [
         4543744343,
         543214651351,
-    ]  # Sudo users have full access to everythin, don't trust anyone
+    ]  # Sudo users have full access to everything, don't trust anyone
     LOG_GROUP_ID = -100125431255
     GBAN_LOG_GROUP_ID = -100125431255
     MESSAGE_DUMP_CHAT = -1001181696437
@@ -49,3 +50,4 @@ else:
     ARQ_API_URL = "https://thearq.tech"
     LOG_MENTIONS = True
     RSS_DELAY = 300  # In seconds
+    PM_PERMIT = True

+ 2 - 2
wbb/core/sections.py

@@ -4,7 +4,7 @@ def section(
     text = f"**--{title}**--:\n" if underline else f"**{title}**:\n"
     for key, value in body.items():
         if not isinstance(value, list):
-            text += f"{' ' * indent}**{key}:** `{value}`\n"
+            text += f"{' ' * indent}`→` **{key}:** `{value}`\n"
         else:
-            text += f"{' ' * indent}**{key}:** {value[0]}\n"
+            text += f"{' ' * indent}`→` **{key}:** {value[0]}\n"
     return text

+ 31 - 18
wbb/modules/global_stats.py

@@ -24,6 +24,7 @@ SOFTWARE.
 import asyncio
 
 from pyrogram import filters
+from pyrogram.errors import FloodWait
 
 from wbb import BOT_ID, BOT_NAME, SUDOERS, app
 from wbb.core.decorators.errors import capture_err
@@ -40,36 +41,48 @@ from wbb.utils.inlinefuncs import keywords_list
 
 
 @app.on_message(
-    filters.command("gstats")
+    filters.command("clean_db")
     & filters.user(SUDOERS)
     & ~filters.edited
 )
 @capture_err
-async def global_stats(_, message):
-    m = await app.send_message(
-        message.chat.id,
-        text="__**Analysing Stats**__",
-        disable_web_page_preview=True,
-    )
-
-    # For bot served chat and users count
-    served_chats = []
-    chats = await get_served_chats()
-    for chat in chats:
-        served_chats.append(int(chat["chat_id"]))
-    await m.edit(
-        f"__**Generating Statistics Report, Should Take {len(served_chats)*2}+ Seconds.**__",
-        disable_web_page_preview=True,
+async def clean_db(_, message):
+    served_chats = [
+        int(i["chat_id"]) for i in (await get_served_chats())
+    ]
+    m = await message.reply(
+        f"__**Cleaning database, Might take around {len(served_chats)*2} seconds.**__",
     )
     for served_chat in served_chats:
         try:
             await app.get_chat_members(served_chat, BOT_ID)
             await asyncio.sleep(2)
+        except FloodWait as e:
+            await asyncio.sleep(int(e.x))
         except Exception:
             await remove_served_chat(served_chat)
             served_chats.remove(served_chat)
             pass
-    served_users = await get_served_users()
+    await m.edit("**Database Cleaned.**")
+    # TODO Add shit to clean filters, notes and other things of left chats.
+
+
+@app.on_message(
+    filters.command("gstats")
+    & filters.user(SUDOERS)
+    & ~filters.edited
+)
+@capture_err
+async def global_stats(_, message):
+    m = await app.send_message(
+        message.chat.id,
+        text="__**Analysing Stats...**__",
+        disable_web_page_preview=True,
+    )
+
+    # For bot served chat and users count
+    served_chats = len(await get_served_chats())
+    served_users = len(await get_served_users())
     # Gbans count
     gbans = await get_gbans_count()
     _notes = await get_notes_count()
@@ -121,7 +134,7 @@ async def global_stats(_, message):
 **{notes_count}** Notes, Across **{notes_chats_count}** chats.
 **{warns_count}** Warns, Across **{warns_chats_count}** chats.
 **{karmas_count}** Karma, Across **{karmas_chats_count}** chats.
-**{len(served_users)}** Users, Across **{len(served_chats)}** chats.
+**{served_users}** Users, Across **{served_chats}** chats.
 **{developers}** Developers And **{commits}** Commits On **[Github]({rurl})**.
 """
     await m.edit(msg, disable_web_page_preview=True)

+ 2 - 0
wbb/modules/misc.py

@@ -55,6 +55,7 @@ __HELP__ = """
 #RTFM - Tell noobs to read the manual
 """
 
+
 @app.on_message(filters.command("asq"))
 async def asq(_, message):
     err = "Reply to text message or pass the question as argument"
@@ -70,6 +71,7 @@ async def asq(_, message):
     resp = await arq.asq(question)
     await m.edit(resp.result)
 
+
 @app.on_message(filters.command("commit") & ~filters.edited)
 async def commit(_, message):
     await message.reply_text(

+ 3 - 1
wbb/modules/music.py

@@ -37,7 +37,6 @@ from pyrogram import filters
 
 from wbb import app, arq
 from wbb.core.decorators.errors import capture_err
-from wbb.utils.http import get
 from wbb.utils.pastebin import paste
 
 __MODULE__ = "Music"
@@ -178,6 +177,7 @@ async def jssong(_, message):
         sname = songs.result[0].song
         slink = songs.result[0].media_url
         ssingers = songs.result[0].singers
+        sduration = songs.result[0].duration
         await m.edit("Downloading")
         song = await download_song(slink)
         await m.edit("Uploading")
@@ -185,6 +185,7 @@ async def jssong(_, message):
             audio=song,
             title=sname,
             performer=ssingers,
+            duration=sduration,
         )
         os.remove(song)
         await m.delete()
@@ -193,6 +194,7 @@ async def jssong(_, message):
         return await m.edit(str(e))
     is_downloading = False
 
+
 # Lyrics
 
 

+ 2 - 0
wbb/modules/paste.py

@@ -79,6 +79,8 @@ async def paste_func(_, message):
         async with aiofiles.open(doc, mode="r") as f:
             content = await f.read()
         os.remove(doc)
+    else:
+        return await message.reply("Reply to a text message or DOC.")
     link = await paste(content)
     preview = link + "/preview.png"
     button = InlineKeyboard(row_width=1)

+ 12 - 1
wbb/modules/pmpermit.py

@@ -23,6 +23,7 @@ SOFTWARE.
 """
 
 from pyrogram import filters
+from pyrogram.raw.functions.messages import DeleteHistory
 
 from wbb import BOT_ID, SUDOERS, USERBOT_ID, USERBOT_PREFIX, app, app2
 from wbb.core.decorators.errors import capture_err
@@ -175,10 +176,18 @@ async def pmpermit_cq(_, cq):
     if data == "block":
         if user_id != USERBOT_ID:
             return await cq.answer("This Button Is Not For You")
+        await cq.answer()
         await app.edit_inline_text(
             cq.inline_message_id, "Successfully blocked the user."
         )
-        return await app2.block_user(int(victim))
+        await app2.block_user(int(victim))
+        return await app2.send(
+            DeleteHistory(
+                peer=(await app2.resolve_peer(victim)),
+                max_id=0,
+                revoke=False,
+            )
+        )
 
     if user_id == USERBOT_ID:
         return await cq.answer("It's For The Other Person.")
@@ -191,8 +200,10 @@ async def pmpermit_cq(_, cq):
             user_id, "Blocked, Go scam someone else."
         )
         await app2.block_user(user_id)
+        await cq.answer()
 
     elif data == "approve_me":
+        await cq.answer()
         if str(user_id) in flood2:
             flood2[str(user_id)] += 1
         else:

+ 3 - 4
wbb/modules/sudo.py

@@ -21,8 +21,6 @@ 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.
 """
-import os
-
 from pyrogram import filters
 from pyrogram.types import Message
 
@@ -30,6 +28,7 @@ from wbb import BOT_ID, SUDOERS, USERBOT_PREFIX, app2
 from wbb.core.decorators.errors import capture_err
 from wbb.modules.userbot import edit_or_reply
 from wbb.utils.dbfunctions import add_sudo, get_sudoers, remove_sudo
+from wbb.utils.functions import restart
 
 __MODULE__ = "Sudo"
 __HELP__ = """
@@ -74,7 +73,7 @@ async def useradd(_, message: Message):
             message,
             text="Successfully added user in sudoers, Bot will be restarted now.",
         )
-        return os.execvp("python3", ["python3", "-m", "wbb"])
+        return await restart(None)
     await edit_or_reply(
         message, text="Something wrong happened, check logs."
     )
@@ -102,7 +101,7 @@ async def userdel(_, message: Message):
             message,
             text="Successfully removed user from sudoers, Bot will be restarted now.",
         )
-        return os.execvp("python3", ["python3", "-m", "wbb"])
+        return await restart(None)
     await edit_or_reply(
         message, text="Something wrong happened, check logs."
     )

+ 68 - 203
wbb/modules/sudoers.py

@@ -35,14 +35,16 @@ from wbb import (BOT_ID, GBAN_LOG_GROUP_ID, SUDOERS, USERBOT_USERNAME,
 from wbb.core.decorators.errors import capture_err
 from wbb.utils import formatter
 from wbb.utils.dbfunctions import (add_gban_user, get_served_chats,
-                                   is_gbanned_user, remove_gban_user,
-                                   start_restart_stage)
+                                   is_gbanned_user, remove_gban_user)
+from wbb.utils.functions import (extract_user,
+                                 extract_user_and_reason, restart)
 
 __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
 """
@@ -68,165 +70,73 @@ DISK: {disk}%
     return stats
 
 
-@app.on_message(filters.user(SUDOERS) & filters.command("stats"))
-@capture_err
-async def get_stats(_, message):
-    stats = await bot_sys_stats()
-    await message.reply_text(stats)
-
-
 # Gban
 
 
 @app.on_message(filters.command("gban") & filters.user(SUDOERS))
 @capture_err
 async def ban_globally(_, message):
-    if not message.reply_to_message:
-        if len(message.command) < 3:
-            return await message.reply_text(
-                "**Usage:**\n/gban [USERNAME | USER_ID] [REASON]"
-            )
-        user = message.text.split(None, 2)[1]
-        reason = message.text.split(None, 2)[2]
-        if "@" in user:
-            user = user.replace("@", "")
-        user = await app.get_users(user)
-        from_user = message.from_user
-        if user.id == from_user.id:
-            await message.reply_text(
-                "You want to gban yourself? FOOL!"
-            )
-        elif user.id == BOT_ID:
-            await message.reply_text(
-                "Should i gban myself? I'm not fool like you, HUMAN!"
-            )
-        elif user.id in SUDOERS:
-            await message.reply_text(
-                "You want to ban a sudo user? GET REKT!!"
-            )
-        else:
-            served_chats = await get_served_chats()
-            m = await message.reply_text(
-                f"**Initializing WBB Global Ban Sequence To Add Restrictions On {user.mention}**"
-                + f" **This Action Should Take About {len(served_chats)} Seconds.**"
+    user_id, reason = await extract_user_and_reason(message)
+    user = await app.get_users(user_id)
+    from_user = message.from_user
+
+    if not user_id:
+        return await message.reply_text("I can't find that user.")
+    if not reason:
+        return await message.reply("No reason provided.")
+
+    if user_id in ([from_user.id, BOT_ID] + SUDOERS):
+        return await message.reply_text("No")
+
+    served_chats = await get_served_chats()
+    m = await message.reply_text(
+        f"**Banning {user.mention} Globally!**"
+        + f" **This Action Should Take About {len(served_chats)} Seconds.**"
+    )
+    await add_gban_user(user_id)
+    number_of_chats = 0
+    for served_chat in served_chats:
+        try:
+            await app.kick_chat_member(
+                served_chat["chat_id"], user.id
             )
-            await add_gban_user(user.id)
-            number_of_chats = 0
-            for served_chat in served_chats:
-                try:
-                    await app.kick_chat_member(
-                        served_chat["chat_id"], user.id
-                    )
-                    number_of_chats += 1
-                    await asyncio.sleep(1)
-                except Exception:
-                    pass
-            try:
-                await app.send_message(
-                    user.id,
-                    f"Hello, You have been globally banned by {from_user.mention},"
-                    + " You can appeal for this ban in @WBBSupport.",
-                )
-            except Exception:
-                pass
-            await m.edit(f"Banned {user.mention} Globally!")
-            ban_text = f"""
+            number_of_chats += 1
+            await asyncio.sleep(1)
+        except FloodWait as e:
+            await asyncio.sleep(int(e.x))
+        except Exception:
+            pass
+    try:
+        await app.send_message(
+            user.id,
+            f"Hello, You have been globally banned by {from_user.mention},"
+            + " You can appeal for this ban by talking to him.",
+        )
+    except Exception:
+        pass
+    await m.edit(f"Banned {user.mention} Globally!")
+    ban_text = f"""
 __**New Global Ban**__
 **Origin:** {message.chat.title} [`{message.chat.id}`]
 **Admin:** {from_user.mention}
 **Banned User:** {user.mention}
-**Banned User ID:** `{user.id}`
+**Banned User ID:** `{user_id}`
 **Reason:** __{reason}__
 **Chats:** `{number_of_chats}`"""
-            try:
-                m2 = await app.send_message(
-                    GBAN_LOG_GROUP_ID,
-                    text=ban_text,
-                    disable_web_page_preview=True,
-                )
-                await m.edit(
-                    f"Banned {user.mention} Globally!\nAction Log: {m2.link}",
-                    disable_web_page_preview=True,
-                )
-            except Exception:
-                await message.reply_text(
-                    "User Gbanned, But This Gban Wasn't Logged, Add Bot In GBAN_LOG_GROUP"
-                )
-                return
-        return
-    if len(message.command) < 2:
-        await message.reply_text("**Usage:**\n/gban [REASON]")
-        return
-    reason = message.text.strip().split(None, 1)[1]
-    from_user_id = message.from_user.id
-    from_user_mention = message.from_user.mention
-    user_id = message.reply_to_message.from_user.id
-    mention = message.reply_to_message.from_user.mention
-    if user_id == from_user_id:
-        await message.reply_text("You want to gban yourself? FOOL!")
-    elif user_id == BOT_ID:
-        await message.reply_text(
-            "Should i gban myself? I'm not fool like you, HUMAN!"
+    try:
+        m2 = await app.send_message(
+            GBAN_LOG_GROUP_ID,
+            text=ban_text,
+            disable_web_page_preview=True,
+        )
+        await m.edit(
+            f"Banned {user.mention} Globally!\nAction Log: {m2.link}",
+            disable_web_page_preview=True,
         )
-    elif user_id in SUDOERS:
+    except Exception:
         await message.reply_text(
-            "You want to ban a sudo user? GET REKT!!"
+            "User Gbanned, But This Gban Action Wasn't Logged, Add Me Bot In GBAN_LOG_GROUP"
         )
-    else:
-        is_gbanned = await is_gbanned_user(user_id)
-        if is_gbanned:
-            await message.reply_text(
-                "He's already gbanned, why bully him?"
-            )
-        else:
-            served_chats = await get_served_chats()
-            m = await message.reply_text(
-                f"**Initializing WBB Global Ban Sequence To Add Restrictions On {mention}**"
-                + f" **This Action Should Take About {len(served_chats)} Seconds.**"
-            )
-            number_of_chats = 0
-            for served_chat in served_chats:
-                try:
-                    await app.kick_chat_member(
-                        served_chat["chat_id"], user_id
-                    )
-                    number_of_chats += 1
-                    await asyncio.sleep(1)
-                except Exception:
-                    pass
-            await add_gban_user(user_id)
-            try:
-                await app.send_message(
-                    user_id,
-                    f"""
-Hello, You have been globally banned by {from_user_mention},
-You can appeal for this ban in @WBBSupport.""",
-                )
-            except Exception:
-                pass
-            await m.edit(f"Banned {mention} Globally!")
-            ban_text = f"""
-__**New Global Ban**__
-**Origin:** {message.chat.title} [`{message.chat.id}`]
-**Admin:** {from_user_mention}
-**Banned User:** {mention}
-**Banned User ID:** `{user_id}`
-**Reason:** __{reason}__
-**Chats:** `{number_of_chats}`"""
-            try:
-                m2 = await app.send_message(
-                    GBAN_LOG_GROUP_ID,
-                    text=ban_text,
-                    disable_web_page_preview=True,
-                )
-                await m.edit(
-                    f"Banned {mention} Globally!\nAction Log: {m2.link}",
-                    disable_web_page_preview=True,
-                )
-            except Exception:
-                await message.reply_text(
-                    "User Gbanned, But This Gban Wasn't Logged, Add Bot In GBAN_LOG_GROUP"
-                )
 
 
 # Ungban
@@ -235,63 +145,19 @@ __**New Global Ban**__
 @app.on_message(filters.command("ungban") & filters.user(SUDOERS))
 @capture_err
 async def unban_globally(_, message):
-    if not message.reply_to_message:
-        if len(message.command) != 2:
-            return await message.reply_text(
-                "Reply to a user's message or give username/user_id."
-            )
-        user = message.text.split(None, 1)[1]
-        if "@" in user:
-            user = user.replace("@", "")
-        user = await app.get_users(user)
-        from_user = message.from_user
-        if user.id == from_user.id:
-            await message.reply_text(
-                "You want to ungban yourself? FOOL!"
-            )
-        elif user.id == BOT_ID:
-            await message.reply_text(
-                "Should i ungban myself? But i'm not gbanned."
-            )
-        elif user.id in SUDOERS:
-            await message.reply_text(
-                "Sudo users can't be gbanned/ungbanned."
-            )
-        else:
-            is_gbanned = await is_gbanned_user(user.id)
-            if not is_gbanned:
-                await message.reply_text(
-                    "He's already free, why bully him?"
-                )
-            else:
-                await remove_gban_user(user.id)
-                await message.reply_text(
-                    f"Unbanned {user.mention} Globally!"
-                )
-        return
-
-    from_user_id = message.from_user.id
-    user_id = message.reply_to_message.from_user.id
-    mention = message.reply_to_message.from_user.mention
-    if user_id == from_user_id:
-        await message.reply_text("You want to ungban yourself? FOOL!")
-    elif user_id == BOT_ID:
-        await message.reply_text(
-            "Should i ungban myself? But i'm not gbanned."
-        )
-    elif user_id in SUDOERS:
+    user_id = await extract_user(message)
+    if not user_id:
+        return await message.reply_text("I can't find that user.")
+    user = await app.get_users(user_id)
+
+    is_gbanned = await is_gbanned_user(user.id)
+    if not is_gbanned:
+        await message.reply_text("I don't remember Gbanning him.")
+    else:
+        await remove_gban_user(user.id)
         await message.reply_text(
-            "Sudo users can't be gbanned/ungbanned."
+            f"Lifted {user.mention}'s Global Ban.'"
         )
-    else:
-        is_gbanned = await is_gbanned_user(user_id)
-        if not is_gbanned:
-            await message.reply_text(
-                "He's already free, why bully him?"
-            )
-        else:
-            await remove_gban_user(user_id)
-            await message.reply_text(f"Unbanned {mention} Globally!")
 
 
 # Broadcast
@@ -308,7 +174,7 @@ async def broadcast_message(_, message):
         return await message.reply_text(
             "**Usage**:\n/broadcast [MESSAGE]"
         )
-    sleep_time = 3
+    sleep_time = 0.1
     text = message.text.split(None, 1)[1]
     sent = 0
     schats = await get_served_chats()
@@ -342,5 +208,4 @@ async def update_restart(_, message):
     m = await message.reply_text(
         "**Updated with default branch, restarting now.**"
     )
-    await start_restart_stage(m.chat.id, m.message_id)
-    os.execvp("python3.9", ["python3.9", "-m", "wbb"])
+    await restart(m)

+ 15 - 1
wbb/utils/dbfunctions.py

@@ -21,10 +21,11 @@ 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.
 """
+import codecs
+import pickle
 from typing import Dict, List, Union
 
 from wbb import db
-from wbb.utils.functions import obj_to_str, str_to_obj
 
 """
 SOME THINGS ARE FUCKED UP HERE, LIKE TOGGLEABLES HAVE THEIR OWN COLLECTION
@@ -54,6 +55,19 @@ restart_stagedb = db.restart_stage
 flood_toggle_db = db.flood_toggle
 rssdb = db.rss
 
+
+def obj_to_str(object):
+    if not object:
+        return False
+    string = codecs.encode(pickle.dumps(object), "base64").decode()
+    return string
+
+
+def str_to_obj(string: str):
+    object = pickle.loads(codecs.decode(string.encode(), "base64"))
+    return object
+
+
 """ Notes functions """
 
 

+ 20 - 15
wbb/utils/functions.py

@@ -21,14 +21,14 @@ 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.
 """
-import codecs
-import pickle
 from asyncio import gather, get_running_loop
 from datetime import datetime, timedelta
 from io import BytesIO
 from math import atan2, cos, radians, sin, sqrt
+from os import execvp
 from random import randint
 from re import findall
+from sys import executable
 from time import time
 
 import aiofiles
@@ -41,6 +41,7 @@ from wget import download
 from wbb import aiohttpsession as aiosession
 from wbb import arq
 from wbb.utils import aiodownloader
+from wbb.utils.dbfunctions import start_restart_stage
 from wbb.utils.http import get
 
 """
@@ -58,6 +59,12 @@ async def download_url(url: str):
     return file
 
 
+async def restart(m: Message):
+    if m:
+        await start_restart_stage(m.chat.id, m.message_id)
+    execvp(executable, [executable, "-m", "wbb"])
+
+
 def generate_captcha():
     # Generate one letter
     def gen_letter():
@@ -155,18 +162,6 @@ async def transfer_sh(file_or_message):
     return download_link
 
 
-def obj_to_str(object):
-    if not object:
-        return False
-    string = codecs.encode(pickle.dumps(object), "base64").decode()
-    return string
-
-
-def str_to_obj(string: str):
-    object = pickle.loads(codecs.decode(string.encode(), "base64"))
-    return object
-
-
 async def calc_distance_from_ip(ip1: str, ip2: str) -> float:
     Radius_Earth = 6371.0088
     data1, data2 = await gather(
@@ -217,7 +212,18 @@ async def time_converter(message: Message, time_value: str) -> int:
 
 
 async def extract_userid(message, text: str):
+    def is_int(text: str):
+        try:
+            int(text)
+        except ValueError:
+            return False
+        return True
+
     text = text.strip()
+
+    if is_int(text):
+        return int(text)
+
     entities = message.entities
     app = message._client
     if len(entities) < 2:
@@ -265,7 +271,6 @@ async def extract_user(message):
 async def test_ARQ(message):
     results = ""
     funcs = {
-        "deezer": arq.deezer("attention", 1),
         "image": arq.image("something"),
         "luna": arq.luna("hello"),
         "lyrics": arq.lyrics("attention"),

+ 2 - 1
wbb/utils/inlinefuncs.py

@@ -707,7 +707,8 @@ async def pmpermit_func(answers, user_id, victim):
             text="Approve", callback_data=f"pmpermit approve {victim}"
         ),
         InlineKeyboardButton(
-            text="Block", callback_data=f"pmpermit block {victim}"
+            text="Block & Delete",
+            callback_data=f"pmpermit block {victim}",
         ),
     )
     answers.append(