Przeglądaj źródła

Merge pull request #8 from beta

Akshay Rajput 5 lat temu
rodzic
commit
e8c62b9679

+ 1 - 0
.gitignore

@@ -130,4 +130,5 @@ dmypy.json
 
 
 #others
+neofetch.txt
 error.log

+ 1 - 0
README.md

@@ -24,6 +24,7 @@ Just Another Telegram Bot Written In Python Using Pyrogram.
    
    [admin]
    owner_id = 1243703097
+   neofetch = True
 
    [prefix]
    prefixes = /

+ 1 - 0
sample_config.ini

@@ -5,6 +5,7 @@ api_hash = r7s8c3b22d4869bd6ca7cc756cb9
 
 [admin]
 owner_id = 1243703097
+neofetch = True
 
 [prefix]
 prefixes = /

+ 1 - 0
wbb/__init__.py

@@ -32,6 +32,7 @@ log = logging.getLogger()
 config = ConfigParser()
 config.read("config.ini")
 OWNER_ID = int(config.get("admin", "owner_id"))
+NEOFETCH = (config.get("admin", "neofetch"))
 Command = config.get("prefix", "prefixes").split()
 MOD_LOAD = config.get("mods", "load_modules").split()
 MOD_NOLOAD = config.get("mods", "noload_modules").split()

+ 110 - 113
wbb/__main__.py

@@ -3,7 +3,7 @@ import re
 from pyrogram import filters, idle
 from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup
 from wbb import app, MOD_NOLOAD, MOD_LOAD, Command
-from wbb.utils import random_line, get_info, paginate_modules, cust_filter
+from wbb.utils import random_line, get_info, paginate_modules, cust_filter, botinfo
 import importlib
 from wbb.modules import ALL_MODULES
 import uvloop
@@ -19,9 +19,8 @@ async def start_bot():
     await get_info(app)
     from wbb.utils import botinfo
 
-    await main_bot()
-    for modul in ALL_MODULES:
-        imported_module = importlib.import_module("wbb.modules." + modul)
+    for module in ALL_MODULES:
+        imported_module = importlib.import_module("wbb.modules." + module)
         if hasattr(imported_module, "__MODULE__") and imported_module.__MODULE__:
             if imported_module.__MODULE__.lower() in MOD_NOLOAD:
                 continue
@@ -44,127 +43,125 @@ async def start_bot():
     print("+===============+===============+===============+===============+")
     print("Bot Started Successfully as {}!".format(botinfo.BOT_NAME))
     await idle()
-
-
-async def main_bot():
-    from wbb.utils import botinfo
-
-    @app.on_message(cust_filter.command("start"))
-    async def start(client, message):
-        if message.chat.type != "private":
-            await message.reply_text((await random_line("wbb/start.txt")))
+    
+
+@app.on_message(cust_filter.command("start"))
+async def start(client, message):
+    if message.chat.type != "private":
+        await message.reply_text((await random_line("wbb/utils/start.txt")))
+        return
+    await message.reply("Hi, try /help")
+
+@app.on_message(cust_filter.command("help"))
+async def help_command(_, message):
+    if message.chat.type != "private":
+        if len(message.command) >= 2 and message.command[1] == "help":
+            text, keyboard = await help_parser(message)
+            await message.reply(
+                text, reply_markup=keyboard, disable_web_page_preview=True
+            )
             return
-        await message.reply("Hi, try /help")
-
-    @app.on_message(cust_filter.command("help"))
-    async def help_command(_, message):
-        if message.chat.type != "private":
-            if len(message.command) >= 2 and message.command[1] == "help":
-                text, keyboard = await help_parser(message)
-                await message.reply(
-                    text, reply_markup=keyboard, disable_web_page_preview=True
-                )
-                return
-            keyboard = InlineKeyboardMarkup(
+        keyboard = InlineKeyboardMarkup(
+            [
                 [
-                    [
-                        InlineKeyboardButton(
-                            text="Help",
-                            url="t.me/" + botinfo.BOT_USERNAME + "?start=help",
-                        )
-                    ]
+                    InlineKeyboardButton(
+                        text="Help",
+                        url="t.me/" + botinfo.BOT_USERNAME + "?start=help",
+                    )
                 ]
+            ]
+        )
+        await message.reply("Contact me in PM.", reply_markup=keyboard)
+        return
+    text, keyboard = await help_parser(message)
+    await message.reply(text, reply_markup=keyboard, disable_web_page_preview=True)
+
+
+async def help_parser(message, keyboard=None):
+    if not keyboard:
+        keyboard = InlineKeyboardMarkup(paginate_modules(0, HELPABLE, "help"))
+    return (
+        "Hi {first_name}, I am {bot_name}".format(
+            first_name=message.from_user.first_name,
+            bot_name=botinfo.BOT_NAME,
+            commands=", ".join(Command),
+        ),
+        keyboard,
+    )
+
+@app.on_callback_query(filters.regex(r"help_(.*?)"))
+async def help_button(c, q):
+    mod_match = re.match(r"help_module\((.+?)\)", q.data)
+    prev_match = re.match(r"help_prev\((.+?)\)", q.data)
+    next_match = re.match(r"help_next\((.+?)\)", q.data)
+    back_match = re.match(r"help_back", q.data)
+    create_match = re.match(r"help_create", q.data)
+
+    if mod_match:
+        module = mod_match.group(1)
+        text = (
+            "{} **{}**:\n".format(
+                "Here is the help for", HELPABLE[module].__MODULE__
             )
-            await message.reply("Contact me in PM.", reply_markup=keyboard)
-            return
-        text, keyboard = await help_parser(message)
-        await message.reply(text, reply_markup=keyboard, disable_web_page_preview=True)
-
-    async def help_parser(message, keyboard=None):
-        if not keyboard:
-            keyboard = InlineKeyboardMarkup(paginate_modules(0, HELPABLE, "help"))
-        return (
-            "Hi {first_name}, I am {bot_name}".format(
-                first_name=message.from_user.first_name,
+            + HELPABLE[module].__HELP__
+        )
+
+        await q.message.edit(
+            text=text,
+            reply_markup=InlineKeyboardMarkup(
+                [[InlineKeyboardButton("back", callback_data="help_back")]]
+            ),
+            disable_web_page_preview=True,
+        )
+
+    elif prev_match:
+        curr_page = int(prev_match.group(1))
+        await q.message.edit(
+            text="Hi {first_name}. I am {bot_name}, you can use commands with following prefixes{commands}".format(
+                first_name=q.from_user.first_name,
                 bot_name=botinfo.BOT_NAME,
                 commands=", ".join(Command),
             ),
-            keyboard,
+            reply_markup=InlineKeyboardMarkup(
+                paginate_modules(curr_page - 1, HELPABLE, "help")
+            ),
+            disable_web_page_preview=True,
         )
 
-    @app.on_callback_query(filters.regex(r"help_(.*?)"))
-    async def help_button(c, q):
-        mod_match = re.match(r"help_module\((.+?)\)", q.data)
-        prev_match = re.match(r"help_prev\((.+?)\)", q.data)
-        next_match = re.match(r"help_next\((.+?)\)", q.data)
-        back_match = re.match(r"help_back", q.data)
-        create_match = re.match(r"help_create", q.data)
-
-        if mod_match:
-            module = mod_match.group(1)
-            text = (
-                "{} **{}**:\n".format(
-                    "Here is the help for", HELPABLE[module].__MODULE__
-                )
-                + HELPABLE[module].__HELP__
-            )
-
-            await q.message.edit(
-                text=text,
-                reply_markup=InlineKeyboardMarkup(
-                    [[InlineKeyboardButton("back", callback_data="help_back")]]
-                ),
-                disable_web_page_preview=True,
-            )
-
-        elif prev_match:
-            curr_page = int(prev_match.group(1))
-            await q.message.edit(
-                text="Hi {first_name}. I am {bot_name}, you can use commands with following prefixes{commands}".format(
-                    first_name=q.from_user.first_name,
-                    bot_name=botinfo.BOT_NAME,
-                    commands=", ".join(Command),
-                ),
-                reply_markup=InlineKeyboardMarkup(
-                    paginate_modules(curr_page - 1, HELPABLE, "help")
-                ),
-                disable_web_page_preview=True,
-            )
-
-        elif next_match:
-            next_page = int(next_match.group(1))
-            await q.message.edit(
-                text="Hi {first_name}. I am {bot_name}, you can use commands with following prefixes{commands}".format(
-                    first_name=q.from_user.first_name,
-                    bot_name=botinfo.BOT_NAME,
-                    commands=", ".join(Command),
-                ),
-                reply_markup=InlineKeyboardMarkup(
-                    paginate_modules(next_page + 1, HELPABLE, "help")
-                ),
-                disable_web_page_preview=True,
-            )
+    elif next_match:
+        next_page = int(next_match.group(1))
+        await q.message.edit(
+            text="Hi {first_name}. I am {bot_name}, you can use commands with following prefixes{commands}".format(
+                first_name=q.from_user.first_name,
+                bot_name=botinfo.BOT_NAME,
+                commands=", ".join(Command),
+            ),
+            reply_markup=InlineKeyboardMarkup(
+                paginate_modules(next_page + 1, HELPABLE, "help")
+            ),
+            disable_web_page_preview=True,
+        )
 
-        elif back_match:
-            await q.message.edit(
-                text="Hi {first_name}. I am {bot_name}, you can use commands with following prefixes{commands}".format(
-                    first_name=q.from_user.first_name,
-                    bot_name=botinfo.BOT_NAME,
-                    commands=", ".join(Command),
-                ),
-                reply_markup=InlineKeyboardMarkup(
-                    paginate_modules(0, HELPABLE, "help")
-                ),
-                disable_web_page_preview=True,
-            )
+    elif back_match:
+        await q.message.edit(
+            text="Hi {first_name}. I am {bot_name}, you can use commands with following prefixes{commands}".format(
+                first_name=q.from_user.first_name,
+                bot_name=botinfo.BOT_NAME,
+                commands=", ".join(Command),
+            ),
+            reply_markup=InlineKeyboardMarkup(
+                paginate_modules(0, HELPABLE, "help")
+            ),
+            disable_web_page_preview=True,
+        )
 
-        elif create_match:
-            text, keyboard = await help_parser(q)
-            await q.message.edit(
-                text=text, reply_markup=keyboard, disable_web_page_preview=True
-            )
+    elif create_match:
+        text, keyboard = await help_parser(q)
+        await q.message.edit(
+            text=text, reply_markup=keyboard, disable_web_page_preview=True
+        )
 
-        return await c.answer_callback_query(q.id)
+    return await c.answer_callback_query(q.id)
 
 
 if __name__ == "__main__":

+ 8 - 1
wbb/modules/admin.py

@@ -4,7 +4,14 @@ 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"])))
+
+__MODULE__ = "Admin"
+__HELP__ = '''
+/purge - Purge Messages From The Replied Message To The Last Message [Limit = 100]
+
+'''
+
+@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")):

+ 118 - 0
wbb/modules/bot_owner.py

@@ -0,0 +1,118 @@
+from wbb.utils import cust_filter, nekobin, formatter
+from wbb import app, Command, OWNER_ID, bot_start_time, NEOFETCH
+from pyrogram import filters, types
+import re, speedtest, psutil, time, os
+
+
+__MODULE__ = "BotOwner"
+__HELP__ = '''
+/log - To Get Logs From Last Run.
+/speedtest - To Perform A Speedtest.
+/stats - For Bot Owner To Check System Status.
+
+'''
+
+#Logs Module
+
+@app.on_message(filters.user(OWNER_ID) & cust_filter.command("log"))
+async def logs_chat(client, message):
+    keyb = types.InlineKeyboardMarkup(
+        [
+            [
+                types.InlineKeyboardButton(
+                    "Paste on Nekobin", callback_data="paste_log_nekobin"
+                )
+            ]
+        ]
+    )
+    await message.reply_document(
+        "error.log", caption="**Here are my Logs ~**", reply_markup=keyb
+    )
+
+
+def logs_callback(_, __, query):
+    if re.match("paste_log_nekobin", query.data):
+        return True
+
+
+logs_create = filters.create(logs_callback)
+
+
+@app.on_callback_query(logs_create)
+async def paste_log_neko(client, query):
+    if query.from_user.id == OWNER_ID:
+        f = open("error.log", "r")
+        data = await nekobin.neko(f.read())
+        keyb = types.InlineKeyboardMarkup(
+            [[types.InlineKeyboardButton("pasted on nekobin", url=f"{data}")]]
+        )
+        await query.message.edit_caption("Successfully Nekofied", reply_markup=keyb)
+    else:
+        await client.answer_callback_query(
+            query.id, "'Blue Button Must Press', huh?", show_alert=True
+        )
+
+
+
+#SpeedTest Module
+
+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
+```''')
+
+
+#Stats Module
+
+@app.on_message(filters.user(OWNER_ID) & cust_filter.command(commands=("stats")))
+async def stats(client, message):
+    bot_uptime = int(time.time() - bot_start_time)
+    cpu = psutil.cpu_percent(interval=0.5)
+    mem = psutil.virtual_memory().percent
+    disk = psutil.disk_usage("/").percent
+    if NEOFETCH == "True":
+        os.system("neofetch --stdout > neofetch.txt")
+        f = open("neofetch.txt", "r")
+        read_file = f.read()
+        neofetch = (f'''
+----------[Neofetch]----------
+
+{read_file}
+''')
+        f.close()
+    else:
+        neofetch = "NeoFetch Is Disabled!"
+    stats = (f'''
+```_________________________
+|________|Stats|________|
+|                       |
+|      Uptime: {formatter.get_readable_time((bot_uptime))}|
+|      CPU: {cpu}%       |
+|      RAM: {mem}%       |
+|      Disk: {disk}%       |
+|_______________________|
+
+
+{neofetch}
+```''')
+    await message.reply_text(stats)
+

+ 2 - 2
wbb/modules/commit.py

@@ -6,6 +6,6 @@ __MODULE__ = "Commit"
 __HELP__ = "/commit - To Generate Funny Commit Messages"
 
 
-@app.on_message(cust_filter.command(commands=(["commit"])))
+@app.on_message(cust_filter.command(commands=("commit")))
 async def commit(client, message):
-    await message.reply_text((await random_line('wbb/commit.txt')))
+    await message.reply_text((await random_line('wbb/utils/commit.txt')))

+ 0 - 2
wbb/modules/greetings.py

@@ -1,8 +1,6 @@
 from wbb import app
 from pyrogram import filters, emoji
 
-__MODULE__ = "Greetings"
-__HELP__ = "Welcomes Users to the Group"
 
 MESSAGE = "{} Welcome {}!"
 

+ 0 - 46
wbb/modules/log.py

@@ -1,46 +0,0 @@
-from pyrogram import filters, types
-import re
-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(
-        [
-            [
-                types.InlineKeyboardButton(
-                    "Paste on Nekobin", callback_data="paste_log_nekobin"
-                )
-            ]
-        ]
-    )
-    await message.reply_document(
-        "error.log", caption="**Here are my Logs ~**", reply_markup=keyb
-    )
-
-
-def logs_callback(_, __, query):
-    if re.match("paste_log_nekobin", query.data):
-        return True
-
-
-logs_create = filters.create(logs_callback)
-
-
-@app.on_callback_query(logs_create)
-async def paste_log_neko(client, query):
-    if query.from_user.id == OWNER_ID:
-        f = open("error.log", "r")
-        data = await nekobin.neko(f.read())
-        keyb = types.InlineKeyboardMarkup(
-            [[types.InlineKeyboardButton("pasted on nekobin", url=f"{data}")]]
-        )
-        await query.message.edit_caption("Successfully Nekofied", reply_markup=keyb)
-    else:
-        await client.answer_callback_query(
-            query.id, "'Blue Button Must Press', huh?", show_alert=True
-        )

+ 1 - 1
wbb/modules/music.py

@@ -24,7 +24,7 @@ ydl_opts = {
     'keepvideo': False
 }
 
-@app.on_message(cust_filter.command(commands=(["music"])))
+@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!```")

+ 1 - 1
wbb/modules/ping.py

@@ -7,7 +7,7 @@ __HELP__ = " /ping - To Get Response Time From All TG Datacenters"
 
 
 
-@app.on_message(cust_filter.command(commands=(["ping"])))
+@app.on_message(cust_filter.command(commands=("ping")))
 async def ping(client, message):
     app.set_parse_mode("markdown")
     m = await message.reply_text("```Wait, Pinging all Datacenters```")

+ 1 - 1
wbb/modules/repo.py

@@ -6,7 +6,7 @@ __MODULE__ = "Repo"
 __HELP__ = "/repo - To Get My Github Repository Link"
 
 
-@app.on_message(cust_filter.command(commands=(["repo"])))
+@app.on_message(cust_filter.command(commands=("repo")))
 async def repo(client, message):
     app.set_parse_mode("markdown")
     await message.reply_text(f'''

+ 0 - 33
wbb/modules/speedtest.py

@@ -1,33 +0,0 @@
-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
-```''')

+ 0 - 21
wbb/modules/stats.py

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

+ 0 - 0
wbb/commit.txt → wbb/utils/commit.txt


+ 6 - 6
wbb/utils/formater.py → wbb/utils/formatter.py

@@ -155,12 +155,12 @@ def escape_invalid_curly_brackets(text, valids):  # sourcery skip
                     if text[idx:].startswith("{" + v + "}"):
                         success = True
                         break
-                if success:
-                    new_text += text[idx : idx + len(v) + 2]
-                    idx += len(v) + 2
-                    continue
-                else:
-                    new_text += "{{"
+                    if success:
+                        new_text += text[idx : idx + len(v) + 2]
+                        idx += len(v) + 2
+                        continue
+                    else:
+                        new_text += "{{"
 
         elif text[idx] == "}":
             if idx + 1 < len(text) and text[idx + 1] == "}":

+ 0 - 0
wbb/start.txt → wbb/utils/start.txt