Kaynağa Gözat

Pylint: fixed various warnings

TheHamkerCat 5 yıl önce
ebeveyn
işleme
90f5d38a35

+ 26 - 0
commands.txt

@@ -0,0 +1,26 @@
+####Send this list to @botfather to set your commands.
+
+ban - Ban A User
+banme - Ban Yourself
+cat - Get Cute Cats Images
+commit - Generate Funny Commit Messages
+dev - Forward Anything To Developers [SPAM = GBAN]
+dog - Get Cute Dogs Images
+help - Help Yourself!
+id - Get Chat_ID or User_ID
+kick - Kick A User
+kickme - Kick Yourself
+log - Get Logs From Last Run.
+music - [link] To Download Music From Various Websites
+paste - Paste To Neokobin
+ping - Get Response Time From All TG Datacenters
+purge - Purge Messages
+quote - Get Random Linux Quotes
+repo - Get My Github Repository Link And Support Group Link
+rice - Forward Your Linux Rice To DE_WM'sRice Gallery only works in DE_WM
+runs - Idk Test Yourself
+start - Start The Bot
+speedtest - To Perform A Speedtest.
+stats  - To Check System Status.
+unban - Unban A User
+wall - Get Wallpapers

+ 1 - 0
pylintrc

@@ -251,6 +251,7 @@ function-naming-style=snake_case
 good-names=i,
            j,
            k,
+           m,
            ex,
            Run,
            _

+ 16 - 16
wbb/__main__.py

@@ -105,12 +105,12 @@ async def help_parser(message, keyboard=None):
 
 
 @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)
+async def help_button(client, query):
+    mod_match = re.match(r"help_module\((.+?)\)", query.data)
+    prev_match = re.match(r"help_prev\((.+?)\)", query.data)
+    next_match = re.match(r"help_next\((.+?)\)", query.data)
+    back_match = re.match(r"help_back", query.data)
+    create_match = re.match(r"help_create", query.data)
 
     if mod_match:
         module = mod_match.group(1)
@@ -121,7 +121,7 @@ async def help_button(c, q):
             + HELPABLE[module].__HELP__
         )
 
-        await q.message.edit(
+        await query.message.edit(
             text=text,
             reply_markup=InlineKeyboardMarkup(
                 [[InlineKeyboardButton("back", callback_data="help_back")]]
@@ -131,9 +131,9 @@ async def help_button(c, q):
 
     elif prev_match:
         curr_page = int(prev_match.group(1))
-        await q.message.edit(
+        await query.message.edit(
             text="Hi {first_name}. I am {bot_name}".format(
-                first_name=q.from_user.first_name,
+                first_name=query.from_user.first_name,
                 bot_name=botinfo.BOT_NAME,
             ),
             reply_markup=InlineKeyboardMarkup(
@@ -144,9 +144,9 @@ async def help_button(c, q):
 
     elif next_match:
         next_page = int(next_match.group(1))
-        await q.message.edit(
+        await query.message.edit(
             text="Hi {first_name}. I am {bot_name}".format(
-                first_name=q.from_user.first_name,
+                first_name=query.from_user.first_name,
                 bot_name=botinfo.BOT_NAME,
             ),
             reply_markup=InlineKeyboardMarkup(
@@ -156,9 +156,9 @@ async def help_button(c, q):
         )
 
     elif back_match:
-        await q.message.edit(
+        await query.message.edit(
             text="Hi {first_name}. I am {bot_name}".format(
-                first_name=q.from_user.first_name,
+                first_name=query.from_user.first_name,
                 bot_name=botinfo.BOT_NAME,
             ),
             reply_markup=InlineKeyboardMarkup(
@@ -168,12 +168,12 @@ async def help_button(c, q):
         )
 
     elif create_match:
-        text, keyboard = await help_parser(q)
-        await q.message.edit(
+        text, keyboard = await help_parser(query)
+        await query.message.edit(
             text=text, reply_markup=keyboard, disable_web_page_preview=True
         )
 
-    return await c.answer_callback_query(q.id)
+    return await client.answer_callback_query(query.id)
 
 
 if __name__ == "__main__":

+ 12 - 10
wbb/modules/__init__.py

@@ -1,10 +1,12 @@
+import glob
 import importlib
+import sys
+
+from os.path import dirname, basename, isfile
 from wbb import MOD_LOAD, MOD_NOLOAD, log
 
 
 def __list_all_modules():
-    from os.path import dirname, basename, isfile
-    import glob
 
 # This generates a list of modules in this
 # folder for the * in __main__ to work.
@@ -19,23 +21,23 @@ def __list_all_modules():
     ]
 
     if MOD_LOAD or MOD_NOLOAD:
-        to_Load = MOD_LOAD
-        if to_Load:
+        to_load = MOD_LOAD
+        if to_load:
             if not all(
                 any(mod == module_name for module_name in all_modules)
-                for mod in to_Load
+                for mod in to_load
             ):
                 log.error("Invalid Module name!")
-                quit(1)
+                sys.exit()
 
         else:
-            to_Load = all_modules
+            to_load = all_modules
 
         if MOD_NOLOAD:
-            log.info("No load: {}".format(MOD_NOLOAD))
-            return [item for item in to_Load if item not in MOD_NOLOAD]
+            log.info("No load: %s", MOD_NOLOAD)
+            return [item for item in to_load if item not in MOD_NOLOAD]
 
-        return to_Load
+        return to_load
 
     return all_modules
 

+ 17 - 15
wbb/modules/admin.py

@@ -3,10 +3,12 @@ from wbb import OWNER_ID, SUDO_USER_ID, app
 from wbb.utils import cust_filter
 
 __MODULE__ = "Admin"
-__HELP__ = "/purge - Purge Messages\n" \
-           "/kick - Kick A User\n" \
-           "/ban - Ban A User\n" \
-           "/unban - Unban A User"
+__HELP__ = "/ban    - Ban A User\n" \
+           "/unban  - Unban A User\n" \
+           "/kick   - Kick A User\n" \
+           "/purge  - Purge Messages\n" \
+           "/banme  - Bans A User Who Issued The Command\n" \
+           "/kickme - Kicks A User Who Issued The Command"
 
 SUDO = [OWNER_ID, SUDO_USER_ID]
 
@@ -35,7 +37,7 @@ async def list_members(group_id):
 @app.on_message(cust_filter.command(commands=("purge")))
 async def purge(client, message: Message):
     message_ids = []
-    if message.chat.type not in (("supergroup", "channel")):
+    if message.chat.type not in ("supergroup", "channel"):
         return
 
     admins = await list_admins(message.chat.id)
@@ -112,9 +114,9 @@ async def kick(client, message: Message):
             else:
                 if message.reply_to_message.from_user.id in \
                         await list_members(message.chat.id):
-                    id = message.reply_to_message.from_user.id
-                    await message.reply_to_message.chat.kick_member(id)
-                    await message.reply_to_message.chat.unban_member(id)
+                    user_id = message.reply_to_message.from_user.id
+                    await message.reply_to_message.chat.kick_member(user_id)
+                    await message.reply_to_message.chat.unban_member(user_id)
                     await message.reply_text(f"Kicked {username}")
                 else:
                     await message.reply_text("This user isn't here,"
@@ -153,8 +155,8 @@ async def ban(client, message: Message):
             else:
                 if (await app.get_users(username)).id in \
                         await list_members(message.chat.id):
-                    id = message.reply_to_message.from_user.id
-                    await message.reply_to_message.chat.kick_member(id)
+                    user_id = message.reply_to_message.from_user.id
+                    await message.reply_to_message.chat.kick_member(user_id)
                     await message.reply_text(f"Banned {username}")
                 else:
                     await message.reply_text("This user isn't here,"
@@ -178,7 +180,7 @@ async def unban(client, message: Message):
         if username != "":
             if (await app.get_users(username)).id not in \
                     await list_members(message.chat.id):
-                await message.chat.kick_member(username)
+                await message.chat.unban_member(username)
                 await message.reply_text(f"Unbanned {username}")
             else:
                 await message.reply_text("This user is already here,"
@@ -186,8 +188,8 @@ async def unban(client, message: Message):
         else:
             if (await app.get_users(username)).id not in \
                     await list_members(message.chat.id):
-                id = message.reply_to_message.from_user.id
-                await message.reply_to_message.chat.kick_member(id)
+                user_id = message.reply_to_message.from_user.id
+                await message.reply_to_message.chat.unban_member(user_id)
                 await message.reply_text(f"Unbanned {username}")
             else:
                 await message.reply_text("This user is already here,"
@@ -201,7 +203,7 @@ async def kickme(client, message: Message):
     if message.from_user.id not in SUDO:
         await message.chat.kick_member(message.from_user.id)
         await message.chat.unban_member(message.from_user.id)
-        await message.reply_text("Kicked!, Joke's on you, i'm into that shit")
+        await message.reply_text("Kicked!, Joke's on you, I'm into that shit!")
     else:
         await message.reply_text("It doesn't works that way mate.")
 
@@ -212,6 +214,6 @@ async def kickme(client, message: Message):
 async def banme(client, message: Message):
     if message.from_user.id not in SUDO:
         await message.chat.kick_member(message.from_user.id)
-        await message.reply_text("Banned!, Joke's on you, I'm into that shit")
+        await message.reply_text("Banned!, Joke's on you, I'm into that shit!")
     else:
         await message.reply_text("It doesn't works that way mate.")

+ 7 - 9
wbb/modules/images.py

@@ -15,7 +15,7 @@ __HELP__ = "/cat - Get Cute Cats Images\n" + \
 
 async def delete_message_with_delay(delay, message: Message):
     await asyncio.sleep(delay)
-    (message).delete()
+    await message.delete()
 
 
 @app.on_message(cust_filter.command(commands=("cat")))
@@ -49,18 +49,16 @@ async def wall(client, message: Message):
 
     json_rep = r.get(api).json()
     if not json_rep.get("success"):
-        await m.edit("FTS! something unusual happened, "
-                     + "report to support @Thepirategang")
+        await m.edit("`\"/wall\"` Needs A Keyword Argument!")
     else:
         wallpapers = json_rep.get("wallpapers")
         if not wallpapers:
             await m.edit("Found literally nothing!,"
                          + "You should work on your English.")
             return
-        else:
-            index = randint(0, len(wallpapers) - 1)
-            wallpaper = wallpapers[index]
-            wallpaper = wallpaper.get("url_image")
-            wallpaper = wallpaper.replace("\\", "")
-            await message.reply_document(wallpaper)
+        index = randint(0, len(wallpapers) - 1)
+        wallpaper = wallpapers[index]
+        wallpaper = wallpaper.get("url_image")
+        wallpaper = wallpaper.replace("\\", "")
+        await message.reply_document(wallpaper)
     await delete_message_with_delay(10, m)

+ 10 - 8
wbb/modules/misc.py

@@ -26,22 +26,23 @@ async def quote(client, message: Message):
 
 
 @app.on_message(cust_filter.command(commands=("id")))
-async def id(client, message: Message):
+async def get_id(client, message: Message):
     app.set_parse_mode("markdown")
     if message.text != '/id':
         username = message.text.replace('/id', '')
-        id = (await app.get_users(username)).id
-        msg = f"{username}'s ID is `{id}`"
+        user_id = (await app.get_users(username)).id
+        msg = f"{username}'s ID is `{user_id}`"
         await message.reply_text(msg)
 
     elif message.text == '/id' and not bool(message.reply_to_message):
-        id = message.chat.id
-        msg = f"{message.chat.title}'s ID is `{id}`"
+        chat_id = message.chat.id
+        msg = f"{message.chat.title}'s ID is `{chat_id}`"
         await message.reply_text(msg)
 
     elif message.text == '/id' and bool(message.reply_to_message):
-        id = message.reply_to_message.from_user.id
-        msg = f"{message.reply_to_message.from_user.mention}'s ID is `{id}`"
+        from_user_id = message.reply_to_message.from_user.id
+        from_user_mention = message.reply_to_message.from_user.mention
+        msg = f"{from_user_mention}'s ID is `{from_user_id}`"
         await message.reply_text(msg)
 
 
@@ -50,7 +51,8 @@ async def dev(client, message: Message):
     app.set_parse_mode("markdown")
     await message.reply_to_message.forward('WBBSupport')
     await app.send_message("WBBSupport",
-                           f"Forwarded By ID: `{message.from_user.id}`")
+                           f"Forwarded By: `{message.from_user.id}` | {message.from_user.mention}\n"
+                           f"Forwarded From: `{message.chat.id}` | {message.chat.title}")
     await message.reply_text("Your Message Has Been Forward To Devs,"
                              + " Any Missuse Of This Feature Will Not"
                              + " Be Tolerated And You Will Be"

+ 2 - 2
wbb/modules/paste.py

@@ -23,8 +23,8 @@ async def paste(client, message: Message):
         elif bool(message.reply_to_message.document) is True:
             m = await message.reply_text("```Pasting To Nekobin...```")
             await message.reply_to_message.download(file_name='paste.txt')
-            f = open("downloads/paste.txt", "r")
-            paste_link = await nekobin.neko(f.read())
+            i = open("downloads/paste.txt", "r")
+            paste_link = await nekobin.neko(i.read())
             os.remove('downloads/paste.txt')
             final_link = f"[Nekobin]({paste_link})"
             await m.edit(final_link, disable_web_page_preview=True)

+ 4 - 4
wbb/modules/ping.py

@@ -10,10 +10,10 @@ __HELP__ = " /ping - To Get Response Time From All TG Datacenters"
 @app.on_message(cust_filter.command(commands=("ping")))
 async def ping(client, message: Message):
     app.set_parse_mode("markdown")
-    m = await message.reply_text("```Wait, Pinging all Datacenters```")
+    j = await message.reply_text("Wait, Pinging all Datacenters`")
     result = ""
     for i in range(1, 6):
-        dc = (f"https://cdn{i}.telesco.pe")
-        ping1 = round(requests.head(dc).elapsed.total_seconds() * 1000)
+        datacenter = (f"https://cdn{i}.telesco.pe")
+        ping1 = round(requests.head(datacenter).elapsed.total_seconds() * 1000)
         result += f'```DC{i} - {ping1}ms```'
-    await m.edit(result)
+    await j.edit(result)

+ 2 - 2
wbb/modules/repo.py

@@ -4,7 +4,7 @@ from wbb.utils import cust_filter
 
 
 __MODULE__ = "Repo"
-__HELP__ = "/repo - To Get My Github Repository Link" + \
+__HELP__ = "/repo - To Get My Github Repository Link " + \
            "And Support Group Link"
 
 
@@ -13,4 +13,4 @@ async def repo(client, message: Message):
     app.set_parse_mode("markdown")
     await message.reply_text(
         "[Github](https://github.com/thehamkercat/WilliamButcherBot)"
-        + " | [Group](t.me/Thepirategang)", disable_web_page_preview=True)
+        + " | [Group](t.me/WBBSupport)", disable_web_page_preview=True)

+ 2 - 2
wbb/modules/rice.py

@@ -13,10 +13,10 @@ __HELP__ = "/rice - To Forward Your Linux Rice To DE_WM's" \
 async def rice(client, message: Message):
     if bool(message.reply_to_message) is True:
         app.set_parse_mode("markdown")
-        id = message.reply_to_message.from_user.id
+        user_id = message.reply_to_message.from_user.id
         await message.reply_to_message.forward('RiceGallery')
         await message.reply_text(
-            f"[Your](tg://user?id={id}) Rice Forwared"
+            f"[Your](tg://user?id={user_id}) Rice Forwared"
             " To [Rice Gallery](https://t.me/RiceGallery)",
             disable_web_page_preview=True)
 

+ 13 - 13
wbb/modules/sudoers.py

@@ -48,8 +48,8 @@ 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 or SUDO_USER_ID:
-        f = open("error.log", "r")
-        data = await nekobin.neko(f.read())
+        j = open("error.log", "r")
+        data = await nekobin.neko(j.read())
         keyb = types.InlineKeyboardMarkup(
             [[types.InlineKeyboardButton("Pasted!", url=f"{data}")]]
         )
@@ -77,17 +77,17 @@ def speed_convert(size):
 @app.on_message(
     filters.user(SUDOERS) & cust_filter.command(commands=("speedtest"))
 )
-async def speeeed(client, message: Message):
+async def get_speedtest_result(client, message: 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()
+    i = speed.get_best_server()
+    j = speed.download()
+    k = speed.upload()
     await m.edit(f'''
-```Download - {speed_convert(y)}
-Upload   - {speed_convert(z)}
-Latency  - {round((x["latency"]))} ms
+```Download - {speed_convert(j)}
+Upload   - {speed_convert(k)}
+Latency  - {round((i["latency"]))} ms
 ```''')
 
 # Stats Module
@@ -96,21 +96,21 @@ Latency  - {round((x["latency"]))} ms
 @ app.on_message(
     filters.user(SUDOERS) & cust_filter.command(commands=("stats"))
 )
-async def stats(client, message: Message):
+async def get_stats(client, message: 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()
+        i = open("neofetch.txt", "r")
+        read_file = i.read()
         neofetch = (f'''
 ----------[Neofetch]----------
 
 {read_file}
 ''')
-        f.close()
+        i.close()
     else:
         neofetch = "NeoFetch Is Disabled!"
     stats = (f'''

+ 2 - 148
wbb/utils/formatter.py

@@ -1,65 +1,3 @@
-import time
-import math
-
-
-def time_formatter(seconds):
-    minutes, seconds = divmod(seconds, 60)
-    hours, minutes = divmod(minutes, 60)
-    days, hours = divmod(hours, 24)
-    tmp = (
-        ((str(days) + " day(s), ") if days else "")
-        + ((str(hours) + " hour(s), ") if hours else "")
-        + ((str(minutes) + " minute(s), ") if minutes else "")
-        + ((str(seconds) + " second(s), ") if seconds else "")
-    )
-    return tmp[:-2]
-
-
-def time_parser(start, end):
-    time_end = end - start
-    month = time_end // 2678400
-    days = time_end // 86400
-    hours = time_end // 3600 % 24
-    minutes = time_end // 60 % 60
-    seconds = time_end % 60
-    times = ""
-    if month:
-        times += "{} month, ".format(month)
-    if days:
-        times += "{} days, ".format(days)
-    if hours:
-        times += "{} hours, ".format(hours)
-    if minutes:
-        times += "{} minutes, ".format(minutes)
-    if seconds:
-        times += "{} seconds".format(seconds)
-    if times == "":
-        times = "{} miliseconds".format(time_end)
-    return times
-
-
-def time_parser_int(time_end):
-    month = time_end // 2678400
-    days = time_end // 86400
-    hours = time_end // 3600 % 24
-    minutes = time_end // 60 % 60
-    seconds = time_end % 60
-    times = ""
-    if month:
-        times += "{} month, ".format(month)
-    if days:
-        times += "{} days, ".format(days)
-    if hours:
-        times += "{} hours, ".format(hours)
-    if minutes:
-        times += "{} minutes, ".format(minutes)
-    if seconds:
-        times += "{} seconds".format(seconds)
-    if times == "":
-        times = "{} miliseconds".format(time_end)
-    return times[:-2] if times[-2:] == ", " else times
-
-
 def get_readable_time(seconds: int) -> str:
     count = 0
     ping_time = ""
@@ -75,94 +13,10 @@ def get_readable_time(seconds: int) -> str:
             break
         time_list.append(int(result))
         seconds = int(remainder)
-    for x in range(len(time_list)):
-        time_list[x] = str(time_list[x]) + time_suffix_list[x]
+    for i in range(len(time_list)):
+        time_list[i] = str(time_list[i]) + time_suffix_list[i]
     if len(time_list) == 4:
         ping_time += time_list.pop() + ", "
     time_list.reverse()
     ping_time += ":".join(time_list)
     return ping_time
-
-
-def convert_size(size_bytes):
-    if size_bytes == 0:
-        return "0B"
-    size_name = ("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB")
-    i = int(math.floor(math.log(size_bytes, 1024)))
-    p = math.pow(1024, i)
-    s = round(size_bytes / p, 2)
-    return "%s %s" % (s, size_name[i])
-
-
-def extract_time(time_val):
-    if not any(time_val.endswith(unit) for unit in ("m", "h", "d")):
-        return False
-    unit = time_val[-1]
-    time_num = time_val[:-1]  # type: str
-    if not time_num.isdigit():
-        return False
-
-    if unit == "d":
-        bantime = int(time.time() + int(time_num) * 24 * 60 * 60)
-    elif unit == "h":
-        bantime = int(time.time() + int(time_num) * 60 * 60)
-    elif unit == "m":
-        bantime = int(time.time() + int(time_num) * 60)
-    else:
-        return False
-    return bantime
-
-
-def extract_time_set(time_val):
-    if not any(time_val.endswith(unit) for unit in ("m", "h", "d")):
-        return False
-    unit = time_val[-1]
-    time_num = time_val[:-1]  # type: str
-    if not time_num.isdigit():
-        return False
-    if unit == "d":
-        bantime = int(int(time_num) * 24 * 60 * 60)
-    elif unit == "h":
-        bantime = int(int(time_num) * 60 * 60)
-    elif unit == "m":
-        bantime = int(int(time_num) * 60)
-    else:
-        return False
-    return bantime
-
-
-def escape_invalid_curly_brackets(text, valids):  # sourcery skip
-    new_text = ""
-    idx = 0
-    while idx < len(text):
-        if text[idx] == "{":
-            if idx + 1 < len(text) and text[idx + 1] == "{":
-                idx += 2
-                new_text += "{{{{"
-                continue
-            else:
-                success = False
-                for v in valids:
-                    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 += "{{"
-
-        elif text[idx] == "}":
-            if idx + 1 < len(text) and text[idx + 1] == "}":
-                idx += 2
-                new_text += "}}}}"
-                continue
-            else:
-                new_text += "}}"
-
-        else:
-            new_text += text[idx]
-        idx += 1
-
-    return new_text

+ 6 - 6
wbb/utils/misc.py

@@ -40,13 +40,13 @@ def paginate_modules(page_n, module_dict, prefix, chat=None):
         )
 
     pairs = list(zip(modules[::3], modules[1::3], modules[2::3]))
-    c = 0
-    for x in pairs:
-        for _ in x:
-            c += 1
-    if len(modules) - c == 1:
+    i = 0
+    for m in pairs:
+        for _ in m:
+            i += 1
+    if len(modules) - i == 1:
         pairs.append((modules[-1],))
-    elif len(modules) - c == 2:
+    elif len(modules) - i == 2:
         pairs.append(
             (
                 modules[-2],

+ 3 - 3
wbb/utils/nekobin.py

@@ -2,11 +2,11 @@ import aiohttp
 
 
 async def neko(data):
-    BASE_URL = "https://nekobin.com"
+    base_url = "https://nekobin.com"
     async with aiohttp.ClientSession() as session:
         async with session.post(
-            f"{BASE_URL}/api/documents", json={"content": data}, timeout=3
+            f"{base_url}/api/documents", json={"content": data}, timeout=3
         ) as response:
             key = (await response.json())["result"]["key"]
-            reply = f"{BASE_URL}/{key}"
+            reply = f"{base_url}/{key}"
     return reply