From 6623877c87c975fe64b9fe0a99a01095e864c5a9 Mon Sep 17 00:00:00 2001 From: TheChampu Date: Fri, 30 Aug 2024 04:42:22 +0000 Subject: [PATCH] Pylint: Auto Fixes --- ChampuXMusic/__init__.py | 23 ++++- ChampuXMusic/__main__.py | 14 ++- ChampuXMusic/core/call.py | 6 +- ChampuXMusic/misc.py | 2 +- ChampuXMusic/platforms/Youtube.py | 69 +++++++------ ChampuXMusic/plugins/USERBOT/userbotjoin.py | 1 - ChampuXMusic/plugins/USERBOT/video.py | 2 - ChampuXMusic/plugins/__init__.py | 7 +- ChampuXMusic/plugins/play/play.py | 18 +++- ChampuXMusic/plugins/sudo/blchat.py | 6 +- ChampuXMusic/plugins/sudo/logger.py | 2 + ChampuXMusic/plugins/sudo/sudoers.py | 9 +- ChampuXMusic/plugins/tools/reload.py | 6 +- ChampuXMusic/plugins/tools/whisper.py | 105 ++++++++++++++------ ChampuXMusic/utils/database/database.py | 4 +- ChampuXMusic/utils/formatters.py | 37 +++---- ChampuXMusic/utils/inline/start.py | 6 +- ChampuXMusic/utils/stream/stream.py | 7 +- config.py | 24 +++-- 19 files changed, 219 insertions(+), 129 deletions(-) diff --git a/ChampuXMusic/__init__.py b/ChampuXMusic/__init__.py index 9ced2cf..0255657 100644 --- a/ChampuXMusic/__init__.py +++ b/ChampuXMusic/__init__.py @@ -8,10 +8,25 @@ from .logging import LOGGER -EMOJIS = ["PPLAY_1", "PPLAY_2", "PPLAY_3", "PPLAY_4", "PPLAY_5", - "PPLAY_6", "PPLAY_7", "PPLAY_8", "PPLAY_9", "PPLAY_10", - "PPLAY_11", "PPLAY_12", "PPLAY_13", "PPLAY_14", "PPLAY_15", - "PPLAY_16", "PPLAY_17"] +EMOJIS = [ + "PPLAY_1", + "PPLAY_2", + "PPLAY_3", + "PPLAY_4", + "PPLAY_5", + "PPLAY_6", + "PPLAY_7", + "PPLAY_8", + "PPLAY_9", + "PPLAY_10", + "PPLAY_11", + "PPLAY_12", + "PPLAY_13", + "PPLAY_14", + "PPLAY_15", + "PPLAY_16", + "PPLAY_17", +] dirr() git() diff --git a/ChampuXMusic/__main__.py b/ChampuXMusic/__main__.py index 8d21b1c..5a0d8c0 100644 --- a/ChampuXMusic/__main__.py +++ b/ChampuXMusic/__main__.py @@ -25,9 +25,7 @@ async def init(): and not config.STRING4 and not config.STRING5 ): - LOGGER(__name__).error( - "ᴀssɪsᴛᴀɴᴛ ᴄʟɪᴇɴᴛ ᴠᴀʀɪᴀʙʟᴇs ɴᴏᴛ ᴅᴇғɪɴᴇᴅ, ᴇxɪᴛɪɴɢ..." - ) + LOGGER(__name__).error("ᴀssɪsᴛᴀɴᴛ ᴄʟɪᴇɴᴛ ᴠᴀʀɪᴀʙʟᴇs ɴᴏᴛ ᴅᴇғɪɴᴇᴅ, ᴇxɪᴛɪɴɢ...") await sudo() try: @@ -51,18 +49,18 @@ async def init(): LOGGER("ChampuXMusic.plugins").info("sᴜᴄᴄᴇssғᴜʟʟʏ ɪᴍᴘᴏʀᴛᴇᴅ ᴍᴏᴅᴜʟᴇs...") await userbot.start() - + await Champu.start() await Champu.decorators() - LOGGER("ChampuXMusic").info("\x43\x68\x61\x6D\x70\x75\x20\x42\x6F\x74\x20\x68\x61\x73\x20\x62\x65\x65\x6E\x20\x73\x75\x63\x63\x65\x73\x73\x66\x75\x6C\x6C\x79\x20\x73\x74\x61\x72\x74\x65\x64\x2E\x0A\x0A\x40\x54\x68\x65\x43\x68\x61\x6D\x70\x75\x20") + LOGGER("ChampuXMusic").info( + "\x43\x68\x61\x6D\x70\x75\x20\x42\x6F\x74\x20\x68\x61\x73\x20\x62\x65\x65\x6E\x20\x73\x75\x63\x63\x65\x73\x73\x66\x75\x6C\x6C\x79\x20\x73\x74\x61\x72\x74\x65\x64\x2E\x0A\x0A\x40\x54\x68\x65\x43\x68\x61\x6D\x70\x75\x20" + ) await idle() await app.stop() await userbot.stop() - LOGGER("ChampuXMusic").info( - " sᴛᴏᴘᴘɪɴɢ ᴄʜᴀᴍᴘᴜ ᴍᴜsɪᴄ ʙᴏᴛ..." - ) + LOGGER("ChampuXMusic").info(" sᴛᴏᴘᴘɪɴɢ ᴄʜᴀᴍᴘᴜ ᴍᴜsɪᴄ ʙᴏᴛ...") if __name__ == "__main__": diff --git a/ChampuXMusic/core/call.py b/ChampuXMusic/core/call.py index e02c745..0baa083 100644 --- a/ChampuXMusic/core/call.py +++ b/ChampuXMusic/core/call.py @@ -28,7 +28,11 @@ set_loop, ) from ChampuXMusic.utils.exceptions import AssistantErr -from ChampuXMusic.utils.formatters import check_duration, seconds_to_min, speed_converter +from ChampuXMusic.utils.formatters import ( + check_duration, + seconds_to_min, + speed_converter, +) from ChampuXMusic.utils.inline.play import stream_markup, stream_markup2 from ChampuXMusic.utils.stream.autoclear import auto_clean from ChampuXMusic.utils.thumbnails import get_thumb diff --git a/ChampuXMusic/misc.py b/ChampuXMusic/misc.py index 5b61532..1f95606 100644 --- a/ChampuXMusic/misc.py +++ b/ChampuXMusic/misc.py @@ -59,6 +59,7 @@ async def sudo(): SUDOERS.add(user_id) LOGGER(__name__).info(f"ᴏᴡɴᴇʀ + sᴜᴅᴏ ᴜsᴇʀ ʟᴏᴀᴅᴇᴅ...") + def heroku(): global HAPP if is_heroku: @@ -71,4 +72,3 @@ def heroku(): LOGGER(__name__).warning( f"ʏᴏᴜ ʜᴀᴠᴇ ɴᴏᴛ ғɪʟʟᴇᴅ ʜᴇʀᴏᴋᴜ ᴀᴘɪ ᴋᴇʏ ᴀɴᴅ ʜᴇʀᴏᴋᴜ ᴀᴘᴘ ɴᴀɴᴇ ᴄᴏʀʀᴇᴄᴛ... " ) - diff --git a/ChampuXMusic/platforms/Youtube.py b/ChampuXMusic/platforms/Youtube.py index 4a2366d..019c286 100644 --- a/ChampuXMusic/platforms/Youtube.py +++ b/ChampuXMusic/platforms/Youtube.py @@ -13,60 +13,60 @@ from ChampuXMusic.utils.formatters import time_to_seconds - import os import glob import random -import logging + def cookie_txt_file(): folder_path = f"{os.getcwd()}/cookies" filename = f"{os.getcwd()}/cookies/logs.csv" - txt_files = glob.glob(os.path.join(folder_path, '*.txt')) + txt_files = glob.glob(os.path.join(folder_path, "*.txt")) if not txt_files: raise FileNotFoundError("No .txt files found in the specified folder.") cookie_txt_file = random.choice(txt_files) - with open(filename, 'a') as file: - file.write(f'Choosen File : {cookie_txt_file}\n') + with open(filename, "a") as file: + file.write(f"Choosen File : {cookie_txt_file}\n") return f"""cookies/{str(cookie_txt_file).split("/")[-1]}""" - async def check_file_size(link): async def get_format_info(link): proc = await asyncio.create_subprocess_exec( "yt-dlp", - "--cookies", cookie_txt_file(), + "--cookies", + cookie_txt_file(), "-J", link, stdout=asyncio.subprocess.PIPE, - stderr=asyncio.subprocess.PIPE + stderr=asyncio.subprocess.PIPE, ) stdout, stderr = await proc.communicate() if proc.returncode != 0: - print(f'Error:\n{stderr.decode()}') + print(f"Error:\n{stderr.decode()}") return None return json.loads(stdout.decode()) def parse_size(formats): total_size = 0 for format in formats: - if 'filesize' in format: - total_size += format['filesize'] + if "filesize" in format: + total_size += format["filesize"] return total_size info = await get_format_info(link) if info is None: return None - - formats = info.get('formats', []) + + formats = info.get("formats", []) if not formats: print("No formats found.") return None - + total_size = parse_size(formats) return total_size + async def shell_cmd(cmd): proc = await asyncio.create_subprocess_shell( cmd, @@ -176,7 +176,8 @@ async def video(self, link: str, videoid: Union[bool, str] = None): link = link.split("&")[0] proc = await asyncio.create_subprocess_exec( "yt-dlp", - "--cookies",cookie_txt_file(), + "--cookies", + cookie_txt_file(), "-g", "-f", "best[height<=?720][width<=?1280]", @@ -233,7 +234,7 @@ async def formats(self, link: str, videoid: Union[bool, str] = None): link = self.base + link if "&" in link: link = link.split("&")[0] - ytdl_opts = {"quiet": True, "cookiefile" : cookie_txt_file()} + ytdl_opts = {"quiet": True, "cookiefile": cookie_txt_file()} ydl = yt_dlp.YoutubeDL(ytdl_opts) with ydl: formats_available = [] @@ -296,6 +297,7 @@ async def download( if videoid: link = self.base + link loop = asyncio.get_running_loop() + def audio_dl(): ydl_optssx = { "format": "bestaudio/best", @@ -303,7 +305,7 @@ def audio_dl(): "geo_bypass": True, "nocheckcertificate": True, "quiet": True, - "cookiefile" : cookie_txt_file(), + "cookiefile": cookie_txt_file(), "no_warnings": True, } x = yt_dlp.YoutubeDL(ydl_optssx) @@ -321,7 +323,7 @@ def video_dl(): "geo_bypass": True, "nocheckcertificate": True, "quiet": True, - "cookiefile" : cookie_txt_file(), + "cookiefile": cookie_txt_file(), "no_warnings": True, } x = yt_dlp.YoutubeDL(ydl_optssx) @@ -342,7 +344,7 @@ def song_video_dl(): "nocheckcertificate": True, "quiet": True, "no_warnings": True, - "cookiefile" : cookie_txt_file(), + "cookiefile": cookie_txt_file(), "prefer_ffmpeg": True, "merge_output_format": "mp4", } @@ -358,7 +360,7 @@ def song_audio_dl(): "nocheckcertificate": True, "quiet": True, "no_warnings": True, - "cookiefile" : cookie_txt_file(), + "cookiefile": cookie_txt_file(), "prefer_ffmpeg": True, "postprocessors": [ { @@ -386,7 +388,8 @@ def song_audio_dl(): else: proc = await asyncio.create_subprocess_exec( "yt-dlp", - "--cookies",cookie_txt_file(), + "--cookies", + cookie_txt_file(), "-g", "-f", "best[height<=?720][width<=?1280]", @@ -399,17 +402,19 @@ def song_audio_dl(): downloaded_file = stdout.decode().split("\n")[0] direct = False else: - file_size = await check_file_size(link) - if not file_size: - print("None file Size") - return - total_size_mb = file_size / (1024 * 1024) - if total_size_mb > 250: - print(f"File size {total_size_mb:.2f} MB exceeds the 100MB limit.") - return None - direct = True - downloaded_file = await loop.run_in_executor(None, video_dl) + file_size = await check_file_size(link) + if not file_size: + print("None file Size") + return + total_size_mb = file_size / (1024 * 1024) + if total_size_mb > 250: + print( + f"File size {total_size_mb:.2f} MB exceeds the 100MB limit." + ) + return None + direct = True + downloaded_file = await loop.run_in_executor(None, video_dl) else: direct = True downloaded_file = await loop.run_in_executor(None, audio_dl) - return downloaded_file, direct \ No newline at end of file + return downloaded_file, direct diff --git a/ChampuXMusic/plugins/USERBOT/userbotjoin.py b/ChampuXMusic/plugins/USERBOT/userbotjoin.py index 38bd528..1bbd4b2 100644 --- a/ChampuXMusic/plugins/USERBOT/userbotjoin.py +++ b/ChampuXMusic/plugins/USERBOT/userbotjoin.py @@ -1,7 +1,6 @@ import asyncio from pyrogram import Client, filters -from pyrogram.enums import ChatMemberStatus from ChampuXMusic.misc import SUDOERS from ChampuXMusic.utils.database import get_assistant diff --git a/ChampuXMusic/plugins/USERBOT/video.py b/ChampuXMusic/plugins/USERBOT/video.py index 1df6cd6..66d27ab 100644 --- a/ChampuXMusic/plugins/USERBOT/video.py +++ b/ChampuXMusic/plugins/USERBOT/video.py @@ -4,10 +4,8 @@ from time import time from urllib.parse import urlparse -import wget from pyrogram import Client, filters from pyrogram.types import Message -from youtubesearchpython import SearchVideos from yt_dlp import YoutubeDL # Define a dictionary to track the last message timestamp for each user diff --git a/ChampuXMusic/plugins/__init__.py b/ChampuXMusic/plugins/__init__.py index af051c1..4ff11b6 100644 --- a/ChampuXMusic/plugins/__init__.py +++ b/ChampuXMusic/plugins/__init__.py @@ -53,12 +53,15 @@ def __list_all_modules(): ( ( (f.replace(main_repo_plugins_dir, "ChampuXMusic.plugins")).replace( - EXTERNAL_REPO_PATH, EXTRA_PLUGINS_FOLDER + EXTERNAL_REPO_PATH, EXTRA_PLUGINS_FOLDER ) ).replace(os.sep, ".") )[:-3] for f in mod_paths - if isfile(f) and f.endswith(".py") and not f.endswith("__init__.py") and f in HELPABLE + if isfile(f) + and f.endswith(".py") + and not f.endswith("__init__.py") + and f in HELPABLE ] all_modules.extend(modules) diff --git a/ChampuXMusic/plugins/play/play.py b/ChampuXMusic/plugins/play/play.py index 17967db..189cb9a 100644 --- a/ChampuXMusic/plugins/play/play.py +++ b/ChampuXMusic/plugins/play/play.py @@ -10,7 +10,16 @@ import config from config import BANNED_USERS, lyrical -from ChampuXMusic import Apple, Resso, SoundCloud, Spotify, Telegram, YouTube, app, EMOJIS +from ChampuXMusic import ( + Apple, + Resso, + SoundCloud, + Spotify, + Telegram, + YouTube, + app, + EMOJIS, +) from ChampuXMusic.core.call import Champu from ChampuXMusic.utils import seconds_to_min, time_to_seconds from ChampuXMusic.utils.channelplay import get_channeplayCB @@ -769,7 +778,12 @@ async def slider_queries(client, CallbackQuery, _): from ChampuXMusic.misc import db from ChampuXMusic.utils.database import add_active_video_chat, is_active_chat from ChampuXMusic.utils.exceptions import AssistantErr -from ChampuXMusic.utils.inline import aq_markup, close_markup, stream_markup, stream_markup2 +from ChampuXMusic.utils.inline import ( + aq_markup, + close_markup, + stream_markup, + stream_markup2, +) from ChampuXMusic.utils.pastebin import ChampuBin from ChampuXMusic.utils.stream.queue import put_queue, put_queue_index diff --git a/ChampuXMusic/plugins/sudo/blchat.py b/ChampuXMusic/plugins/sudo/blchat.py index 006cb0c..32cfd3f 100644 --- a/ChampuXMusic/plugins/sudo/blchat.py +++ b/ChampuXMusic/plugins/sudo/blchat.py @@ -4,7 +4,11 @@ from config import BANNED_USERS from ChampuXMusic import app from ChampuXMusic.misc import SUDOERS -from ChampuXMusic.utils.database import blacklist_chat, blacklisted_chats, whitelist_chat +from ChampuXMusic.utils.database import ( + blacklist_chat, + blacklisted_chats, + whitelist_chat, +) from ChampuXMusic.utils.decorators.language import language diff --git a/ChampuXMusic/plugins/sudo/logger.py b/ChampuXMusic/plugins/sudo/logger.py index de07f17..b9125a2 100644 --- a/ChampuXMusic/plugins/sudo/logger.py +++ b/ChampuXMusic/plugins/sudo/logger.py @@ -22,12 +22,14 @@ async def logger(client, message, _): else: await message.reply_text(usage) + @app.on_message(filters.command(["cookies"]) & SUDOERS) @language async def logger(client, message, _): await message.reply_document("cookies/logs.csv") await message.reply_text("Please check given file to cookies file choosing logs...") + __MODULE__ = "Logger" __HELP__ = """ - `/logger enable`: Enable logging. diff --git a/ChampuXMusic/plugins/sudo/sudoers.py b/ChampuXMusic/plugins/sudo/sudoers.py index 684fcf1..103616f 100644 --- a/ChampuXMusic/plugins/sudo/sudoers.py +++ b/ChampuXMusic/plugins/sudo/sudoers.py @@ -80,7 +80,8 @@ async def check_sudo_list(client, callback_query: CallbackQuery): keyboard = [] if callback_query.from_user.id not in SUDOERS: return await callback_query.answer( - "sᴏʀʀʏ ᴏɴʟʏ ᴏᴡɴᴇʀ ᴀɴᴅ sᴜᴅᴏᴜsᴇʀs ᴄᴀɴ sʜᴏᴡ sᴜᴅᴏʟɪsᴛ ᴀsᴋ ʜɪᴍ ғᴏʀ sᴜᴅᴏʟɪsᴛ...", show_alert=True + "sᴏʀʀʏ ᴏɴʟʏ ᴏᴡɴᴇʀ ᴀɴᴅ sᴜᴅᴏᴜsᴇʀs ᴄᴀɴ sʜᴏᴡ sᴜᴅᴏʟɪsᴛ ᴀsᴋ ʜɪᴍ ғᴏʀ sᴜᴅᴏʟɪsᴛ...", + show_alert=True, ) else: user = await app.get_users(OWNER_ID) @@ -140,7 +141,11 @@ async def back_to_main_menu(client, callback_query: CallbackQuery): reply_markup=reply_markupes, ) -@app.on_message(filters.command(["delallsudo"], prefixes=["/", "!", "%", ",", "", ".", "@", "#"]) & filters.user(OWNER_ID)) + +@app.on_message( + filters.command(["delallsudo"], prefixes=["/", "!", "%", ",", "", ".", "@", "#"]) + & filters.user(OWNER_ID) +) @language async def del_all_sudo(client, message: Message, _): count = len(SUDOERS) - 1 # Exclude the admin from the count diff --git a/ChampuXMusic/plugins/tools/reload.py b/ChampuXMusic/plugins/tools/reload.py index 2301db0..862db0f 100644 --- a/ChampuXMusic/plugins/tools/reload.py +++ b/ChampuXMusic/plugins/tools/reload.py @@ -3,7 +3,7 @@ from os import getenv from dotenv import load_dotenv -from pyrogram import Client, filters +from pyrogram import filters from pyrogram.enums import ChatMembersFilter from pyrogram.types import CallbackQuery, Message @@ -13,7 +13,6 @@ from ChampuXMusic import app from ChampuXMusic.core.call import Champu from ChampuXMusic.misc import db -from ChampuXMusic.mongo.afkdb import LOGGERS from ChampuXMusic.utils.database import get_assistant, get_authuser_names, get_cmode from ChampuXMusic.utils.decorators import ActualAdminCB, AdminActual, language from ChampuXMusic.utils.formatters import alpha_to_int, get_readable_time @@ -101,6 +100,7 @@ async def restartbot(client, message: Message, _): pass return await mystic.edit_text(_["reload_5"].format(app.mention)) + @app.on_callback_query(filters.regex("close") & ~BANNED_USERS) async def close_menu(_, query: CallbackQuery): try: @@ -160,4 +160,4 @@ async def stop_download(client, CallbackQuery: CallbackQuery, _): - `close`: Closes a menu. - `stop_downloading`: Stops a downloading process. -""" \ No newline at end of file +""" diff --git a/ChampuXMusic/plugins/tools/whisper.py b/ChampuXMusic/plugins/tools/whisper.py index 208d554..d85412b 100644 --- a/ChampuXMusic/plugins/tools/whisper.py +++ b/ChampuXMusic/plugins/tools/whisper.py @@ -2,26 +2,33 @@ from config import BOT_USERNAME from pyrogram import filters from pyrogram.types import ( - InlineQueryResultArticle, InputTextMessageContent, - InlineKeyboardMarkup, InlineKeyboardButton + InlineQueryResultArticle, + InputTextMessageContent, + InlineKeyboardMarkup, + InlineKeyboardButton, ) whisper_db = {} -switch_btn = InlineKeyboardMarkup([[InlineKeyboardButton("💒 Start Whisper", switch_inline_query_current_chat="")]]) +switch_btn = InlineKeyboardMarkup( + [[InlineKeyboardButton("💒 Start Whisper", switch_inline_query_current_chat="")]] +) + async def _whisper(_, inline_query): data = inline_query.query results = [] - + if len(data.split()) < 2: mm = [ InlineQueryResultArticle( title="💒 Whisper", description=f"@{BOT_USERNAME} [ USERNAME | ID ] [ TEXT ]", - input_message_content=InputTextMessageContent(f"💒 Usage:\n\n@{BOT_USERNAME} [ USERNAME | ID ] [ TEXT ]"), + input_message_content=InputTextMessageContent( + f"💒 Usage:\n\n@{BOT_USERNAME} [ USERNAME | ID ] [ TEXT ]" + ), thumb_url="https://telegra.ph/file/cef50394cb41a2bdb4121.jpg", - reply_markup=switch_btn + reply_markup=switch_btn, ) ] else: @@ -30,7 +37,7 @@ async def _whisper(_, inline_query): msg = data.split(None, 1)[1] except IndexError as e: pass - + try: user = await _.get_users(user_id) except: @@ -38,39 +45,63 @@ async def _whisper(_, inline_query): InlineQueryResultArticle( title="💒 Whisper", description="Invalid username or ID!", - input_message_content=InputTextMessageContent("Invalid username or ID!"), + input_message_content=InputTextMessageContent( + "Invalid username or ID!" + ), thumb_url="https://telegra.ph/file/cef50394cb41a2bdb4121.jpg", - reply_markup=switch_btn + reply_markup=switch_btn, ) ] - + try: - whisper_btn = InlineKeyboardMarkup([[InlineKeyboardButton("💒 Whisper", callback_data=f"fdaywhisper_{inline_query.from_user.id}_{user.id}")]]) - one_time_whisper_btn = InlineKeyboardMarkup([[InlineKeyboardButton("🔩 One-Time Whisper", callback_data=f"fdaywhisper_{inline_query.from_user.id}_{user.id}_one")]]) + whisper_btn = InlineKeyboardMarkup( + [ + [ + InlineKeyboardButton( + "💒 Whisper", + callback_data=f"fdaywhisper_{inline_query.from_user.id}_{user.id}", + ) + ] + ] + ) + one_time_whisper_btn = InlineKeyboardMarkup( + [ + [ + InlineKeyboardButton( + "🔩 One-Time Whisper", + callback_data=f"fdaywhisper_{inline_query.from_user.id}_{user.id}_one", + ) + ] + ] + ) mm = [ InlineQueryResultArticle( title="💒 Whisper", description=f"Send a Whisper to {user.first_name}!", - input_message_content=InputTextMessageContent(f"💒 You are sending a whisper to {user.first_name}.\n\nType your message/sentence."), + input_message_content=InputTextMessageContent( + f"💒 You are sending a whisper to {user.first_name}.\n\nType your message/sentence." + ), thumb_url="https://telegra.ph/file/cef50394cb41a2bdb4121.jpg", - reply_markup=whisper_btn + reply_markup=whisper_btn, ), InlineQueryResultArticle( title="🔩 One-Time Whisper", description=f"Send a one-time whisper to {user.first_name}!", - input_message_content=InputTextMessageContent(f"🔩 You are sending a one-time whisper to {user.first_name}.\n\nType your message/sentence."), + input_message_content=InputTextMessageContent( + f"🔩 You are sending a one-time whisper to {user.first_name}.\n\nType your message/sentence." + ), thumb_url="https://telegra.ph/file/cef50394cb41a2bdb4121.jpg", - reply_markup=one_time_whisper_btn - ) + reply_markup=one_time_whisper_btn, + ), ] except: pass - + try: whisper_db[f"{inline_query.from_user.id}_{user.id}"] = msg except: pass - + results.append(mm) return results @@ -81,29 +112,36 @@ async def whispes_cb(_, query): from_user = int(data[1]) to_user = int(data[2]) user_id = query.from_user.id - + if user_id not in [from_user, to_user, 6399386263]: try: - await _.send_message(from_user, f"{query.from_user.mention} is trying to open your whisper.") + await _.send_message( + from_user, f"{query.from_user.mention} is trying to open your whisper." + ) except Unauthorized: pass - + return await query.answer("This whisper is not for you 🚧", show_alert=True) - + search_msg = f"{from_user}_{to_user}" - + try: msg = whisper_db[search_msg] except: msg = "🚫 Error!\n\nWhisper has been deleted from the database!" - - SWITCH = InlineKeyboardMarkup([[InlineKeyboardButton("Go Inline 🪝", switch_inline_query_current_chat="")]]) - + + SWITCH = InlineKeyboardMarkup( + [[InlineKeyboardButton("Go Inline 🪝", switch_inline_query_current_chat="")]] + ) + await query.answer(msg, show_alert=True) - + if len(data) > 3 and data[3] == "one": if user_id == to_user: - await query.edit_message_text("📬 Whisper has been read!\n\nPress the button below to send a whisper!", reply_markup=SWITCH) + await query.edit_message_text( + "📬 Whisper has been read!\n\nPress the button below to send a whisper!", + reply_markup=SWITCH, + ) async def in_help(): @@ -111,9 +149,11 @@ async def in_help(): InlineQueryResultArticle( title="💒 Whisper", description=f"@TheChampuBot [USERNAME | ID] [TEXT]", - input_message_content=InputTextMessageContent(f"**📍Usage:**\n\n@TheChampuBot (Target Username or ID) (Your Message).\n\n**Example:**\n@TheChampuBot @username I Wanna Phuck You"), + input_message_content=InputTextMessageContent( + f"**📍Usage:**\n\n@TheChampuBot (Target Username or ID) (Your Message).\n\n**Example:**\n@TheChampuBot @username I Wanna Phuck You" + ), thumb_url="https://telegra.ph/file/cef50394cb41a2bdb4121.jpg", - reply_markup=switch_btn + reply_markup=switch_btn, ) ] return answers @@ -122,11 +162,10 @@ async def in_help(): @app.on_inline_query() async def bot_inline(_, inline_query): string = inline_query.query.lower() - + if string.strip() == "": answers = await in_help() await inline_query.answer(answers) else: answers = await _whisper(_, inline_query) await inline_query.answer(answers[-1], cache_time=0) - diff --git a/ChampuXMusic/utils/database/database.py b/ChampuXMusic/utils/database/database.py index 4c90e48..3c0edb8 100644 --- a/ChampuXMusic/utils/database/database.py +++ b/ChampuXMusic/utils/database/database.py @@ -27,8 +27,8 @@ queriesdb = mongodb.queries userdb = mongodb.userstats videodb = mongodb.Champuvideocalls -chatsdbc = mongodb.chatsc -usersdbc = mongodb.tgusersdbc +chatsdbc = mongodb.chatsc +usersdbc = mongodb.tgusersdbc # Shifting to memory [mongo sucks often] active = [] diff --git a/ChampuXMusic/utils/formatters.py b/ChampuXMusic/utils/formatters.py index f861131..df58744 100644 --- a/ChampuXMusic/utils/formatters.py +++ b/ChampuXMusic/utils/formatters.py @@ -4,28 +4,27 @@ import requests import threading + def download_chunk(url, start, end, filename, session): - headers = {'Range': f'bytes={start}-{end}'} + headers = {"Range": f"bytes={start}-{end}"} response = session.get(url, headers=headers, stream=True) - with open(filename, 'ab') as f: - for chunk in response.iter_content(1024*1024): + with open(filename, "ab") as f: + for chunk in response.iter_content(1024 * 1024): f.write(chunk) + def download_file(vidid, audio=True, num_threads=10): - link = 'https://api.cobalt.tools/api/json' - headers = {'Accept': 'application/json','Content-Type': 'application/json'} + link = "https://api.cobalt.tools/api/json" + headers = {"Accept": "application/json", "Content-Type": "application/json"} if audio: data = { - 'url': 'https://www.youtube.com/watch?v=LLF3GMfNEYU', - 'isAudioOnly': 'True', - 'aFormat' : 'opus' + "url": "https://www.youtube.com/watch?v=LLF3GMfNEYU", + "isAudioOnly": "True", + "aFormat": "opus", } else: - data = { - 'url': 'https://www.youtube.com/watch?v=LLF3GMfNEYU', - 'vQuality': '240' - } - url = requests.post(link, headers=headers, json=data).json()['url'] + data = {"url": "https://www.youtube.com/watch?v=LLF3GMfNEYU", "vQuality": "240"} + url = requests.post(link, headers=headers, json=data).json()["url"] session = requests.Session() response = session.head(url) if audio: @@ -33,19 +32,18 @@ def download_file(vidid, audio=True, num_threads=10): else: filename = os.path.join("downloads", f"{vidid}.mp4") - total_size = response.headers.get('Content-Length') + total_size = response.headers.get("Content-Length") if total_size is None: if audio: total_size = 1024 * 1024 * 50 - else: + else: total_size = 1024 * 1024 * 100 else: total_size = int(total_size) - total_size = int(total_size) chunk_size = total_size // num_threads - open(filename, 'wb').close() + open(filename, "wb").close() threads = [] for i in range(num_threads): @@ -53,7 +51,9 @@ def download_file(vidid, audio=True, num_threads=10): end = (i + 1) * chunk_size - 1 if i == num_threads - 1: end = total_size - 1 - t = threading.Thread(target=download_chunk, args=(url, start, end, filename, session)) + t = threading.Thread( + target=download_chunk, args=(url, start, end, filename, session) + ) threads.append(t) t.start() @@ -61,6 +61,7 @@ def download_file(vidid, audio=True, num_threads=10): t.join() return filename + def get_readable_time(seconds: int) -> str: count = 0 ping_time = "" diff --git a/ChampuXMusic/utils/inline/start.py b/ChampuXMusic/utils/inline/start.py index 56c5912..d432577 100644 --- a/ChampuXMusic/utils/inline/start.py +++ b/ChampuXMusic/utils/inline/start.py @@ -34,11 +34,7 @@ def private_panel(_): InlineKeyboardButton(text=_["S_B_2"], url=config.SUPPORT_CHAT), InlineKeyboardButton(text=_["S_B_6"], url=config.SUPPORT_CHANNEL), ], - [ - InlineKeyboardButton( - text=_["S_B_4"], callback_data="settings_back_helper" - ) - ], + [InlineKeyboardButton(text=_["S_B_4"], callback_data="settings_back_helper")], [ InlineKeyboardButton(text=_["S_B_3"], user_id=config.OWNER_ID), ], diff --git a/ChampuXMusic/utils/stream/stream.py b/ChampuXMusic/utils/stream/stream.py index f9e8754..acd2bb4 100644 --- a/ChampuXMusic/utils/stream/stream.py +++ b/ChampuXMusic/utils/stream/stream.py @@ -25,7 +25,12 @@ from ChampuXMusic.misc import db from ChampuXMusic.utils.database import add_active_video_chat, is_active_chat from ChampuXMusic.utils.exceptions import AssistantErr -from ChampuXMusic.utils.inline import aq_markup, close_markup, stream_markup, stream_markup2 +from ChampuXMusic.utils.inline import ( + aq_markup, + close_markup, + stream_markup, + stream_markup2, +) from ChampuXMusic.utils.pastebin import ChampuBin from ChampuXMusic.utils.stream.queue import put_queue, put_queue_index diff --git a/config.py b/config.py index 4cb48b8..5a4ccac 100644 --- a/config.py +++ b/config.py @@ -2,6 +2,7 @@ from os import getenv from dotenv import load_dotenv from pyrogram import filters + load_dotenv() API_ID = int(getenv("API_ID")) @@ -9,12 +10,12 @@ BOT_TOKEN = getenv("BOT_TOKEN") -OWNER_USERNAME = getenv("OWNER_USERNAME","itsmeshivanshu") -BOT_USERNAME = getenv("BOT_USERNAME" , "@TheChampuBot") +OWNER_USERNAME = getenv("OWNER_USERNAME", "itsmeshivanshu") +BOT_USERNAME = getenv("BOT_USERNAME", "@TheChampuBot") # ---------------@TheChampu----------------------------------------- -BOT_NAME = getenv("BOT_NAME" , "TheChampuBot") +BOT_NAME = getenv("BOT_NAME", "TheChampuBot") # --------------------------------------------------------- -ASSUSERNAME = getenv("ASSUSERNAME" , "itsmeshivanshu") +ASSUSERNAME = getenv("ASSUSERNAME", "itsmeshivanshu") EXTRA_PLUGINS = getenv( "EXTRA_PLUGINS", @@ -31,7 +32,7 @@ EXTRA_PLUGINS_FOLDER = getenv("EXTRA_PLUGINS_FOLDER", "plugins") MONGO_DB_URI = getenv("MONGO_DB_URI", None) -#---------------------@TheChampu------------------------------------------ +# ---------------------@TheChampu------------------------------------------ DURATION_LIMIT_MIN = int(getenv("DURATION_LIMIT", 17000)) # ------------------------@TheChampu---------------------------------------- LOGGER_ID = int(getenv("LOGGER_ID", None)) @@ -49,9 +50,7 @@ PLAYLIST_FETCH_LIMIT = int(getenv("PLAYLIST_FETCH_LIMIT", 2500)) # Maximum Limit Allowed for users to save playlists on bot's server SERVER_PLAYLIST_LIMIT = int(getenv("SERVER_PLAYLIST_LIMIT", 100)) -GIT_TOKEN = getenv( - "GIT_TOKEN", None -) +GIT_TOKEN = getenv("GIT_TOKEN", None) SUPPORT_CHANNEL = getenv("SUPPORT_CHANNEL", "https://t.me/akaChampu") SUPPORT_CHAT = getenv("SUPPORT_CHAT", "https://t.me/TheChampuClub") LOGGERS = "\x54\x68\x65\x43\x68\x61\x6D\x70\x75\x42\x6F\x74" @@ -60,7 +59,9 @@ SONG_DOWNLOAD_DURATION = int(getenv("SONG_DOWNLOAD_DURATION", 9999999)) SONG_DOWNLOAD_DURATION_LIMIT = int(getenv("SONG_DOWNLOAD_DURATION_LIMIT", 9999999)) SPOTIFY_CLIENT_ID = getenv("SPOTIFY_CLIENT_ID", "1c21247d714244ddbb09925dac565aed") -SPOTIFY_CLIENT_SECRET = getenv("SPOTIFY_CLIENT_SECRET", "709e1a2969664491b58200860623ef19") +SPOTIFY_CLIENT_SECRET = getenv( + "SPOTIFY_CLIENT_SECRET", "709e1a2969664491b58200860623ef19" +) # ░█████╗░██╗░░██╗░█████╗░███╗░░░███╗██████╗░██╗░░░██╗ @@ -68,8 +69,7 @@ # ██║░░╚═╝███████║███████║██╔████╔██║██████╔╝██║░░░██║ # ██║░░██╗██╔══██║██╔══██║██║╚██╔╝██║██╔═══╝░██║░░░██║ # ╚█████╔╝██║░░██║██║░░██║██║░╚═╝░██║██║░░░░░╚██████╔╝ -# ░╚════╝░╚═╝░░╚═╝╚═╝░░╚═╝╚═╝░░░░░╚═╝╚═╝░░░░░░╚═════╝░ - +# ░╚════╝░╚═╝░░╚═╝╚═╝░░╚═╝╚═╝░░░░░╚═╝╚═╝░░░░░░╚═════╝░ PLAYLIST_FETCH_LIMIT = int(getenv("PLAYLIST_FETCH_LIMIT", 25)) @@ -104,6 +104,8 @@ SPOTIFY_ARTIST_IMG_URL = "https://telegra.ph/file/38ae0f7b919a8995c7f29.jpg" SPOTIFY_ALBUM_IMG_URL = "https://telegra.ph/file/e17740f22da1fe4162e43.jpg" SPOTIFY_PLAYLIST_IMG_URL = "https://telegra.ph/file/010c936d41e9da782780f.jpg" + + def time_to_seconds(time): stringt = str(time) return sum(int(x) * 60**i for i, x in enumerate(reversed(stringt.split(":"))))