소스 검색

Small fixes

TheHamkerCat 5 년 전
부모
커밋
8f54b0809e
6개의 변경된 파일과 49개의 추가작업 그리고 29개의 파일을 삭제
  1. 1 0
      requirements.txt
  2. 3 4
      wbb/modules/global_stats.py
  3. 14 4
      wbb/modules/music.py
  4. 21 19
      wbb/modules/regex.py
  5. 2 2
      wbb/modules/sudoers.py
  6. 8 0
      wbb/utils/functions.py

+ 1 - 0
requirements.txt

@@ -4,6 +4,7 @@ cryptography
 dnspython
 future
 googletrans==4.0.0-rc1
+hurry.filesize
 motor
 pillow
 psutil

+ 3 - 4
wbb/modules/global_stats.py

@@ -48,13 +48,13 @@ async def global_stats(_, message):
     for chat in chats:
         served_chats.append(int(chat["chat_id"]))
     await m.edit(
-            f"__**Analysing Stats Might Take {len(served_chats)*6}+ Seconds.**__",
+            f"__**Analysing Statistics, Should Take {len(served_chats)*6}+ Seconds.**__",
             disable_web_page_preview=True
             )
     for served_chat in served_chats:
         try:
             await app.get_chat_members(served_chat, BOT_ID)
-            await asyncio.sleep(3)
+            await asyncio.sleep(2)
         except Exception:
             await remove_served_chat(served_chat)
             served_chats.remove(served_chat)
@@ -66,11 +66,10 @@ async def global_stats(_, message):
         except Exception:
             await remove_served_chat(served_chat)
             pass
-        await asyncio.sleep(3)
+        await asyncio.sleep(2)
 
     # Gbans count
     gbans = await get_gbans_count()
-    # Notes count across chats
     _notes = await get_notes_count()
     notes_count = _notes["notes_count"]
     notes_chats_count = _notes["chats_count"]

+ 14 - 4
wbb/modules/music.py

@@ -5,10 +5,13 @@ import aiohttp
 import aiofiles
 import os
 from random import randint
+from hurry.filesize import size as format_size
 from pyrogram import filters
 from wbb import app, SUDOERS, arq, MAIN_CHATS
 from wbb.core.decorators.errors import capture_err
 from wbb.utils.pastebin import paste
+from wbb.utils.functions import file_size_from_url
+
 
 __MODULE__ = "Music"
 __HELP__ = """/ytmusic [link] To Download Music From Various Websites Including Youtube.
@@ -108,8 +111,12 @@ async def jssong(_, message):
         song = await download_song(slink)
         await m.edit("Uploading")
         await message.reply_audio(
-                audio=song, title=sname,
-                performer=ssingers, duration=int(songs[0].duration))
+                audio=song,
+                title=sname,
+                caption=f"「 `{format_size(await file_size_from_url(slink))}` 」",
+                performer=ssingers,
+                duration=int(songs[0].duration)
+                )
         os.remove(song)
         await m.delete()
     except Exception as e:
@@ -143,8 +150,11 @@ async def deezsong(_, message):
         await m.edit("Downloading")
         song = await download_song(url)
         await m.edit("Uploading")
-        await message.reply_audio(audio=song, title=title,
-                                  performer=artist)
+        await message.reply_audio(
+                audio=song,
+                title=title,
+                performer=artist,
+                caption=f"「 `{format_size(await file_size_from_url(slink))}` 」")
         os.remove(song)
         await m.delete()
     except Exception as e:

+ 21 - 19
wbb/modules/regex.py

@@ -77,28 +77,30 @@ def infinite_checker(repl):
 
 
 def separate_sed(sed_string):
-    if (
-        len(sed_string) >= 3
-        and sed_string[1] in DELIMITERS
-        and sed_string.count(sed_string[1]) >= 2
-    ):
-        delim = sed_string[1]
-        start = counter = 2
-        while counter < len(sed_string):
-            if sed_string[counter] == "\\":
-                counter += 1
+    try:
+        if (
+            len(sed_string) >= 3
+            and sed_string[1] in DELIMITERS
+            and sed_string.count(sed_string[1]) >= 2
+        ):
+            delim = sed_string[1]
+            start = counter = 2
+            while counter < len(sed_string):
+                if sed_string[counter] == "\\":
+                    counter += 1
+
+                elif sed_string[counter] == delim:
+                    replace = sed_string[start:counter]
+                    counter += 1
+                    start = counter
+                    break
 
-            elif sed_string[counter] == delim:
-                replace = sed_string[start:counter]
                 counter += 1
-                start = counter
-                break
-
-            counter += 1
-
-        else:
-            return None
 
+            else:
+                return None
+    except TypeError:
+        return
         while counter < len(sed_string):
             if (
                 sed_string[counter] == "\\"

+ 2 - 2
wbb/modules/sudoers.py

@@ -6,7 +6,7 @@ import psutil
 import asyncio
 from sys import version as pyver
 from wbb import (
-    app, SUDOERS, bot_start_time, BOT_ID,
+    app, app2, SUDOERS, bot_start_time, BOT_ID,
     USERBOT_USERNAME, GBAN_LOG_GROUP_ID
 )
 from wbb.utils import formatter
@@ -244,7 +244,7 @@ async def broadcast_message(_, message):
 
 # Update
 
-
+@app2.on_message(filters.command("update", prefixes=".") & filters.user(SUDOERS))
 @app.on_message(filters.command("update") & filters.user(SUDOERS))
 async def update_restart(_, message):
     await message.reply_text(f'```{subprocess.check_output(["git", "pull"]).decode("UTF-8")}```')

+ 8 - 0
wbb/utils/functions.py

@@ -1,6 +1,7 @@
 from PIL import Image, ImageDraw, ImageFont, ImageFilter
 from random import randint
 import speedtest
+import aiohttp
 
 
 def generate_captcha():
@@ -67,3 +68,10 @@ async def test_speedtest():
     download = speed.download()
     upload = speed.upload()
     return [speed_convert(download), speed_convert(upload), info]
+
+
+async def file_size_from_url(url: str) -> int:
+    async with aiohttp.ClientSession() as session:
+        async with session.get(url) as resp:
+            size = int(resp.headers['content-length'])
+    return size