TheHamkerCat 5 лет назад
Родитель
Сommit
12c0710130
5 измененных файлов с 39 добавлено и 30 удалено
  1. 13 16
      wbb/__main__.py
  2. 1 1
      wbb/modules/global_stats.py
  3. 10 7
      wbb/modules/stickers.py
  4. 5 2
      wbb/utils/files.py
  5. 10 4
      wbb/utils/stickerset.py

+ 13 - 16
wbb/__main__.py

@@ -1,22 +1,21 @@
 import asyncio
 import re
 import importlib
-import time
 import uvloop
 from pyrogram import filters, idle
 from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup
-from wbb import app, MOD_NOLOAD
+from wbb import app
 from wbb.utils import get_info, paginate_modules
-from wbb.utils import botinfo, formatter
+from wbb.utils import botinfo
 from wbb.modules.sudoers import bot_sys_stats
 from wbb.modules import ALL_MODULES
-from wbb import bot_start_time
 
 loop = asyncio.get_event_loop()
 
 
 HELPABLE = {}
 
+
 async def start_bot():
     global COMMANDS_COUNT
     await app.start()
@@ -90,7 +89,7 @@ async def help_command(_, message):
         await message.reply("Pm Me For More Details.", reply_markup=keyboard)
         return
     keyboard = InlineKeyboardMarkup(
-        [    
+        [
             [
                 InlineKeyboardButton(
                     text="Commands ❓",
@@ -102,7 +101,7 @@ async def help_command(_, message):
                 )
             ],
             [
-                InlineKeyboardButton(   
+                InlineKeyboardButton(
                     text="System Stats 🖥",
                     callback_data="stats_callback"
                 ),
@@ -119,10 +118,7 @@ async def help_command(_, message):
             ]
         ]
     )
-    await message.reply("fHey there! My name is {botinfo.BOT_NAME}. I can manage your group with lots of useful features, feel free to add me to your group.", reply_markup=keyboard)
-
-
-
+    await message.reply(f"Hey there! My name is {botinfo.BOT_NAME}. I can manage your group with lots of useful features, feel free to add me to your group.", reply_markup=keyboard)
 
 
 async def help_parser(name, keyboard=None):
@@ -145,18 +141,19 @@ General command are:
 
 
 @app.on_callback_query(filters.regex("bot_commands"))
-async def end_callbacc(_, CallbackQuery):
+async def commands_callbacc(_, CallbackQuery):
     text, keyboard = await help_parser(CallbackQuery.from_user.mention)
     await app.send_message(
-            CallbackQuery.message.chat.id,
-            text=text,
-            reply_markup=keyboard
-            )
+        CallbackQuery.message.chat.id,
+        text=text,
+        reply_markup=keyboard
+    )
 
     await CallbackQuery.message.delete()
 
+
 @app.on_callback_query(filters.regex("stats_callback"))
-async def end_callbacc(_, CallbackQuery):
+async def stats_callbacc(_, CallbackQuery):
     text = await bot_sys_stats()
     await app.answer_callback_query(CallbackQuery.id, text, show_alert=True)
 

+ 1 - 1
wbb/modules/global_stats.py

@@ -88,7 +88,7 @@ async def global_stats(_, message):
     for developer in developers:
         commits += developer['contributions']
     developers = len(developers)
-    
+
     # Modules info
     modules_count = len(ALL_MODULES)
 

+ 10 - 7
wbb/modules/stickers.py

@@ -1,7 +1,6 @@
 import os
 import imghdr
 from wbb.utils.botinfo import BOT_USERNAME
-from wbb import BOT_TOKEN
 from wbb import app
 from pyrogram import filters
 from wbb.utils.errors import capture_err
@@ -14,9 +13,10 @@ __MODULE__ = "Stickers"
 __HELP__ = """/sticker_id - To Get File ID of A Sticker.
 /kang - To Kang A Sticker or Image."""
 
-MAX_STICKERS = 120 # would be better if we could fetch this limit directly from telegram
+MAX_STICKERS = 120  # would be better if we could fetch this limit directly from telegram
 SUPPORTED_TYPES = ['jpeg', 'png', 'webp']
 
+
 @app.on_message(filters.command("sticker_id") & ~filters.edited)
 @capture_err
 async def sticker_id(_, message):
@@ -53,16 +53,18 @@ async def kang(client, message):
         sticker = await create_sticker(await get_document_from_file_id(message.reply_to_message.sticker.file_id), sticker_emoji)
     elif doc:
         temp_file_path = await app.download_media(doc)
-        if imghdr.what(temp_file_path) not in SUPPORTED_TYPES:
+        image_type = imghdr.what(temp_file_path)
+        if image_type not in SUPPORTED_TYPES:
             await msg.edit("Format not supported! ({})".format(image_type))
             return
         try:
             temp_file_path = await resize_file_to_sticker_size(temp_file_path)
         except OSError as e:
             await msg.edit_text("Something wrong happened.")
-            raise Exception(f"Something went wrong while resizing the sticker (at {temp_file_path}); {e}")
+            raise Exception(
+                f"Something went wrong while resizing the sticker (at {temp_file_path}); {e}")
             return False
-        sticker =  await create_sticker(await upload_document(client, temp_file_path, message.chat.id), sticker_emoji)
+        sticker = await create_sticker(await upload_document(client, temp_file_path, message.chat.id), sticker_emoji)
         if os.path.isfile(temp_file_path):
             os.remove(temp_file_path)
     else:
@@ -70,8 +72,9 @@ async def kang(client, message):
         return
 
     # Find an available pack & add the sticker to the pack; create a new pack if needed
-    packnum = 0 # Would be a good idea to cache the number instead of searching it every single time...
-    packname = "f" + str(message.from_user.id) + "_by_"+ BOT_USERNAME
+    # Would be a good idea to cache the number instead of searching it every single time...
+    packnum = 0
+    packname = "f" + str(message.from_user.id) + "_by_" + BOT_USERNAME
     while True:
         stickerset = await get_sticker_set_by_name(client, packname)
         if not stickerset:

+ 5 - 2
wbb/utils/files.py

@@ -34,12 +34,14 @@ async def resize_file_to_sticker_size(file_path: str) -> str:
     finally:
         im.save(file_path)
 
+
 async def upload_document(client: Client, file_path: str, chat_id: int) -> raw.base.InputDocument:
     media = await client.send(
         raw.functions.messages.UploadMedia(
             peer=await client.resolve_peer(chat_id),
             media=raw.types.InputMediaUploadedDocument(
-                mime_type=client.guess_mime_type(file_path) or "application/zip",
+                mime_type=client.guess_mime_type(
+                    file_path) or "application/zip",
                 file=await client.save_file(file_path),
                 attributes=[
                     raw.types.DocumentAttributeFilename(
@@ -51,6 +53,7 @@ async def upload_document(client: Client, file_path: str, chat_id: int) -> raw.b
     )
     return raw.types.InputDocument(id=media.document.id, access_hash=media.document.access_hash, file_reference=media.document.file_reference)
 
+
 async def get_document_from_file_id(file_id: str) -> raw.base.InputDocument:
     decoded = FileId.decode(file_id)
-    return raw.types.InputDocument(id=decoded.media_id, access_hash=decoded.access_hash, file_reference=decoded.file_reference)
+    return raw.types.InputDocument(id=decoded.media_id, access_hash=decoded.access_hash, file_reference=decoded.file_reference)

+ 10 - 4
wbb/utils/stickerset.py

@@ -3,11 +3,12 @@ from typing import List
 from pyrogram import Client, raw
 from pyrogram import errors
 
+
 async def get_sticker_set_by_name(client: Client, name: str) -> raw.base.messages.StickerSet:
     try:
         return await client.send(
             raw.functions.messages.GetStickerSet(
-                stickerset = raw.types.InputStickerSetShortName(short_name=name)
+                stickerset=raw.types.InputStickerSetShortName(short_name=name)
             )
         )
     except errors.exceptions.not_acceptable_406.StickersetInvalid:
@@ -16,23 +17,28 @@ async def get_sticker_set_by_name(client: Client, name: str) -> raw.base.message
 # Known errors: (I don't see a reason to catch them as we, for sure, won't face them right now):
 # errors.exceptions.bad_request_400.PackShortNameInvalid -> pack name needs to end with _by_botname
 # errors.exceptions.bad_request_400.ShortnameOccupyFailed -> pack's name is already in use
+
+
 async def create_sticker_set(client: Client, owner: int, title: str, short_name: str, stickers: List[raw.base.InputStickerSetItem]) -> raw.base.messages.StickerSet:
     return await client.send(
         raw.functions.stickers.CreateStickerSet(
-            user_id=await client.resolve_peer(owner), 
+            user_id=await client.resolve_peer(owner),
             title=title,
             short_name=short_name,
             stickers=stickers
         )
     )
 
+
 async def add_sticker_to_set(client: Client, stickerset: raw.base.messages.StickerSet, sticker: raw.base.InputStickerSetItem) -> raw.base.messages.StickerSet:
     return await client.send(
         raw.functions.stickers.AddStickerToSet(
-            stickerset=raw.types.InputStickerSetShortName(short_name=stickerset.set.short_name),
+            stickerset=raw.types.InputStickerSetShortName(
+                short_name=stickerset.set.short_name),
             sticker=sticker
         )
     )
 
+
 async def create_sticker(sticker: raw.base.InputDocument, emoji: str) -> raw.base.InputStickerSetItem:
-    return raw.types.InputStickerSetItem(document=sticker, emoji=emoji)
+    return raw.types.InputStickerSetItem(document=sticker, emoji=emoji)