Эх сурвалжийг харах

Merge pull request #6 from thehamkercat/pnut-dev

Pnut dev
Akshay Rajput 5 жил өмнө
parent
commit
7ee03b0699

+ 3 - 0
requirements.txt

@@ -3,3 +3,6 @@ uvloop
 aiohttp
 pyrogram==1.0.7
 TgCrypto
+speedtest-cli
+youtube_dl
+future

+ 1 - 2
wbb/__main__.py

@@ -8,7 +8,6 @@ import importlib
 from wbb.modules import ALL_MODULES
 import uvloop
 
-
 loop = asyncio.get_event_loop()
 
 
@@ -43,7 +42,7 @@ async def start_bot():
     print("+===============+===============+===============+===============+")
     print(bot_modules)
     print("+===============+===============+===============+===============+")
-    print("Bot run successfully as {}!".format(botinfo.BOT_NAME))
+    print("Bot Started Successfully as {}!".format(botinfo.BOT_NAME))
     await idle()
 
 

+ 44 - 0
wbb/modules/admin.py

@@ -0,0 +1,44 @@
+import asyncio
+from pyrogram import Client, filters
+from wbb.utils import cust_filter
+from wbb import app, Command
+from wbb.utils.is_admin import is_admin
+
+@app.on_message(cust_filter.command(commands=(["purge"])))
+async def purge(client, message):
+    app.set_parse_mode("markdown")
+    if message.chat.type not in (("supergroup", "channel")):
+        return
+    
+    admin = await is_admin(message)
+
+    if not admin:
+        return
+
+    message_ids = []
+
+    if message.reply_to_message:
+        for a_s_message_id in range(
+            message.reply_to_message.message_id,
+            message.message_id
+        ):
+            message_ids.append(a_s_message_id)
+            if len(message_ids) == 100:
+                await client.delete_messages(
+                    chat_id=message.chat.id,
+                    message_ids=message_ids,
+                    revoke=True
+                )
+                message_ids = []
+        if len(message_ids) > 0:
+            await client.delete_messages(
+                chat_id=message.chat.id,
+                message_ids=message_ids,
+                revoke=True
+            )
+
+    m = await message.reply_text(
+        f"```Purged!```"
+    )
+    await asyncio.sleep(2)
+    await m.delete()

+ 1 - 1
wbb/modules/commit.py

@@ -3,7 +3,7 @@ from pyrogram import filters
 from wbb.utils import cust_filter, random_line
 
 __MODULE__ = "Commit"
-__HELP__ = "A Funny little module, try /commit uwu"
+__HELP__ = "/commit - To Generate Funny Commit Messages"
 
 
 @app.on_message(cust_filter.command(commands=(["commit"])))

+ 3 - 0
wbb/modules/log.py

@@ -4,6 +4,9 @@ from wbb.utils import cust_filter, nekobin
 from wbb import app, OWNER_ID
 
 
+__MODULE__ = "Logs"
+__HELP__ = "/log - To Get Logs From Last Run [Owner Only]"
+
 @app.on_message(filters.user(OWNER_ID) & cust_filter.command("log"))
 async def logs_chat(client, message):
     keyb = types.InlineKeyboardMarkup(

+ 42 - 0
wbb/modules/music.py

@@ -0,0 +1,42 @@
+from __future__ import unicode_literals
+import youtube_dl
+from wbb.utils import cust_filter
+from pyrogram import filters
+from wbb import app, Command
+import os
+import glob
+
+__MODULE__ = "Music"
+__HELP__ = "/music [link] To Download Music From Various Websites"
+
+
+ydl_opts = {
+    'format': 'bestaudio/best',
+    'postprocessors': [{
+        'key': 'FFmpegExtractAudio',
+        'preferredcodec': 'mp3',
+        'preferredquality': '320'
+    }],
+    'postprocessor_args': [
+        '-ar', '16000'
+    ],
+    'prefer_ffmpeg': True,
+    'keepvideo': False
+}
+
+@app.on_message(cust_filter.command(commands=(["music"])))
+async def commit(client, message):
+    app.set_parse_mode("markdown")
+    down = await message.reply_text("```Downloading Media!```")
+    link = (message.text.split(None, 1)[1])
+    with youtube_dl.YoutubeDL(ydl_opts) as ydl:
+        ydl.download([link])
+    for filename in glob.glob("*.mp3"):
+        filename_final = filename.split("-")[0]+" - "+filename.split("-")[-2]+".mp3"
+        os.rename(filename, filename_final)
+        await down.edit(f"```Uploading Media!```")
+        m = await message.reply_audio(filename_final)
+        await down.delete()
+        await m.edit_caption(f"[{filename_final}]({link})")
+        os.remove(filename_final)
+

+ 3 - 4
wbb/modules/ping.py

@@ -1,10 +1,9 @@
-from wbb import app
-import time
+from wbb import app, Command
 from wbb.utils import cust_filter
 import requests
-import inspect
+import time
 __MODULE__ = "Ping"
-__HELP__ = " - /ping - to check if I am Alive or Not"
+__HELP__ = " /ping - To Get Response Time From All TG Datacenters"
 
 
 

+ 6 - 5
wbb/modules/repo.py

@@ -3,14 +3,15 @@ from pyrogram import filters
 from wbb.utils import cust_filter
 
 __MODULE__ = "Repo"
-__HELP__ = "Do /repo To Get My Github Repository Link"
+__HELP__ = "/repo - To Get My Github Repository Link"
 
 
 @app.on_message(cust_filter.command(commands=(["repo"])))
-async def commit(client, message):
+async def repo(client, message):
+    app.set_parse_mode("markdown")
     await message.reply_text(f'''
-👨‍💻 Developer - @TheHamkerCat
+```👨‍💻 Developer``` - @TheHamkerCat
 
-🔗 Repo - github.com/thehamkercat/WilliamButcherBot
+```🔗 Repo``` - github.com/thehamkercat/WilliamButcherBot
 
-❤️ PRs Are Always Welcomed''', disable_web_page_preview=True)
+```❤️ PRs Are Always Welcomed```''', disable_web_page_preview=True)

+ 33 - 0
wbb/modules/speedtest.py

@@ -0,0 +1,33 @@
+from pyrogram import filters
+from wbb import app, Command, OWNER_ID
+from wbb.utils import cust_filter
+import speedtest
+
+
+__MODULE__ = "Speedtest"
+__HELP__ = " - /speedtest - To Perform A Speedtest [Owner Only]"
+
+
+def speed_convert(size):
+    power = 2 ** 10
+    zero = 0
+    units = {0: "", 1: "Kb/s", 2: "Mb/s", 3: "Gb/s", 4: "Tb/s"}
+    while size > power:
+        size /= power
+        zero += 1
+    return f"{round(size, 2)} {units[zero]}"
+
+
+@app.on_message(filters.user(OWNER_ID) & cust_filter.command(commands=(["speedtest"])))
+async def speeeed(client, message):
+    app.set_parse_mode("markdown")
+    m = await message.reply_text("```Performing A Speedtest!```")
+    speed = speedtest.Speedtest()
+    x = speed.get_best_server()
+    y = speed.download()
+    z = speed.upload()
+    await m.edit(f'''
+```Download - {speed_convert(y)}
+Upload   - {speed_convert(z)}
+Latency  - {round((x["latency"]))} ms
+```''')

+ 6 - 2
wbb/modules/stats.py

@@ -5,7 +5,7 @@ import psutil
 from wbb.utils import cust_filter, formater
 
 __MODULE__ = "Stats"
-__HELP__ = "For Bot Owner to Check system Status"
+__HELP__ = "/stats - For Bot Owner To Check System Status [Owner Only]"
 
 
 @app.on_message(filters.user(OWNER_ID) & cust_filter.command(commands=(["stats"])))
@@ -13,5 +13,9 @@ async def stats(client, message):
     cpu = psutil.cpu_percent(interval=0.5)
     mem = psutil.virtual_memory().percent
     disk = psutil.disk_usage("/").percent
-    stats = f"<b>Uptime:</b> {formater.get_readable_time((time.time() - bot_start_time))}" f"\n<b>CPU:</b> {cpu}% " f"\n<b>RAM:</b> {mem}% " f"\n<b>Disk:</b> {disk}%"
+    stats = (f'''
+```Uptime: {formater.get_readable_time((time.time() - bot_start_time))} 
+CPU: {cpu}% 
+RAM: {mem}% 
+Disk: {disk}%```''')
     await message.reply_text(stats)

+ 32 - 0
wbb/utils/is_admin.py

@@ -0,0 +1,32 @@
+from pyrogram.types import Message
+
+
+async def is_admin(message: Message) -> bool:
+    if not message.from_user:
+        return False
+
+    if message.chat.type not in ["supergroup", "channel"]:
+        return False
+
+    if message.from_user.id in [
+        777000,  # Telegram Service Notifications
+        1087968824  # GroupAnonymousBot
+    ]:
+        return True
+
+    client = message._client
+    chat_id = message.chat.id
+    user_id = message.from_user.id
+
+    check_status = await client.get_chat_member(
+        chat_id=chat_id,
+        user_id=user_id
+    )
+    admin_strings = [
+        "creator",
+        "administrator"
+    ]
+    if check_status.status not in admin_strings:
+        return False
+    else:
+        return True