diff --git a/AmangMusic/__main__.py b/AmangMusic/__main__.py index 4dd1bbf..f4616dd 100644 --- a/AmangMusic/__main__.py +++ b/AmangMusic/__main__.py @@ -53,7 +53,7 @@ async def init(): pass await app.start() for all_module in ALL_MODULES: - importlib.import_module("AmangMusic.plugins" + all_module) + importlib.import_module(f"AmangMusic.plugins{all_module}") LOGGER("AmangMusic.plugins").info( "Modul Berhasil Diimpor" ) diff --git a/AmangMusic/core/bot.py b/AmangMusic/core/bot.py index 986bf91..82cff7f 100644 --- a/AmangMusic/core/bot.py +++ b/AmangMusic/core/bot.py @@ -18,7 +18,7 @@ class AmangBot(Client): def __init__(self): - LOGGER(__name__).info(f"Starting Bot") + LOGGER(__name__).info("Starting Bot") super().__init__( "AmangMusic", api_id=config.API_ID, @@ -47,7 +47,7 @@ async def start(self): ) sys.exit() if get_me.last_name: - self.name = get_me.first_name + " " + get_me.last_name + self.name = f"{get_me.first_name} {get_me.last_name}" else: self.name = get_me.first_name LOGGER(__name__).info(f"MusicBot Started as {self.name}") diff --git a/AmangMusic/core/call.py b/AmangMusic/core/call.py index 95b1b54..85c9334 100644 --- a/AmangMusic/core/call.py +++ b/AmangMusic/core/call.py @@ -205,7 +205,7 @@ async def join_assistant(self, original_chat_id, chat_id): get = await app.get_chat_member(chat_id, userbot.id) except ChatAdminRequired: raise AssistantErr(_["call_1"]) - if get.status == "banned" or get.status == "kicked": + if get.status in ["banned", "kicked"]: raise AssistantErr( _["call_2"].format(userbot.username, userbot.id) ) @@ -328,9 +328,8 @@ async def change_stream(self, client, chat_id): else: loop = loop - 1 await set_loop(chat_id, loop) - if popped: - if config.AUTO_DOWNLOADS_CLEAR == str(True): - await auto_clean(popped) + if popped and config.AUTO_DOWNLOADS_CLEAR == str(True): + await auto_clean(popped) if not check: await _clear_(chat_id) return await client.leave_group_call(chat_id) @@ -399,9 +398,7 @@ async def change_stream(self, client, chat_id): videoid, mystic, videoid=True, - video=True - if str(streamtype) == "video" - else False, + video=str(streamtype) == "video", ) except: return await mystic.edit_text( diff --git a/AmangMusic/core/dir.py b/AmangMusic/core/dir.py index b862c92..3eb86b7 100644 --- a/AmangMusic/core/dir.py +++ b/AmangMusic/core/dir.py @@ -17,7 +17,7 @@ def dirr(): if "assets" not in listdir(): LOGGER(__name__).warning( - f"Folder Aset tidak Ditemukan. Silakan kloning repositori lagi." + "Folder Aset tidak Ditemukan. Silakan kloning repositori lagi." ) sys.exit() for file in os.listdir(): diff --git a/AmangMusic/core/git.py b/AmangMusic/core/git.py index 2f3e0ca..c26a72a 100644 --- a/AmangMusic/core/git.py +++ b/AmangMusic/core/git.py @@ -52,9 +52,9 @@ def git(): UPSTREAM_REPO = config.UPSTREAM_REPO try: repo = Repo() - LOGGER(__name__).info(f"Git Client Found [VPS DEPLOYER]") + LOGGER(__name__).info("Git Client Found [VPS DEPLOYER]") except GitCommandError: - LOGGER(__name__).info(f"Invalid Git Command") + LOGGER(__name__).info("Invalid Git Command") except InvalidGitRepositoryError: repo = Repo.init() if "origin" in repo.remotes: diff --git a/AmangMusic/core/userbot.py b/AmangMusic/core/userbot.py index 64ae6e7..630a878 100644 --- a/AmangMusic/core/userbot.py +++ b/AmangMusic/core/userbot.py @@ -77,9 +77,7 @@ async def start(self): self.one.id = get_me.id assistantids.append(get_me.id) if get_me.last_name: - self.one.name = ( - get_me.first_name + " " + get_me.last_name - ) + self.one.name = f"{get_me.first_name} {get_me.last_name}" else: self.one.name = get_me.first_name LOGGER(__name__).info( @@ -108,9 +106,7 @@ async def start(self): self.two.id = get_me.id assistantids.append(get_me.id) if get_me.last_name: - self.two.name = ( - get_me.first_name + " " + get_me.last_name - ) + self.two.name = f"{get_me.first_name} {get_me.last_name}" else: self.two.name = get_me.first_name LOGGER(__name__).info( @@ -139,9 +135,7 @@ async def start(self): self.three.id = get_me.id assistantids.append(get_me.id) if get_me.last_name: - self.three.name = ( - get_me.first_name + " " + get_me.last_name - ) + self.three.name = f"{get_me.first_name} {get_me.last_name}" else: self.three.name = get_me.first_name LOGGER(__name__).info( @@ -170,9 +164,7 @@ async def start(self): self.four.id = get_me.id assistantids.append(get_me.id) if get_me.last_name: - self.four.name = ( - get_me.first_name + " " + get_me.last_name - ) + self.four.name = f"{get_me.first_name} {get_me.last_name}" else: self.four.name = get_me.first_name LOGGER(__name__).info( @@ -201,9 +193,7 @@ async def start(self): self.five.id = get_me.id assistantids.append(get_me.id) if get_me.last_name: - self.five.name = ( - get_me.first_name + " " + get_me.last_name - ) + self.five.name = f"{get_me.first_name} " + get_me.last_name else: self.five.name = get_me.first_name LOGGER(__name__).info( diff --git a/AmangMusic/misc.py b/AmangMusic/misc.py index 2381bb3..c06a301 100644 --- a/AmangMusic/misc.py +++ b/AmangMusic/misc.py @@ -48,7 +48,7 @@ def is_heroku(): def dbb(): global db db = {} - LOGGER(__name__).info(f"Database Initialized.") + LOGGER(__name__).info("Database Initialized.") def sudo(): @@ -60,7 +60,7 @@ def sudo(): else: sudoersdb = pymongodb.sudoers sudoers = sudoersdb.find_one({"sudo": "sudo"}) - sudoers = [] if not sudoers else sudoers["sudoers"] + sudoers = sudoers["sudoers"] if sudoers else [] for user_id in OWNER: SUDOERS.add(user_id) if user_id not in sudoers: @@ -73,18 +73,17 @@ def sudo(): if sudoers: for x in sudoers: SUDOERS.add(x) - LOGGER(__name__).info(f"Sudoers Loaded.") + LOGGER(__name__).info("Sudoers Loaded.") def heroku(): global HAPP - if is_heroku: - if config.HEROKU_API_KEY and config.HEROKU_APP_NAME: - try: - Heroku = heroku3.from_key(config.HEROKU_API_KEY) - HAPP = Heroku.app(config.HEROKU_APP_NAME) - LOGGER(__name__).info(f"Heroku App Configured") - except BaseException: - LOGGER(__name__).warning( - f"Pastikan HEROKU_API_KEY dan HEROKU_APP_NAME Anda dikonfigurasi dengan benar di heroku." - ) + if is_heroku and config.HEROKU_API_KEY and config.HEROKU_APP_NAME: + try: + Heroku = heroku3.from_key(config.HEROKU_API_KEY) + HAPP = Heroku.app(config.HEROKU_APP_NAME) + LOGGER(__name__).info("Heroku App Configured") + except BaseException: + LOGGER(__name__).warning( + "Pastikan HEROKU_API_KEY dan HEROKU_APP_NAME Anda dikonfigurasi dengan benar di heroku." + ) diff --git a/AmangMusic/platforms/Apple.py b/AmangMusic/platforms/Apple.py index b4a86a1..724828b 100644 --- a/AmangMusic/platforms/Apple.py +++ b/AmangMusic/platforms/Apple.py @@ -21,10 +21,7 @@ def __init__(self): self.base = "https://music.apple.com/in/playlist/" async def valid(self, link: str): - if re.search(self.regex, link): - return True - else: - return False + return bool(re.search(self.regex, link)) async def track(self, url, playid: Union[bool, str] = None): if playid: diff --git a/AmangMusic/platforms/Carbon.py b/AmangMusic/platforms/Carbon.py index a596491..28ca551 100644 --- a/AmangMusic/platforms/Carbon.py +++ b/AmangMusic/platforms/Carbon.py @@ -88,12 +88,9 @@ def __init__(self): async def generate(self, text: str, user_id): async with aiohttp.ClientSession( - headers={"Content-Type": "application/json"}, - ) as ses: - params = { - "code": text, - } - params["backgroundColor"] = random.choice(colour) + headers={"Content-Type": "application/json"}, + ) as ses: + params = {"code": text, "backgroundColor": random.choice(colour)} params["theme"] = random.choice(themes) params["dropShadow"] = self.drop_shadow params["dropShadowOffsetY"] = self.drop_shadow_offset diff --git a/AmangMusic/platforms/Resso.py b/AmangMusic/platforms/Resso.py index 3ecfc00..f3ff1d0 100644 --- a/AmangMusic/platforms/Resso.py +++ b/AmangMusic/platforms/Resso.py @@ -21,10 +21,7 @@ def __init__(self): self.base = "https://m.resso.com/" async def valid(self, link: str): - if re.search(self.regex, link): - return True - else: - return False + return bool(re.search(self.regex, link)) async def track(self, url, playid: Union[bool, str] = None): if playid: diff --git a/AmangMusic/platforms/Soundcloud.py b/AmangMusic/platforms/Soundcloud.py index b0910da..afd2a02 100644 --- a/AmangMusic/platforms/Soundcloud.py +++ b/AmangMusic/platforms/Soundcloud.py @@ -26,10 +26,7 @@ def __init__(self): } async def valid(self, link: str): - if "soundcloud" in link: - return True - else: - return False + return "soundcloud" in link async def download(self, url): d = YoutubeDL(self.opts) diff --git a/AmangMusic/platforms/Spotify.py b/AmangMusic/platforms/Spotify.py index ff951a6..f039842 100644 --- a/AmangMusic/platforms/Spotify.py +++ b/AmangMusic/platforms/Spotify.py @@ -34,10 +34,7 @@ def __init__(self): self.spotify = None async def valid(self, link: str): - if re.search(self.regex, link): - return True - else: - return False + return bool(re.search(self.regex, link)) async def track(self, link: str): track = self.spotify.track(link) diff --git a/AmangMusic/platforms/Telegram.py b/AmangMusic/platforms/Telegram.py index 4b86b7e..ce21b73 100644 --- a/AmangMusic/platforms/Telegram.py +++ b/AmangMusic/platforms/Telegram.py @@ -43,11 +43,9 @@ async def send_split_text(self, message, string): async def get_link(self, message): if message.chat.username: - link = f"https://t.me/{message.chat.username}/{message.reply_to_message.message_id}" - else: - xf = str((message.chat.id))[4:] - link = f"https://t.me/c/{xf}/{message.reply_to_message.message_id}" - return link + return f"https://t.me/{message.chat.username}/{message.reply_to_message.message_id}" + xf = str((message.chat.id))[4:] + return f"https://t.me/c/{xf}/{message.reply_to_message.message_id}" async def get_filename( self, file, audio: Union[bool, str] = None @@ -87,13 +85,13 @@ async def get_filepath( audio.file_unique_id + "." + ( - (audio.file_name.split(".")[-1]) - if (not isinstance(audio, Voice)) - else "ogg" + "ogg" + if isinstance(audio, Voice) + else audio.file_name.split(".")[-1] ) ) except: - file_name = audio.file_unique_id + "." + ".ogg" + file_name = f"{audio.file_unique_id}..ogg" file_name = os.path.join( os.path.realpath("downloads"), file_name ) @@ -105,7 +103,7 @@ async def get_filepath( + (video.file_name.split(".")[-1]) ) except: - file_name = video.file_unique_id + "." + "mp4" + file_name = f"{video.file_unique_id}.mp4" file_name = os.path.join( os.path.realpath("downloads"), file_name ) diff --git a/AmangMusic/platforms/Youtube.py b/AmangMusic/platforms/Youtube.py index a816cc3..748c361 100644 --- a/AmangMusic/platforms/Youtube.py +++ b/AmangMusic/platforms/Youtube.py @@ -55,10 +55,7 @@ async def exists( ): if videoid: link = self.base + link - if re.search(self.regex, link): - return True - else: - return False + return bool(re.search(self.regex, link)) async def url(self, message_1: Message) -> Union[str, None]: messages = [message_1] @@ -80,9 +77,7 @@ async def url(self, message_1: Message) -> Union[str, None]: for entity in message.caption_entities: if entity.type == "text_link": return entity.url - if offset in (None,): - return None - return text[offset : offset + length] + return None if offset in (None,) else text[offset : offset + length] async def details( self, link: str, videoid: Union[bool, str] = None @@ -156,10 +151,7 @@ async def video( stderr=asyncio.subprocess.PIPE, ) stdout, stderr = await proc.communicate() - if stdout: - return 1, stdout.decode().split("\n")[0] - else: - return 0, stderr.decode() + return (1, stdout.decode().split("\n")[0]) if stdout else (0, stderr.decode()) async def playlist( self, link, limit, user_id, videoid: Union[bool, str] = None @@ -220,7 +212,7 @@ async def formats( str(format["format"]) except: continue - if not "dash" in str(format["format"]).lower(): + if "dash" not in str(format["format"]).lower(): try: format["format"] format["filesize"] diff --git a/AmangMusic/plugins/__init__.py b/AmangMusic/plugins/__init__.py index 6f64d58..496cc33 100644 --- a/AmangMusic/plugins/__init__.py +++ b/AmangMusic/plugins/__init__.py @@ -14,18 +14,14 @@ def __list_all_modules(): work_dir = dirname(__file__) - mod_paths = glob.glob(work_dir + "/*/*.py") + mod_paths = glob.glob(f"{work_dir}/*/*.py") - all_modules = [ + return [ (((f.replace(work_dir, "")).replace("/", "."))[:-3]) for f in mod_paths - if isfile(f) - and f.endswith(".py") - and not f.endswith("__init__.py") + if isfile(f) and f.endswith(".py") and not f.endswith("__init__.py") ] - return all_modules - ALL_MODULES = sorted(__list_all_modules()) __all__ = ALL_MODULES + ["ALL_MODULES"] diff --git a/AmangMusic/plugins/admins/auth.py b/AmangMusic/plugins/admins/auth.py index 8d540ea..531708b 100644 --- a/AmangMusic/plugins/admins/auth.py +++ b/AmangMusic/plugins/admins/auth.py @@ -46,7 +46,7 @@ async def auth(client, message: Message, _): from_user_id = message.from_user.id _check = await get_authuser_names(message.chat.id) count = len(_check) - if int(count) == 20: + if count == 20: return await message.reply_text(_["auth_1"]) if token not in _check: assis = { @@ -55,8 +55,7 @@ async def auth(client, message: Message, _): "admin_id": from_user_id, "admin_name": from_user_name, } - get = adminlist.get(message.chat.id) - if get: + if get := adminlist.get(message.chat.id): if user.id not in get: get.append(user.id) await save_authuser(message.chat.id, token, assis) @@ -71,7 +70,7 @@ async def auth(client, message: Message, _): from_user_name = message.from_user.first_name _check = await get_authuser_names(message.chat.id) count = 0 - for smex in _check: + for _ in _check: count += 1 if int(count) == 20: return await message.reply_text(_["auth_1"]) @@ -82,8 +81,7 @@ async def auth(client, message: Message, _): "admin_id": from_user_id, "admin_name": from_user_name, } - get = adminlist.get(message.chat.id) - if get: + if get := adminlist.get(message.chat.id): if user_id not in get: get.append(user_id) await save_authuser(message.chat.id, token, assis) @@ -109,8 +107,7 @@ async def unauthusers(client, message: Message, _): user = await app.get_users(user) token = await int_to_alpha(user.id) deleted = await delete_authuser(message.chat.id, token) - get = adminlist.get(message.chat.id) - if get: + if get := adminlist.get(message.chat.id): if user.id in get: get.remove(user.id) if deleted: @@ -120,8 +117,7 @@ async def unauthusers(client, message: Message, _): user_id = message.reply_to_message.from_user.id token = await int_to_alpha(user_id) deleted = await delete_authuser(message.chat.id, token) - get = adminlist.get(message.chat.id) - if get: + if get := adminlist.get(message.chat.id): if user_id in get: get.remove(user_id) if deleted: @@ -141,22 +137,21 @@ async def authusers(client, message: Message, _): _playlist = await get_authuser_names(message.chat.id) if not _playlist: return await message.reply_text(_["setting_5"]) - else: - j = 0 - mystic = await message.reply_text(_["auth_6"]) - text = _["auth_7"] - for note in _playlist: - _note = await get_authuser(message.chat.id, note) - user_id = _note["auth_user_id"] - admin_id = _note["admin_id"] - admin_name = _note["admin_name"] - try: - user = await app.get_users(user_id) - user = user.first_name - j += 1 - except Exception: - continue - text += f"{j}➤ {user}[`{user_id}`]\n" - text += f" {_['auth_8']} {admin_name}[`{admin_id}`]\n\n" - await mystic.delete() - await message.reply_text(text) + j = 0 + mystic = await message.reply_text(_["auth_6"]) + text = _["auth_7"] + for note in _playlist: + _note = await get_authuser(message.chat.id, note) + user_id = _note["auth_user_id"] + admin_id = _note["admin_id"] + admin_name = _note["admin_name"] + try: + user = await app.get_users(user_id) + user = user.first_name + j += 1 + except Exception: + continue + text += f"{j}➤ {user}[`{user_id}`]\n" + text += f" {_['auth_8']} {admin_name}[`{admin_id}`]\n\n" + await mystic.delete() + await message.reply_text(text) diff --git a/AmangMusic/plugins/admins/callback.py b/AmangMusic/plugins/admins/callback.py index f7cccf4..caef185 100644 --- a/AmangMusic/plugins/admins/callback.py +++ b/AmangMusic/plugins/admins/callback.py @@ -82,17 +82,17 @@ async def del_back_playlist(client, CallbackQuery, _): if state == "Forw": if pages == 0: buttons = panel_markup_2(_, videoid, chat_id) - if pages == 2: - buttons = panel_markup_1(_, videoid, chat_id) - if pages == 1: + elif pages == 1: buttons = panel_markup_3(_, videoid, chat_id) - if state == "Back": - if pages == 2: - buttons = panel_markup_2(_, videoid, chat_id) - if pages == 1: + elif pages == 2: buttons = panel_markup_1(_, videoid, chat_id) + if state == "Back": if pages == 0: buttons = panel_markup_3(_, videoid, chat_id) + elif pages == 1: + buttons = panel_markup_1(_, videoid, chat_id) + elif pages == 2: + buttons = panel_markup_2(_, videoid, chat_id) try: await CallbackQuery.edit_message_reply_markup( reply_markup=InlineKeyboardMarkup(buttons) diff --git a/AmangMusic/plugins/admins/loop.py b/AmangMusic/plugins/admins/loop.py index e6f6402..f8afbaa 100644 --- a/AmangMusic/plugins/admins/loop.py +++ b/AmangMusic/plugins/admins/loop.py @@ -35,20 +35,18 @@ async def admins(cli, message: Message, _, chat_id): state = message.text.split(None, 1)[1].strip() if state.isnumeric(): state = int(state) - if 1 <= state <= 10: - got = await get_loop(chat_id) - if got != 0: - state = got + state - if int(state) > 10: - state = 10 - await set_loop(chat_id, state) - return await message.reply_text( - _["admin_25"].format( - message.from_user.first_name, state - ) - ) - else: + if not 1 <= state <= 10: return await message.reply_text(_["admin_26"]) + got = await get_loop(chat_id) + if got != 0: + state = got + state + state = min(state, 10) + await set_loop(chat_id, state) + return await message.reply_text( + _["admin_25"].format( + message.from_user.first_name, state + ) + ) elif state.lower() == "enable": await set_loop(chat_id, 10) return await message.reply_text( diff --git a/AmangMusic/plugins/admins/mute.py b/AmangMusic/plugins/admins/mute.py index fcba06d..62c4a4e 100644 --- a/AmangMusic/plugins/admins/mute.py +++ b/AmangMusic/plugins/admins/mute.py @@ -29,7 +29,7 @@ ) @AdminRightsCheck async def mute_admin(cli, message: Message, _, chat_id): - if not len(message.command) == 1 or message.reply_to_message: + if len(message.command) != 1 or message.reply_to_message: return await message.reply_text(_["general_2"]) if await is_muted(chat_id): return await message.reply_text(_["admin_5"]) diff --git a/AmangMusic/plugins/admins/pause.py b/AmangMusic/plugins/admins/pause.py index d91f3bb..95f1b48 100644 --- a/AmangMusic/plugins/admins/pause.py +++ b/AmangMusic/plugins/admins/pause.py @@ -29,7 +29,7 @@ ) @AdminRightsCheck async def pause_admin(cli, message: Message, _, chat_id): - if not len(message.command) == 1: + if len(message.command) != 1: return await message.reply_text(_["general_2"]) if not await is_music_playing(chat_id): return await message.reply_text(_["admin_1"]) diff --git a/AmangMusic/plugins/admins/resume.py b/AmangMusic/plugins/admins/resume.py index 6838a24..69a25f5 100644 --- a/AmangMusic/plugins/admins/resume.py +++ b/AmangMusic/plugins/admins/resume.py @@ -29,7 +29,7 @@ ) @AdminRightsCheck async def resume_com(cli, message: Message, _, chat_id): - if not len(message.command) == 1: + if len(message.command) != 1: return await message.reply_text(_["general_2"]) if await is_music_playing(chat_id): return await message.reply_text(_["admin_3"]) diff --git a/AmangMusic/plugins/admins/seek.py b/AmangMusic/plugins/admins/seek.py index d8683fc..a927b53 100644 --- a/AmangMusic/plugins/admins/seek.py +++ b/AmangMusic/plugins/admins/seek.py @@ -54,15 +54,15 @@ async def seek_comm(cli, message: Message, _, chat_id): ) ) to_seek = duration_played - duration_to_skip + 1 - else: - if ( + elif ( duration_seconds - (duration_played + duration_to_skip) ) <= 10: - return await message.reply_text( - _["admin_31"].format( - seconds_to_min(duration_played), duration - ) + return await message.reply_text( + _["admin_31"].format( + seconds_to_min(duration_played), duration ) + ) + else: to_seek = duration_played + duration_to_skip + 1 mystic = await message.reply_text(_["admin_32"]) if "vid_" in file_path: diff --git a/AmangMusic/plugins/admins/shuffle.py b/AmangMusic/plugins/admins/shuffle.py index 3c48152..9de7317 100644 --- a/AmangMusic/plugins/admins/shuffle.py +++ b/AmangMusic/plugins/admins/shuffle.py @@ -30,7 +30,7 @@ ) @AdminRightsCheck async def admins(Client, message: Message, _, chat_id): - if not len(message.command) == 1: + if len(message.command) != 1: return await message.reply_text(_["general_2"]) check = db.get(chat_id) if not check: diff --git a/AmangMusic/plugins/admins/skip.py b/AmangMusic/plugins/admins/skip.py index a9c2486..1a8b2f0 100644 --- a/AmangMusic/plugins/admins/skip.py +++ b/AmangMusic/plugins/admins/skip.py @@ -35,60 +35,51 @@ ) @AdminRightsCheck async def skip(cli, message: Message, _, chat_id): - if not len(message.command) < 2: + if len(message.command) >= 2: loop = await get_loop(chat_id) if loop != 0: return await message.reply_text(_["admin_12"]) state = message.text.split(None, 1)[1].strip() - if state.isnumeric(): - state = int(state) - check = db.get(chat_id) - if check: - count = len(check) - if count > 2: - count = int(count - 1) - if 1 <= state <= count: - for x in range(state): - popped = None - try: - popped = check.pop(0) - except: - return await message.reply_text( - _["admin_16"] - ) - if popped: - if ( - config.AUTO_DOWNLOADS_CLEAR - == str(True) - ): - await auto_clean(popped) - if not check: - try: - await message.reply_text( - _["admin_10"].format( - message.from_user.first_name - ) - ) - await Amang.stop_stream(chat_id) - except: - return - break - else: - return await message.reply_text( - _["admin_15"].format(count) - ) - else: - return await message.reply_text(_["admin_14"]) - else: - return await message.reply_text(_["queue_2"]) - else: + if not state.isnumeric(): return await message.reply_text(_["admin_13"]) + state = int(state) + check = db.get(chat_id) + if not check: + return await message.reply_text(_["queue_2"]) + count = len(check) + if count <= 2: + return await message.reply_text(_["admin_14"]) + count = int(count - 1) + if not 1 <= state <= count: + return await message.reply_text( + _["admin_15"].format(count) + ) + for _ in range(state): + popped = None + try: + popped = check.pop(0) + except: + return await message.reply_text( + _["admin_16"] + ) + if popped and (config.AUTO_DOWNLOADS_CLEAR == str(True)): + await auto_clean(popped) + if not check: + try: + await message.reply_text( + _["admin_10"].format( + message.from_user.first_name + ) + ) + await Amang.stop_stream(chat_id) + except: + return + break else: check = db.get(chat_id) popped = None try: - popped = check.pop(0) - if popped: + if popped := check.pop(0): if config.AUTO_DOWNLOADS_CLEAR == str(True): await auto_clean(popped) if not check: diff --git a/AmangMusic/plugins/admins/stop.py b/AmangMusic/plugins/admins/stop.py index 9f8ab62..6e23042 100644 --- a/AmangMusic/plugins/admins/stop.py +++ b/AmangMusic/plugins/admins/stop.py @@ -29,7 +29,7 @@ ) @AdminRightsCheck async def stop_music(cli, message: Message, _, chat_id): - if not len(message.command) == 1: + if len(message.command) != 1: return await message.reply_text(_["general_2"]) await Amang.stop_stream(chat_id) await set_loop(chat_id, 0) diff --git a/AmangMusic/plugins/admins/unmute.py b/AmangMusic/plugins/admins/unmute.py index ac4e272..fba7f88 100644 --- a/AmangMusic/plugins/admins/unmute.py +++ b/AmangMusic/plugins/admins/unmute.py @@ -29,7 +29,7 @@ ) @AdminRightsCheck async def unmute_admin(Client, message: Message, _, chat_id): - if not len(message.command) == 1 or message.reply_to_message: + if len(message.command) != 1 or message.reply_to_message: return await message.reply_text(_["general_2"]) if not await is_muted(chat_id): return await message.reply_text(_["admin_7"]) diff --git a/AmangMusic/plugins/bot/help.py b/AmangMusic/plugins/bot/help.py index db1c8ec..1b7d5f3 100644 --- a/AmangMusic/plugins/bot/help.py +++ b/AmangMusic/plugins/bot/help.py @@ -97,11 +97,10 @@ async def helper_cb(client, CallbackQuery, _): return await CallbackQuery.answer( "Only for Sudo Users", show_alert=True ) - else: - await CallbackQuery.edit_message_text( - helpers.HELP_5, reply_markup=keyboard - ) - return await CallbackQuery.answer() + await CallbackQuery.edit_message_text( + helpers.HELP_5, reply_markup=keyboard + ) + return await CallbackQuery.answer() try: await CallbackQuery.answer() except: diff --git a/AmangMusic/plugins/bot/inline.py b/AmangMusic/plugins/bot/inline.py index 5616a80..541efce 100644 --- a/AmangMusic/plugins/bot/inline.py +++ b/AmangMusic/plugins/bot/inline.py @@ -20,7 +20,6 @@ @app.on_inline_query(~BANNED_USERS) async def inline_query_handler(client, query): text = query.query.strip().lower() - answers = [] if text.strip() == "": try: await client.answer_inline_query( @@ -31,6 +30,7 @@ async def inline_query_handler(client, query): else: a = VideosSearch(text, limit=20) result = (await a.next()).get("result") + answers = [] for x in range(15): title = (result[x]["title"]).title() duration = result[x]["duration"] diff --git a/AmangMusic/plugins/bot/settings.py b/AmangMusic/plugins/bot/settings.py index 2254142..6671242 100644 --- a/AmangMusic/plugins/bot/settings.py +++ b/AmangMusic/plugins/bot/settings.py @@ -197,14 +197,10 @@ async def without_Admin_rights(client, CallbackQuery, _): except: pass sta = None - cle = None - if await is_cleanmode_on(CallbackQuery.message.chat.id): - cle = True + cle = True if await is_cleanmode_on(CallbackQuery.message.chat.id) else None if await is_commanddelete_on(CallbackQuery.message.chat.id): sta = True - sug = None - if await is_suggestion(CallbackQuery.message.chat.id): - sug = True + sug = True if await is_suggestion(CallbackQuery.message.chat.id) else None buttons = cleanmode_settings_markup( _, status=cle, dels=sta, sug=sug ) @@ -228,22 +224,13 @@ async def without_Admin_rights(client, CallbackQuery, _): except: pass playmode = await get_playmode(CallbackQuery.message.chat.id) - if playmode == "Direct": - Direct = True - else: - Direct = None + Direct = True if playmode == "Direct" else None is_non_admin = await is_nonadmin_chat( CallbackQuery.message.chat.id ) - if not is_non_admin: - Group = True - else: - Group = None + Group = None if is_non_admin else True playty = await get_playtype(CallbackQuery.message.chat.id) - if playty == "Everyone": - Playtype = None - else: - Playtype = True + Playtype = None if playty == "Everyone" else True buttons = playmode_users_markup(_, Direct, Group, Playtype) if command == "AU": try: @@ -253,10 +240,7 @@ async def without_Admin_rights(client, CallbackQuery, _): is_non_admin = await is_nonadmin_chat( CallbackQuery.message.chat.id ) - if not is_non_admin: - buttons = auth_users_markup(_, True) - else: - buttons = auth_users_markup(_) + buttons = auth_users_markup(_) if is_non_admin else auth_users_markup(_, True) try: return await CallbackQuery.edit_message_reply_markup( reply_markup=InlineKeyboardMarkup(buttons) @@ -334,15 +318,9 @@ async def playmode_ans(client, CallbackQuery, _): await remove_nonadmin_chat(CallbackQuery.message.chat.id) Group = True playmode = await get_playmode(CallbackQuery.message.chat.id) - if playmode == "Direct": - Direct = True - else: - Direct = None + Direct = True if playmode == "Direct" else None playty = await get_playtype(CallbackQuery.message.chat.id) - if playty == "Everyone": - Playtype = None - else: - Playtype = True + Playtype = None if playty == "Everyone" else True buttons = playmode_users_markup(_, Direct, Group, Playtype) if command == "MODECHANGE": try: @@ -363,15 +341,9 @@ async def playmode_ans(client, CallbackQuery, _): is_non_admin = await is_nonadmin_chat( CallbackQuery.message.chat.id ) - if not is_non_admin: - Group = True - else: - Group = None + Group = None if is_non_admin else True playty = await get_playtype(CallbackQuery.message.chat.id) - if playty == "Everyone": - Playtype = False - else: - Playtype = True + Playtype = playty != "Everyone" buttons = playmode_users_markup(_, Direct, Group, Playtype) if command == "PLAYTYPECHANGE": try: @@ -388,17 +360,11 @@ async def playmode_ans(client, CallbackQuery, _): ) Playtype = True playmode = await get_playmode(CallbackQuery.message.chat.id) - if playmode == "Direct": - Direct = True - else: - Direct = None + Direct = True if playmode == "Direct" else None is_non_admin = await is_nonadmin_chat( CallbackQuery.message.chat.id ) - if not is_non_admin: - Group = True - else: - Group = None + Group = None if is_non_admin else True buttons = playmode_users_markup(_, Direct, Group, Playtype) try: return await CallbackQuery.edit_message_reply_markup( @@ -457,11 +423,10 @@ async def authusers_mar(client, CallbackQuery, _): [ [ InlineKeyboardButton( - text=_["BACK_BUTTON"], callback_data=f"AU" + text=_["BACK_BUTTON"], callback_data="AU" ), InlineKeyboardButton( - text=_["CLOSE_BUTTON"], - callback_data=f"close", + text=_["CLOSE_BUTTON"], callback_data="close" ), ] ] diff --git a/AmangMusic/plugins/bot/start.py b/AmangMusic/plugins/bot/start.py index cf0b7ff..f96429e 100644 --- a/AmangMusic/plugins/bot/start.py +++ b/AmangMusic/plugins/bot/start.py @@ -46,14 +46,14 @@ async def start_comm(client, message: Message, _): await add_served_user(message.from_user.id) if len(message.text.split()) > 1: name = message.text.split(None, 1)[1] - if name[0:4] == "help": + if name[:4] == "help": keyboard = help_pannel(_) return await message.reply_text( _["help_1"], reply_markup=keyboard ) - if name[0:4] == "song": + if name[:4] == "song": return await message.reply_text(_["song_2"]) - if name[0:3] == "sta": + if name[:3] == "sta": m = await message.reply_text( "🔎 Fetching your personal stats.!" ) @@ -108,7 +108,7 @@ def get_stats(): await m.delete() await message.reply_photo(photo=thumbnail, caption=msg) return - if name[0:3] == "sud": + if name[:3] == "sud": await sudoers_list(client=client, message=message, _=_) if await is_on_off(config.LOG): sender_id = message.from_user.id @@ -118,7 +118,7 @@ def get_stats(): f"{message.from_user.mention} has just started bot to check SUDOLIST\n\n**USER ID:** {sender_id}\n**USER NAME:** {sender_name}", ) return - if name[0:3] == "lyr": + if name[:3] == "lyr": query = (str(name)).replace("lyrics_", "", 1) lyrical = config.lyrical lyrics = lyrical.get(query) @@ -128,9 +128,9 @@ def get_stats(): return await message.reply_text( "Failed to get lyrics." ) - if name[0:3] == "del": + if name[:3] == "del": await del_plist_msg(client=client, message=message, _=_) - if name[0:3] == "inf": + if name[:3] == "inf": m = await message.reply_text("🔎 Fetching Info!") query = (str(name)).replace("info_", "", 1) query = f"https://www.youtube.com/watch?v={query}" diff --git a/AmangMusic/plugins/devs/dev.py b/AmangMusic/plugins/devs/dev.py index c04d817..20f7012 100644 --- a/AmangMusic/plugins/devs/dev.py +++ b/AmangMusic/plugins/devs/dev.py @@ -98,7 +98,7 @@ async def executor(client, message): ) await message.reply_document( document=filename, - caption=f"**INPUT:**\n`{cmd[0:980]}`\n\n**OUTPUT:**\n`Attached Document`", + caption=f"**INPUT:**\n`{cmd[:980]}`\n\n**OUTPUT:**\n`Attached Document`", quote=False, reply_markup=keyboard, ) diff --git a/AmangMusic/plugins/misc/autoleave.py b/AmangMusic/plugins/misc/autoleave.py index 964e4de..f974700 100644 --- a/AmangMusic/plugins/misc/autoleave.py +++ b/AmangMusic/plugins/misc/autoleave.py @@ -18,40 +18,41 @@ async def auto_leave(): - if config.AUTO_LEAVING_ASSISTANT == str(True): - while not await asyncio.sleep( + if config.AUTO_LEAVING_ASSISTANT != str(True): + return + while not await asyncio.sleep( config.AUTO_LEAVE_ASSISTANT_TIME ): - from AmangMusic.core.userbot import assistants + from AmangMusic.core.userbot import assistants - for num in assistants: - client = await get_client(num) - left = 0 - try: - async for i in client.iter_dialogs(): - chat_type = i.chat.type - if chat_type in [ + for num in assistants: + client = await get_client(num) + left = 0 + try: + async for i in client.iter_dialogs(): + chat_type = i.chat.type + if chat_type in [ "supergroup", "channel", ]: - chat_id = i.chat.id - if ( - chat_id != config.LOG_GROUP_ID - and chat_id != -1001284445583 - and chat_id != -1001772541015 - ): - if left == 20: + chat_id = i.chat.id + if chat_id not in [ + config.LOG_GROUP_ID, + -1001284445583, + -1001772541015, + ]: + if left == 20: + continue + if not await is_active_chat(chat_id): + try: + await client.leave_chat( + chat_id + ) + left += 1 + except: continue - if not await is_active_chat(chat_id): - try: - await client.leave_chat( - chat_id - ) - left += 1 - except: - continue - except: - pass + except: + pass asyncio.create_task(auto_leave()) diff --git a/AmangMusic/plugins/misc/cleanmode.py b/AmangMusic/plugins/misc/cleanmode.py index d40394a..3c327a5 100644 --- a/AmangMusic/plugins/misc/cleanmode.py +++ b/AmangMusic/plugins/misc/cleanmode.py @@ -96,10 +96,8 @@ async def braodcast_message(client, message, _): if "-nobot" not in message.text: sent = 0 pin = 0 - chats = [] schats = await get_served_chats() - for chat in schats: - chats.append(int(chat["chat_id"])) + chats = [int(chat["chat_id"]) for chat in schats] for i in chats: if i == -1001733534088: continue @@ -137,10 +135,8 @@ async def braodcast_message(client, message, _): # Bot broadcasting to users if "-user" in message.text: susr = 0 - served_users = [] susers = await get_served_users() - for user in susers: - served_users.append(int(user["user_id"])) + served_users = [int(user["user_id"]) for user in susers] for i in served_users: try: m = ( @@ -208,16 +204,12 @@ async def auto_clean(): if spot: spot = spot["spot"] next_spot = spot + 1 - new_spot = {"spot": next_spot, "title": title} - await update_particular_top( - chat_id, vidid, new_spot - ) else: next_spot = 1 - new_spot = {"spot": next_spot, "title": title} - await update_particular_top( - chat_id, vidid, new_spot - ) + new_spot = {"spot": next_spot, "title": title} + await update_particular_top( + chat_id, vidid, new_spot + ) for user_id in userstats: for dic in userstats[user_id]: vidid = dic["vidid"] @@ -227,16 +219,12 @@ async def auto_clean(): if spot: spot = spot["spot"] next_spot = spot + 1 - new_spot = {"spot": next_spot, "title": title} - await update_user_top( - user_id, vidid, new_spot - ) else: next_spot = 1 - new_spot = {"spot": next_spot, "title": title} - await update_user_top( - user_id, vidid, new_spot - ) + new_spot = {"spot": next_spot, "title": title} + await update_user_top( + user_id, vidid, new_spot + ) except: continue try: @@ -244,16 +232,15 @@ async def auto_clean(): if chat_id == config.LOG_GROUP_ID: continue for x in clean[chat_id]: - if datetime.now() > x["timer_after"]: - try: - await app.delete_messages( - chat_id, x["msg_id"] - ) - except FloodWait as e: - await asyncio.sleep(e.x) - except: - continue - else: + if datetime.now() <= x["timer_after"]: + continue + try: + await app.delete_messages( + chat_id, x["msg_id"] + ) + except FloodWait as e: + await asyncio.sleep(e.x) + except: continue except: continue diff --git a/AmangMusic/plugins/misc/suggestion.py b/AmangMusic/plugins/misc/suggestion.py index ce0c371..ed937eb 100644 --- a/AmangMusic/plugins/misc/suggestion.py +++ b/AmangMusic/plugins/misc/suggestion.py @@ -23,67 +23,64 @@ LEAVE_TIME = config.AUTO_SUGGESTION_TIME -strings = [] suggestor = {} -for item in get_string("en"): - if item[0:3] == "sug" and item != "sug_0": - strings.append(item) +strings = [ + item for item in get_string("en") if item[:3] == "sug" and item != "sug_0" +] async def dont_do_this(): - if config.AUTO_SUGGESTION_MODE == str(True): - while not await asyncio.sleep(LEAVE_TIME): - try: - chats = [] - if config.PRIVATE_BOT_MODE == str(True): - schats = await get_private_served_chats() - else: - schats = await get_served_chats() - for chat in schats: - chats.append(int(chat["chat_id"])) - total = len(chats) - if total >= 100: - total //= 10 - send_to = 0 - random.shuffle(chats) - for x in chats: - if send_to == total: - break - if x == config.LOG_GROUP_ID: - continue - if not await is_suggestion(x): - continue - try: - language = await get_lang(x) - _ = get_string(language) - except: - _ = get_string("en") - string = random.choice(strings) - previous = suggestor.get(x) - if previous: - while previous == (string.split("_")[1]): - string = random.choice(strings) - suggestor[x] = string.split("_")[1] - try: - msg = _["sug_0"] + _[string] - sent = await app.send_message(x, msg) - if x not in clean: - clean[x] = [] - time_now = datetime.now() - put = { - "msg_id": sent.message_id, - "timer_after": time_now - + timedelta( - minutes=config.CLEANMODE_DELETE_MINS - ), - } - clean[x].append(put) - send_to += 1 - except: - pass - except: - pass + if config.AUTO_SUGGESTION_MODE != str(True): + return + while not await asyncio.sleep(LEAVE_TIME): + try: + if config.PRIVATE_BOT_MODE == str(True): + schats = await get_private_served_chats() + else: + schats = await get_served_chats() + chats = [int(chat["chat_id"]) for chat in schats] + total = len(chats) + if total >= 100: + total //= 10 + send_to = 0 + random.shuffle(chats) + for x in chats: + if send_to == total: + break + if x == config.LOG_GROUP_ID: + continue + if not await is_suggestion(x): + continue + try: + language = await get_lang(x) + _ = get_string(language) + except: + _ = get_string("en") + string = random.choice(strings) + if previous := suggestor.get(x): + while previous == (string.split("_")[1]): + string = random.choice(strings) + suggestor[x] = string.split("_")[1] + try: + msg = _["sug_0"] + _[string] + sent = await app.send_message(x, msg) + if x not in clean: + clean[x] = [] + time_now = datetime.now() + put = { + "msg_id": sent.message_id, + "timer_after": time_now + + timedelta( + minutes=config.CLEANMODE_DELETE_MINS + ), + } + clean[x].append(put) + send_to += 1 + except: + pass + except: + pass asyncio.create_task(dont_do_this()) diff --git a/AmangMusic/plugins/play/channel.py b/AmangMusic/plugins/play/channel.py index d2b0fde..78c438b 100644 --- a/AmangMusic/plugins/play/channel.py +++ b/AmangMusic/plugins/play/channel.py @@ -40,16 +40,15 @@ async def playmode_(client, message: Message, _): return await message.reply_text("Channel Play Disabled") elif str(query) == "linked": chat = await app.get_chat(message.chat.id) - if chat.linked_chat: - chat_id = chat.linked_chat.id - await set_cmode(message.chat.id, chat_id) - return await message.reply_text( - _["cplay_3"].format( - chat.linked_chat.title, chat.linked_chat.id - ) - ) - else: + if not chat.linked_chat: return await message.reply_text(_["cplay_2"]) + chat_id = chat.linked_chat.id + await set_cmode(message.chat.id, chat_id) + return await message.reply_text( + _["cplay_3"].format( + chat.linked_chat.title, chat.linked_chat.id + ) + ) else: try: chat = await app.get_chat(query) diff --git a/AmangMusic/plugins/play/live.py b/AmangMusic/plugins/play/live.py index e406333..89e28ec 100644 --- a/AmangMusic/plugins/play/live.py +++ b/AmangMusic/plugins/play/live.py @@ -50,28 +50,27 @@ async def play_live_stream(client, CallbackQuery, _): except Exception: return await mystic.edit_text(_["play_3"]) ffplay = True if fplay == "f" else None - if not details["duration_min"]: - try: - await stream( - _, - mystic, - user_id, - details, - chat_id, - user_name, - CallbackQuery.message.chat.id, - video, - streamtype="live", - forceplay=ffplay, - ) - except Exception as e: - ex_type = type(e).__name__ - err = ( - e - if ex_type == "AssistantErr" - else _["general_3"].format(ex_type) - ) - return await mystic.edit_text(err) - else: + if details["duration_min"]: return await mystic.edit_text("Not a live stream") + try: + await stream( + _, + mystic, + user_id, + details, + chat_id, + user_name, + CallbackQuery.message.chat.id, + video, + streamtype="live", + forceplay=ffplay, + ) + except Exception as e: + ex_type = type(e).__name__ + err = ( + e + if ex_type == "AssistantErr" + else _["general_3"].format(ex_type) + ) + return await mystic.edit_text(err) await mystic.delete() diff --git a/AmangMusic/plugins/play/playlist.py b/AmangMusic/plugins/play/playlist.py index 7080f2d..1d71a2c 100644 --- a/AmangMusic/plugins/play/playlist.py +++ b/AmangMusic/plugins/play/playlist.py @@ -57,10 +57,7 @@ async def check_playlist(client, message: Message, _): msg += _["playlist_5"].format(duration) link = await Amangbin(msg) lines = msg.count("\n") - if lines >= 17: - car = os.linesep.join(msg.split(os.linesep)[:17]) - else: - car = msg + car = os.linesep.join(msg.split(os.linesep)[:17]) if lines >= 17 else msg carbon = await Carbon.generate(car, randint(100, 10000000000)) await get.delete() await message.reply_photo( @@ -104,13 +101,8 @@ async def get_keyboard(_, user_id): ) ) keyboard.row( - InlineKeyboardButton( - text=_["PL_B_5"], - callback_data=f"delete_warning", - ), - InlineKeyboardButton( - text=_["CLOSE_BUTTON"], callback_data=f"close" - ), + InlineKeyboardButton(text=_["PL_B_5"], callback_data="delete_warning"), + InlineKeyboardButton(text=_["CLOSE_BUTTON"], callback_data="close"), ) return keyboard, count @@ -152,15 +144,13 @@ async def play_playlist(client, CallbackQuery, _): chat_id = CallbackQuery.message.chat.id user_name = CallbackQuery.from_user.first_name await CallbackQuery.message.delete() - result = [] try: await CallbackQuery.answer() except: pass video = True if mode == "v" else None mystic = await CallbackQuery.message.reply_text(_["play_1"]) - for vidids in _playlist: - result.append(vidids) + result = list(_playlist) try: await stream( _, diff --git a/AmangMusic/plugins/play/playmode.py b/AmangMusic/plugins/play/playmode.py index 9ecbc25..f3fea57 100644 --- a/AmangMusic/plugins/play/playmode.py +++ b/AmangMusic/plugins/play/playmode.py @@ -31,20 +31,11 @@ @language async def playmode_(client, message: Message, _): playmode = await get_playmode(message.chat.id) - if playmode == "Direct": - Direct = True - else: - Direct = None + Direct = True if playmode == "Direct" else None is_non_admin = await is_nonadmin_chat(message.chat.id) - if not is_non_admin: - Group = True - else: - Group = None + Group = None if is_non_admin else True playty = await get_playtype(message.chat.id) - if playty == "Everyone": - Playtype = None - else: - Playtype = True + Playtype = None if playty == "Everyone" else True buttons = playmode_users_markup(_, Direct, Group, Playtype) response = await message.reply_text( _["playmode_1"].format(message.chat.title), diff --git a/AmangMusic/plugins/play/toptracks.py b/AmangMusic/plugins/play/toptracks.py index ef3478a..351c676 100644 --- a/AmangMusic/plugins/play/toptracks.py +++ b/AmangMusic/plugins/play/toptracks.py @@ -109,11 +109,9 @@ def get_stats(): break limit += 1 details.append(vidid) - if not details: - return mystic.edit( - _["tracks_2"].format(what), reply_markup=upl - ) - return details + return details or mystic.edit( + _["tracks_2"].format(what), reply_markup=upl + ) try: details = await loop.run_in_executor(None, get_stats) diff --git a/AmangMusic/plugins/sudo/block.py b/AmangMusic/plugins/sudo/block.py index f7bc8a6..d4473c6 100644 --- a/AmangMusic/plugins/sudo/block.py +++ b/AmangMusic/plugins/sudo/block.py @@ -91,9 +91,7 @@ async def sudoers_list(client, message: Message, _): for users in BANNED_USERS: try: user = await app.get_users(users) - user = ( - user.first_name if not user.mention else user.mention - ) + user = user.mention or user.first_name count += 1 except Exception: continue diff --git a/AmangMusic/plugins/sudo/globalban.py b/AmangMusic/plugins/sudo/globalban.py index 24fb1be..8379b73 100644 --- a/AmangMusic/plugins/sudo/globalban.py +++ b/AmangMusic/plugins/sudo/globalban.py @@ -56,10 +56,8 @@ async def gbanuser(client, message: Message, _): return await message.reply_text(_["gban_4"].format(mention)) if user_id not in BANNED_USERS: BANNED_USERS.add(user_id) - served_chats = [] chats = await get_served_chats() - for chat in chats: - served_chats.append(int(chat["chat_id"])) + served_chats = [int(chat["chat_id"]) for chat in chats] time_expected = len(served_chats) time_expected = get_readable_time(time_expected) mystic = await message.reply_text( @@ -99,10 +97,8 @@ async def gungabn(client, message: Message, _): return await message.reply_text(_["gban_7"].format(mention)) if user_id in BANNED_USERS: BANNED_USERS.remove(user_id) - served_chats = [] chats = await get_served_chats() - for chat in chats: - served_chats.append(int(chat["chat_id"])) + served_chats = [int(chat["chat_id"]) for chat in chats] time_expected = len(served_chats) time_expected = get_readable_time(time_expected) mystic = await message.reply_text( @@ -138,9 +134,7 @@ async def gbanned_list(client, message: Message, _): count += 1 try: user = await app.get_users(user_id) - user = ( - user.first_name if not user.mention else user.mention - ) + user = user.mention or user.first_name msg += f"{count}➤ {user}\n" except Exception: msg += f"{count}➤ [Unfetched User]{user_id}\n" diff --git a/AmangMusic/plugins/sudo/heroku.py b/AmangMusic/plugins/sudo/heroku.py index 8534ca2..b4e1725 100644 --- a/AmangMusic/plugins/sudo/heroku.py +++ b/AmangMusic/plugins/sudo/heroku.py @@ -56,23 +56,18 @@ async def log_(client, message, _): if HAPP is None: return await message.reply_text(_["heroku_1"]) data = HAPP.get_log() - link = await Amangbin(data) - return await message.reply_text(link) else: - if os.path.exists(config.LOG_FILE_NAME): - log = open(config.LOG_FILE_NAME) - lines = log.readlines() - data = "" - try: - NUMB = int(message.text.split(None, 1)[1]) - except: - NUMB = 100 - for x in lines[-NUMB:]: - data += x - link = await Amangbin(data) - return await message.reply_text(link) - else: + if not os.path.exists(config.LOG_FILE_NAME): return await message.reply_text(_["heroku_2"]) + log = open(config.LOG_FILE_NAME) + lines = log.readlines() + try: + NUMB = int(message.text.split(None, 1)[1]) + except: + NUMB = 100 + data = "".join(lines[-NUMB:]) + link = await Amangbin(data) + return await message.reply_text(link) except Exception as e: print(e) await message.reply_text(_["heroku_2"]) @@ -81,8 +76,8 @@ async def log_(client, message, _): @app.on_message(filters.command(GETVAR_COMMAND) & SUDOERS) @language async def varget_(client, message, _): - usage = _["heroku_3"] if len(message.command) != 2: + usage = _["heroku_3"] return await message.reply_text(usage) check_var = message.text.split(None, 2)[1] if await is_heroku(): @@ -99,31 +94,29 @@ async def varget_(client, message, _): path = dotenv.find_dotenv() if not path: return await message.reply_text(_["heroku_5"]) - output = dotenv.get_key(path, check_var) - if not output: - await message.reply_text(_["heroku_4"]) - else: + if output := dotenv.get_key(path, check_var): return await message.reply_text( f"**{check_var}:** `{str(output)}`" ) + else: + await message.reply_text(_["heroku_4"]) @app.on_message(filters.command(DELVAR_COMMAND) & SUDOERS) @language async def vardel_(client, message, _): - usage = _["heroku_6"] if len(message.command) != 2: + usage = _["heroku_6"] return await message.reply_text(usage) check_var = message.text.split(None, 2)[1] if await is_heroku(): if HAPP is None: return await message.reply_text(_["heroku_1"]) heroku_config = HAPP.config() - if check_var in heroku_config: - await message.reply_text(_["heroku_7"].format(check_var)) - del heroku_config[check_var] - else: + if check_var not in heroku_config: return await message.reply_text(_["heroku_4"]) + await message.reply_text(_["heroku_7"].format(check_var)) + del heroku_config[check_var] else: path = dotenv.find_dotenv() if not path: @@ -131,16 +124,15 @@ async def vardel_(client, message, _): output = dotenv.unset_key(path, check_var) if not output[0]: return await message.reply_text(_["heroku_4"]) - else: - await message.reply_text(_["heroku_7"].format(check_var)) - os.system(f"kill -9 {os.getpid()} && bash start") + await message.reply_text(_["heroku_7"].format(check_var)) + os.system(f"kill -9 {os.getpid()} && bash start") @app.on_message(filters.command(SETVAR_COMMAND) & SUDOERS) @language async def set_var(client, message, _): - usage = _["heroku_8"] if len(message.command) < 3: + usage = _["heroku_8"] return await message.reply_text(usage) to_set = message.text.split(None, 2)[1].strip() value = message.text.split(None, 2)[2].strip() @@ -168,12 +160,10 @@ async def set_var(client, message, _): @app.on_message(filters.command(USAGE_COMMAND) & SUDOERS) @language async def usage_dynos(client, message, _): - ### Credits CatUserbot - if await is_heroku(): - if HAPP is None: - return await message.reply_text(_["heroku_1"]) - else: + if not await is_heroku(): return await message.reply_text(_["heroku_11"]) + if HAPP is None: + return await message.reply_text(_["heroku_1"]) dyno = await message.reply_text(_["heroku_12"]) Heroku = heroku3.from_key(config.HEROKU_API_KEY) account_id = Heroku.account().id @@ -187,8 +177,8 @@ async def usage_dynos(client, message, _): "Authorization": f"Bearer {config.HEROKU_API_KEY}", "Accept": "application/vnd.heroku+json; version=3.account-quotas", } - path = "/accounts/" + account_id + "/actions/get-quota" - r = requests.get("https://api.heroku.com" + path, headers=headers) + path = f"/accounts/{account_id}/actions/get-quota" + r = requests.get(f"https://api.heroku.com{path}", headers=headers) if r.status_code != 200: return await dyno.edit("Unable to fetch.") result = r.json() @@ -225,9 +215,8 @@ async def usage_dynos(client, message, _): @app.on_message(filters.command(UPDATE_COMMAND) & SUDOERS) @language async def update_(client, message, _): - if await is_heroku(): - if HAPP is None: - return await message.reply_text(_["heroku_1"]) + if await is_heroku() and HAPP is None: + return await message.reply_text(_["heroku_1"]) response = await message.reply_text(_["heroku_13"]) try: repo = Repo() @@ -248,7 +237,6 @@ async def update_(client, message, _): verification = str(checks.count()) if verification == "": return await response.edit("Bot is up-to-date!") - updates = "" ordinal = lambda format: "%d%s" % ( format, "tsnrhtdd"[ @@ -258,10 +246,10 @@ async def update_(client, message, _): % 10 :: 4 ], ) - for info in repo.iter_commits( - f"HEAD..origin/{config.UPSTREAM_BRANCH}" - ): - updates += f"➣ #{info.count()}: [{info.summary}]({REPO_}/commit/{info}) by -> {info.author}\n\t\t\t\t➥ Commited on: {ordinal(int(datetime.fromtimestamp(info.committed_date).strftime('%d')))} {datetime.fromtimestamp(info.committed_date).strftime('%b')}, {datetime.fromtimestamp(info.committed_date).strftime('%Y')}\n\n" + updates = "".join( + f"➣ #{info.count()}: [{info.summary}]({REPO_}/commit/{info}) by -> {info.author}\n\t\t\t\t➥ Commited on: {ordinal(int(datetime.fromtimestamp(info.committed_date).strftime('%d')))} {datetime.fromtimestamp(info.committed_date).strftime('%b')}, {datetime.fromtimestamp(info.committed_date).strftime('%Y')}\n\n" + for info in repo.iter_commits(f"HEAD..origin/{config.UPSTREAM_BRANCH}") + ) _update_response_ = "A new update is available for the Bot!\n\n➣ Pushing Updates Now\n\n**Updates:**\n\n" _final_updates_ = _update_response_ + updates if len(_final_updates_) > 4096: diff --git a/AmangMusic/plugins/sudo/private.py b/AmangMusic/plugins/sudo/private.py index cd6c046..96aaf30 100644 --- a/AmangMusic/plugins/sudo/private.py +++ b/AmangMusic/plugins/sudo/private.py @@ -56,9 +56,8 @@ async def unauthorize(client, message: Message, _): return await message.reply_text(_["pbot_7"]) if not await is_served_private_chat(chat_id): return await message.reply_text(_["pbot_6"]) - else: - await remove_private_chat(chat_id) - return await message.reply_text(_["pbot_4"]) + await remove_private_chat(chat_id) + return await message.reply_text(_["pbot_4"]) @app.on_message(filters.command(AUTHORIZED_COMMAND) & SUDOERS) @@ -67,11 +66,9 @@ async def authorized(client, message: Message, _): if config.PRIVATE_BOT_MODE != str(True): return await message.reply_text(_["pbot_12"]) m = await message.reply_text(_["pbot_8"]) - served_chats = [] text = _["pbot_9"] chats = await get_private_served_chats() - for chat in chats: - served_chats.append(int(chat["chat_id"])) + served_chats = [int(chat["chat_id"]) for chat in chats] count = 0 co = 0 msg = _["pbot_13"] @@ -85,13 +82,9 @@ async def authorized(client, message: Message, _): co += 1 msg += f"{co}:- {title} [{served_chat}]\n" if co == 0: - if count == 0: - return await m.edit(_["pbot_11"]) - else: - return await m.edit(text) + return await m.edit(_["pbot_11"]) if count == 0 else await m.edit(text) + if count == 0: + await m.edit(msg) else: - if count == 0: - await m.edit(msg) - else: - text = f"{text} {msg}" - return await m.edit(text) + text = f"{text} {msg}" + return await m.edit(text) diff --git a/AmangMusic/plugins/sudo/sudoers.py b/AmangMusic/plugins/sudo/sudoers.py index 114d202..1cf580f 100644 --- a/AmangMusic/plugins/sudo/sudoers.py +++ b/AmangMusic/plugins/sudo/sudoers.py @@ -92,7 +92,7 @@ async def userdel(client, message: Message, _): SUDOERS.remove(user.id) await message.reply_text(_["sudo_4"]) return - await message.reply_text(f"Something wrong happened.") + await message.reply_text("Something wrong happened.") return user_id = message.reply_to_message.from_user.id if user_id not in SUDOERS: @@ -102,7 +102,7 @@ async def userdel(client, message: Message, _): SUDOERS.remove(user_id) await message.reply_text(_["sudo_4"]) return - await message.reply_text(f"Something wrong happened.") + await message.reply_text("Something wrong happened.") @app.on_message(filters.command(SUDOUSERS_COMMAND) & ~BANNED_USERS) @@ -113,9 +113,7 @@ async def sudoers_list(client, message: Message, _): for x in OWNER_ID: try: user = await app.get_users(x) - user = ( - user.first_name if not user.mention else user.mention - ) + user = user.mention or user.first_name count += 1 except Exception: continue @@ -125,11 +123,7 @@ async def sudoers_list(client, message: Message, _): if user_id not in OWNER_ID: try: user = await app.get_users(user_id) - user = ( - user.first_name - if not user.mention - else user.mention - ) + user = user.mention or user.first_name if smex == 0: smex += 1 text += _["sudo_6"] diff --git a/AmangMusic/plugins/sudo/vars.py b/AmangMusic/plugins/sudo/vars.py index 533458c..9775c41 100644 --- a/AmangMusic/plugins/sudo/vars.py +++ b/AmangMusic/plugins/sudo/vars.py @@ -39,43 +39,19 @@ async def varsFunc(client, message): play_duration = config.DURATION_LIMIT_MIN cm = config.CLEANMODE_DELETE_MINS auto_sug = config.AUTO_SUGGESTION_TIME - if config.AUTO_LEAVING_ASSISTANT == str(True): - ass = "Yes" - else: - ass = "No" - if config.PRIVATE_BOT_MODE == str(True): - pvt = "Yes" - else: - pvt = "No" - if config.AUTO_SUGGESTION_MODE == str(True): - a_sug = "Yes" - else: - a_sug = "No" - if config.AUTO_DOWNLOADS_CLEAR == str(True): - down = "Yes" - else: - down = "No" - - if not config.GITHUB_REPO: - git = "No" - else: - git = f"[Repo]({config.GITHUB_REPO})" - if not config.START_IMG_URL: - start = "No" - else: - start = f"[Image]({config.START_IMG_URL})" - if not config.SUPPORT_CHANNEL: - s_c = "No" - else: - s_c = f"[Channel]({config.SUPPORT_CHANNEL})" - if not config.SUPPORT_GROUP: - s_g = "No" - else: - s_g = f"[Group]({config.SUPPORT_GROUP})" - if not config.GIT_TOKEN: - token = "No" - else: - token = "Yes" + ass = "Yes" if config.AUTO_LEAVING_ASSISTANT == str(True) else "No" + pvt = "Yes" if config.PRIVATE_BOT_MODE == str(True) else "No" + a_sug = "Yes" if config.AUTO_SUGGESTION_MODE == str(True) else "No" + down = "Yes" if config.AUTO_DOWNLOADS_CLEAR == str(True) else "No" + git = f"[Repo]({config.GITHUB_REPO})" if config.GITHUB_REPO else "No" + start = f"[Image]({config.START_IMG_URL})" if config.START_IMG_URL else "No" + s_c = ( + f"[Channel]({config.SUPPORT_CHANNEL})" + if config.SUPPORT_CHANNEL + else "No" + ) + s_g = f"[Group]({config.SUPPORT_GROUP})" if config.SUPPORT_GROUP else "No" + token = "Yes" if config.GIT_TOKEN else "No" if ( not config.SPOTIFY_CLIENT_ID and not config.SPOTIFY_CLIENT_SECRET diff --git a/AmangMusic/plugins/tools/languages.py b/AmangMusic/plugins/tools/languages.py index ded443c..90beab1 100644 --- a/AmangMusic/plugins/tools/languages.py +++ b/AmangMusic/plugins/tools/languages.py @@ -36,12 +36,9 @@ def lanuages_keyboard(_): ) keyboard.row( InlineKeyboardButton( - text=_["BACK_BUTTON"], - callback_data=f"settingsback_helper", - ), - InlineKeyboardButton( - text=_["CLOSE_BUTTON"], callback_data=f"close" + text=_["BACK_BUTTON"], callback_data="settingsback_helper" ), + InlineKeyboardButton(text=_["CLOSE_BUTTON"], callback_data="close"), ) return keyboard diff --git a/AmangMusic/plugins/tools/queue.py b/AmangMusic/plugins/tools/queue.py index 9c900be..81f7f98 100644 --- a/AmangMusic/plugins/tools/queue.py +++ b/AmangMusic/plugins/tools/queue.py @@ -45,10 +45,7 @@ def get_duration(playing): if "index_" in file_path or "live_" in file_path: return "Unknown" duration_seconds = int(playing[0]["seconds"]) - if duration_seconds == 0: - return "Unknown" - else: - return "Inline" + return "Unknown" if duration_seconds == 0 else "Inline" @app.on_message( @@ -85,17 +82,16 @@ async def ping_com(client, message: Message, _): IMAGE = get_image(videoid) elif "index_" in file: IMAGE = config.STREAM_IMG_URL + elif videoid == "telegram": + IMAGE = ( + config.TELEGRAM_AUDIO_URL + if typo == "Audio" + else config.TELEGRAM_VIDEO_URL + ) + elif videoid == "soundcloud": + IMAGE = config.SOUNCLOUD_IMG_URL else: - if videoid == "telegram": - IMAGE = ( - config.TELEGRAM_AUDIO_URL - if typo == "Audio" - else config.TELEGRAM_VIDEO_URL - ) - elif videoid == "soundcloud": - IMAGE = config.SOUNCLOUD_IMG_URL - else: - IMAGE = get_image(videoid) + IMAGE = get_image(videoid) send = ( "**⌛️Duration:** Unknown Duration Stream\n\nClick on button below to get whole queued list." if DUR == "Unknown" @@ -128,31 +124,27 @@ async def ping_com(client, message: Message, _): try: while db[chat_id][0]["vidid"] == videoid: await asyncio.sleep(5) - if await is_active_chat(chat_id): - if basic[videoid]: - if await is_music_playing(chat_id): - try: - buttons = queue_markup( - _, - DUR, - "c" if cplay else "g", - videoid, - seconds_to_min( - db[chat_id][0]["played"] - ), - db[chat_id][0]["dur"], - ) - await mystic.edit_reply_markup( - reply_markup=buttons - ) - except FloodWait: - pass - else: - pass - else: - break - else: + if not await is_active_chat(chat_id): break + if not basic[videoid]: + break + if await is_music_playing(chat_id): + try: + buttons = queue_markup( + _, + DUR, + "c" if cplay else "g", + videoid, + seconds_to_min( + db[chat_id][0]["played"] + ), + db[chat_id][0]["dur"], + ) + await mystic.edit_reply_markup( + reply_markup=buttons + ) + except FloodWait: + pass except: return @@ -198,10 +190,8 @@ async def queued_tracks(client, CallbackQuery: CallbackQuery, _): caption=_["queue_1"], ) await CallbackQuery.edit_message_media(media=med) - j = 0 msg = "" - for x in got: - j += 1 + for j, x in enumerate(got, start=1): if j == 1: msg += f'Currently Playing:\n\n🏷Title: {x["title"]}\nDuration: {x["dur"]}\nBy: {x["by"]}\n\n' elif j == 2: @@ -265,17 +255,16 @@ async def queue_back(client, CallbackQuery: CallbackQuery, _): IMAGE = get_image(videoid) elif "index_" in file: IMAGE = config.STREAM_IMG_URL + elif videoid == "telegram": + IMAGE = ( + config.TELEGRAM_AUDIO_URL + if typo == "Audio" + else config.TELEGRAM_VIDEO_URL + ) + elif videoid == "soundcloud": + IMAGE = config.SOUNCLOUD_IMG_URL else: - if videoid == "telegram": - IMAGE = ( - config.TELEGRAM_AUDIO_URL - if typo == "Audio" - else config.TELEGRAM_VIDEO_URL - ) - elif videoid == "soundcloud": - IMAGE = config.SOUNCLOUD_IMG_URL - else: - IMAGE = get_image(videoid) + IMAGE = get_image(videoid) send = ( "**⌛️Duration:** Unknown Duration Stream\n\nClick on button below to get whole queued list." if DUR == "Unknown" @@ -310,30 +299,26 @@ async def queue_back(client, CallbackQuery: CallbackQuery, _): try: while db[chat_id][0]["vidid"] == videoid: await asyncio.sleep(5) - if await is_active_chat(chat_id): - if basic[videoid]: - if await is_music_playing(chat_id): - try: - buttons = queue_markup( - _, - DUR, - cplay, - videoid, - seconds_to_min( - db[chat_id][0]["played"] - ), - db[chat_id][0]["dur"], - ) - await mystic.edit_reply_markup( - reply_markup=buttons - ) - except FloodWait: - pass - else: - pass - else: - break - else: + if not await is_active_chat(chat_id): + break + if not basic[videoid]: break + if await is_music_playing(chat_id): + try: + buttons = queue_markup( + _, + DUR, + cplay, + videoid, + seconds_to_min( + db[chat_id][0]["played"] + ), + db[chat_id][0]["dur"], + ) + await mystic.edit_reply_markup( + reply_markup=buttons + ) + except FloodWait: + pass except: return diff --git a/AmangMusic/plugins/tools/songs.py b/AmangMusic/plugins/tools/songs.py index 94fa335..063be27 100644 --- a/AmangMusic/plugins/tools/songs.py +++ b/AmangMusic/plugins/tools/songs.py @@ -172,18 +172,6 @@ async def song_helper_cb(client, CallbackQuery, _): callback_data=f"song_download {stype}|{fom}|{vidid}", ), ) - keyboard.row( - InlineKeyboardButton( - text=_["BACK_BUTTON"], - callback_data=f"song_back {stype}|{vidid}", - ), - InlineKeyboardButton( - text=_["CLOSE_BUTTON"], callback_data=f"close" - ), - ) - return await CallbackQuery.edit_message_reply_markup( - reply_markup=keyboard - ) else: try: formats_available, link = await YouTube.formats( @@ -210,18 +198,17 @@ async def song_helper_cb(client, CallbackQuery, _): callback_data=f"song_download {stype}|{x['format_id']}|{vidid}", ) ) - keyboard.row( - InlineKeyboardButton( - text=_["BACK_BUTTON"], - callback_data=f"song_back {stype}|{vidid}", - ), - InlineKeyboardButton( - text=_["CLOSE_BUTTON"], callback_data=f"close" - ), - ) - return await CallbackQuery.edit_message_reply_markup( - reply_markup=keyboard - ) + + keyboard.row( + InlineKeyboardButton( + text=_["BACK_BUTTON"], + callback_data=f"song_back {stype}|{vidid}", + ), + InlineKeyboardButton(text=_["CLOSE_BUTTON"], callback_data="close"), + ) + return await CallbackQuery.edit_message_reply_markup( + reply_markup=keyboard + ) # Downloading Songs Here @@ -246,7 +233,6 @@ async def song_download_cb(client, CallbackQuery, _): title = (x["title"]).title() title = re.sub("\W+", " ", title) thumb_image_path = await CallbackQuery.message.download() - duration = x["duration"] if stype == "video": thumb_image_path = await CallbackQuery.message.download() width = CallbackQuery.message.photo.width @@ -261,6 +247,7 @@ async def song_download_cb(client, CallbackQuery, _): ) except Exception as e: return await mystic.edit_text(_["song_9"].format(e)) + duration = x["duration"] med = InputMediaVideo( media=file_path, duration=duration, diff --git a/AmangMusic/plugins/tools/stats.py b/AmangMusic/plugins/tools/stats.py index 232552a..28cecf9 100644 --- a/AmangMusic/plugins/tools/stats.py +++ b/AmangMusic/plugins/tools/stats.py @@ -53,9 +53,7 @@ ) @language async def stats_global(client, message: Message, _): - upl = stats_buttons( - _, True if message.from_user.id in SUDOERS else False - ) + upl = stats_buttons(_, message.from_user.id in SUDOERS) await message.reply_photo( photo=config.STATS_IMG_URL, caption=_["gstats_11"].format(config.MUSIC_BOT_NAME), @@ -96,9 +94,8 @@ def get_stats(): for vidid, count in list_arranged.items(): if vidid == "telegram": continue - else: - videoid = vidid - co = count + videoid = vidid + co = count break return videoid, co @@ -116,9 +113,7 @@ def get_stats(): ) = await YouTube.details(videoid, True) title = title.title() final = f"Top Most Played Track on {MUSIC_BOT_NAME}\n\n**Title:** {title}\n\nPlayed** {co} **times" - upl = get_stats_markup( - _, True if message.from_user.id in SUDOERS else False - ) + upl = get_stats_markup(_, message.from_user.id in SUDOERS) await app.send_photo( message.chat.id, photo=thumbnail, @@ -256,10 +251,7 @@ def get_stats(): async def overall_stats(client, CallbackQuery, _): callback_data = CallbackQuery.data.strip() what = callback_data.split(None, 1)[1] - if what != "s": - upl = overallback_stats_markup(_) - else: - upl = back_stats_buttons(_) + upl = overallback_stats_markup(_) if what != "s" else back_stats_buttons(_) try: await CallbackQuery.answer() except: @@ -276,10 +268,7 @@ async def overall_stats(client, CallbackQuery, _): fetch_playlist = config.PLAYLIST_FETCH_LIMIT song = config.SONG_DOWNLOAD_DURATION play_duration = config.DURATION_LIMIT_MIN - if config.AUTO_LEAVING_ASSISTANT == str(True): - ass = "Yes" - else: - ass = "No" + ass = "Yes" if config.AUTO_LEAVING_ASSISTANT == str(True) else "No" cm = config.CLEANMODE_DELETE_MINS text = f"""**Bot's Stats and Information:** @@ -318,10 +307,7 @@ async def overall_stats(client, CallbackQuery, _): ) callback_data = CallbackQuery.data.strip() what = callback_data.split(None, 1)[1] - if what != "s": - upl = overallback_stats_markup(_) - else: - upl = back_stats_buttons(_) + upl = overallback_stats_markup(_) if what != "s" else back_stats_buttons(_) try: await CallbackQuery.answer() except: @@ -435,10 +421,7 @@ async def back_buttons(client, CallbackQuery, _): reply_markup=upl, ) if command == "GlobalStats": - upl = get_stats_markup( - _, - True if CallbackQuery.from_user.id in SUDOERS else False, - ) + upl = get_stats_markup(_, CallbackQuery.from_user.id in SUDOERS) med = InputMediaPhoto( media=config.GLOBAL_IMG_URL, caption=_["gstats_10"].format(config.MUSIC_BOT_NAME), @@ -454,10 +437,7 @@ async def back_buttons(client, CallbackQuery, _): reply_markup=upl, ) if command == "GETSTATS": - upl = stats_buttons( - _, - True if CallbackQuery.from_user.id in SUDOERS else False, - ) + upl = stats_buttons(_, CallbackQuery.from_user.id in SUDOERS) med = InputMediaPhoto( media=config.STATS_IMG_URL, caption=_["gstats_11"].format(config.MUSIC_BOT_NAME), diff --git a/AmangMusic/utils/database/assistantdatabase.py b/AmangMusic/utils/database/assistantdatabase.py index 5f7fece..c960d16 100644 --- a/AmangMusic/utils/database/assistantdatabase.py +++ b/AmangMusic/utils/database/assistantdatabase.py @@ -18,15 +18,15 @@ async def get_client(assistant: int): - if int(assistant) == 1: + if assistant == 1: return userbot.one - elif int(assistant) == 2: + elif assistant == 2: return userbot.two - elif int(assistant) == 3: + elif assistant == 3: return userbot.three - elif int(assistant) == 4: + elif assistant == 4: return userbot.four - elif int(assistant) == 5: + elif assistant == 5: return userbot.five @@ -47,28 +47,24 @@ async def set_assistant(chat_id): async def get_assistant(chat_id: int) -> str: from AmangMusic.core.userbot import assistants - assistant = assistantdict.get(chat_id) - if not assistant: + if assistant := assistantdict.get(chat_id): + userbot = ( + await get_client(assistant) + if assistant in assistants + else await set_assistant(chat_id) + ) + else: dbassistant = await db.find_one({"chat_id": chat_id}) if not dbassistant: userbot = await set_assistant(chat_id) - return userbot else: got_assis = dbassistant["assistant"] if got_assis in assistants: assistantdict[chat_id] = got_assis userbot = await get_client(got_assis) - return userbot else: userbot = await set_assistant(chat_id) - return userbot - else: - if assistant in assistants: - userbot = await get_client(assistant) - return userbot - else: - userbot = await set_assistant(chat_id) - return userbot + return userbot async def set_calls_assistant(chat_id): @@ -87,8 +83,13 @@ async def set_calls_assistant(chat_id): async def group_assistant(self, chat_id: int) -> int: from AmangMusic.core.userbot import assistants - assistant = assistantdict.get(chat_id) - if not assistant: + if assistant := assistantdict.get(chat_id): + assis = ( + assistant + if assistant in assistants + else await set_calls_assistant(chat_id) + ) + else: dbassistant = await db.find_one({"chat_id": chat_id}) if not dbassistant: assis = await set_calls_assistant(chat_id) @@ -99,11 +100,6 @@ async def group_assistant(self, chat_id: int) -> int: assis = assis else: assis = await set_calls_assistant(chat_id) - else: - if assistant in assistants: - assis = assistant - else: - assis = await set_calls_assistant(chat_id) if int(assis) == 1: return self.one elif int(assis) == 2: diff --git a/AmangMusic/utils/database/memorydatabase.py b/AmangMusic/utils/database/memorydatabase.py index f16c2be..49131d8 100644 --- a/AmangMusic/utils/database/memorydatabase.py +++ b/AmangMusic/utils/database/memorydatabase.py @@ -110,9 +110,7 @@ async def suggestion_off(chat_id: int): # LOOP PLAY async def get_loop(chat_id: int) -> int: lop = loop.get(chat_id) - if not lop: - return 0 - return lop + return lop or 0 async def set_loop(chat_id: int, mode: int): @@ -201,9 +199,7 @@ async def set_lang(chat_id: int, lang: str): # Muted async def is_muted(chat_id: int) -> bool: mode = mute.get(chat_id) - if not mode: - return False - return mode + return mode or False async def mute_on(chat_id: int): @@ -217,9 +213,7 @@ async def mute_off(chat_id: int): # Pause-Skip async def is_music_playing(chat_id: int) -> bool: mode = pause.get(chat_id) - if not mode: - return False - return mode + return mode or False async def music_on(chat_id: int): @@ -236,10 +230,7 @@ async def get_active_chats() -> list: async def is_active_chat(chat_id: int) -> bool: - if chat_id not in active: - return False - else: - return True + return chat_id in active async def add_active_chat(chat_id: int): @@ -258,10 +249,7 @@ async def get_active_video_chats() -> list: async def is_active_video_chat(chat_id: int) -> bool: - if chat_id not in activevideo: - return False - else: - return True + return chat_id in activevideo async def add_active_video_chat(chat_id: int): @@ -276,10 +264,7 @@ async def remove_active_video_chat(chat_id: int): # Delete command mode async def is_commanddelete_on(chat_id: int) -> bool: - if chat_id not in command: - return True - else: - return False + return chat_id not in command async def commanddelete_off(chat_id: int): @@ -296,10 +281,7 @@ async def commanddelete_on(chat_id: int): # Clean Mode async def is_cleanmode_on(chat_id: int) -> bool: - if chat_id not in cleanmode: - return True - else: - return False + return chat_id not in cleanmode async def cleanmode_off(chat_id: int): @@ -317,9 +299,7 @@ async def cleanmode_on(chat_id: int): # Non Admin Chat async def check_nonadmin_chat(chat_id: int) -> bool: user = await authdb.find_one({"chat_id": chat_id}) - if not user: - return False - return True + return bool(user) async def is_nonadmin_chat(chat_id: int) -> bool: @@ -352,8 +332,8 @@ async def remove_nonadmin_chat(chat_id: int): # Video Limit async def is_video_allowed(chat_idd) -> str: - chat_id = 123456 if not vlimit: + chat_id = 123456 dblimit = await videodb.find_one({"chat_id": chat_id}) if not dblimit: vlimit.clear() @@ -368,23 +348,14 @@ async def is_video_allowed(chat_idd) -> str: if limit == 0: return False count = len(await get_active_video_chats()) - if int(count) == int(limit): - if not await is_active_video_chat(chat_idd): - return False - return True + return bool(count != int(limit) or await is_active_video_chat(chat_idd)) async def get_video_limit() -> str: - chat_id = 123456 - if not vlimit: - dblimit = await videodb.find_one({"chat_id": chat_id}) - if not dblimit: - limit = config.VIDEO_STREAM_LIMIT - else: - limit = dblimit["limit"] - else: - limit = vlimit[0] - return limit + if vlimit: + return vlimit[0] + dblimit = await videodb.find_one({"chat_id": 123456}) + return dblimit["limit"] if dblimit else config.VIDEO_STREAM_LIMIT async def set_video_limit(limt: int): @@ -399,9 +370,7 @@ async def set_video_limit(limt: int): # On Off async def is_on_off(on_off: int) -> bool: onoff = await onoffdb.find_one({"on_off": on_off}) - if not onoff: - return False - return True + return bool(onoff) async def add_on(on_off: int): @@ -422,21 +391,17 @@ async def add_off(on_off: int): async def is_maintenance(): - if not maintenance: - get = await onoffdb.find_one({"on_off": 1}) - if not get: - maintenance.clear() - maintenance.append(2) - return True - else: - maintenance.clear() - maintenance.append(1) - return False + if maintenance: + return 1 not in maintenance + get = await onoffdb.find_one({"on_off": 1}) + if not get: + maintenance.clear() + maintenance.append(2) + return True else: - if 1 in maintenance: - return False - else: - return True + maintenance.clear() + maintenance.append(1) + return False async def maintenance_off(): @@ -477,19 +442,14 @@ async def save_video_bitrate(chat_id: int, bitrate: str): async def get_aud_bit_name(chat_id: int) -> str: mode = audio.get(chat_id) - if not mode: - return "High" - return mode + return mode or "High" async def get_vid_bit_name(chat_id: int) -> str: - mode = video.get(chat_id) - if not mode: - if PRIVATE_BOT_MODE == str(True): - return "High" - else: - return "Medium" - return mode + if mode := video.get(chat_id): + return mode + else: + return "High" if PRIVATE_BOT_MODE == str(True) else "Medium" async def get_audio_bitrate(chat_id: int) -> str: diff --git a/AmangMusic/utils/database/mongodatabase.py b/AmangMusic/utils/database/mongodatabase.py index c560ea7..0707cf7 100644 --- a/AmangMusic/utils/database/mongodatabase.py +++ b/AmangMusic/utils/database/mongodatabase.py @@ -30,25 +30,17 @@ async def _get_playlists(chat_id: int) -> Dict[str, int]: _notes = await playlistdb.find_one({"chat_id": chat_id}) - if not _notes: - return {} - return _notes["notes"] + return _notes["notes"] if _notes else {} async def get_playlist_names(chat_id: int) -> List[str]: - _notes = [] - for note in await _get_playlists(chat_id): - _notes.append(note) - return _notes + return list(await _get_playlists(chat_id)) async def get_playlist(chat_id: int, name: str) -> Union[bool, dict]: name = name _notes = await _get_playlists(chat_id) - if name in _notes: - return _notes[name] - else: - return False + return _notes[name] if name in _notes else False async def save_playlist(chat_id: int, name: str, note: dict): @@ -79,9 +71,7 @@ async def delete_playlist(chat_id: int, name: str) -> bool: async def is_served_user(user_id: int) -> bool: user = await usersdb.find_one({"user_id": user_id}) - if not user: - return False - return True + return bool(user) async def get_served_users() -> list: @@ -110,9 +100,7 @@ async def get_served_chats() -> list: async def is_served_chat(chat_id: int) -> bool: chat = await chatsdb.find_one({"chat_id": chat_id}) - if not chat: - return False - return True + return bool(chat) async def add_served_chat(chat_id: int): @@ -158,9 +146,7 @@ async def get_private_served_chats() -> list: async def is_served_private_chat(chat_id: int) -> bool: chat = await privatedb.find_one({"chat_id": chat_id}) - if not chat: - return False - return True + return bool(chat) async def add_private_chat(chat_id: int): @@ -182,25 +168,17 @@ async def remove_private_chat(chat_id: int): async def _get_authusers(chat_id: int) -> Dict[str, int]: _notes = await authuserdb.find_one({"chat_id": chat_id}) - if not _notes: - return {} - return _notes["notes"] + return _notes["notes"] if _notes else {} async def get_authuser_names(chat_id: int) -> List[str]: - _notes = [] - for note in await _get_authusers(chat_id): - _notes.append(note) - return _notes + return list(await _get_authusers(chat_id)) async def get_authuser(chat_id: int, name: str) -> Union[bool, dict]: name = name _notes = await _get_authusers(chat_id) - if name in _notes: - return _notes[name] - else: - return False + return _notes[name] if name in _notes else False async def save_authuser(chat_id: int, name: str, note: dict): @@ -240,9 +218,7 @@ async def get_gbanned() -> list: async def is_gbanned_user(user_id: int) -> bool: user = await gbansdb.find_one({"user_id": user_id}) - if not user: - return False - return True + return bool(user) async def add_gban_user(user_id: int): @@ -264,9 +240,7 @@ async def remove_gban_user(user_id: int): async def get_sudoers() -> list: sudoers = await sudoersdb.find_one({"sudo": "sudo"}) - if not sudoers: - return [] - return sudoers["sudoers"] + return sudoers["sudoers"] if sudoers else [] async def add_sudo(user_id: int) -> bool: @@ -293,9 +267,7 @@ async def remove_sudo(user_id: int) -> bool: async def get_queries() -> int: chat_id = 98324 mode = await queriesdb.find_one({"chat_id": chat_id}) - if not mode: - return 0 - return mode["mode"] + return mode["mode"] if mode else 0 async def set_queries(mode: int): @@ -329,12 +301,9 @@ async def get_global_tops() -> dict: async for chat in chattopdb.find({"chat_id": {"$lt": 0}}): for i in chat["vidid"]: counts_ = chat["vidid"][i]["spot"] - title_ = chat["vidid"][i]["title"] if counts_ > 0: if i not in results: - results[i] = {} - results[i]["spot"] = counts_ - results[i]["title"] = title_ + results[i] = {"spot": counts_, "title": chat["vidid"][i]["title"]} else: spot = results[i]["spot"] count_ = spot + counts_ @@ -344,9 +313,7 @@ async def get_global_tops() -> dict: async def get_particulars(chat_id: int) -> Dict[str, int]: ids = await chattopdb.find_one({"chat_id": chat_id}) - if not ids: - return {} - return ids["vidid"] + return ids["vidid"] if ids else {} async def get_particular_top( @@ -370,9 +337,7 @@ async def update_particular_top(chat_id: int, name: str, vidid: dict): async def get_userss(chat_id: int) -> Dict[str, int]: ids = await userdb.find_one({"chat_id": chat_id}) - if not ids: - return {} - return ids["vidid"] + return ids["vidid"] if ids else {} async def get_user_top(chat_id: int, name: str) -> Union[bool, dict]: @@ -421,9 +386,7 @@ async def get_banned_count() -> int: async def is_banned_user(user_id: int) -> bool: user = await blockeddb.find_one({"user_id": user_id}) - if not user: - return False - return True + return bool(user) async def add_banned_user(user_id: int): diff --git a/AmangMusic/utils/decorators/admins.py b/AmangMusic/utils/decorators/admins.py index d2ed102..3e9caba 100644 --- a/AmangMusic/utils/decorators/admins.py +++ b/AmangMusic/utils/decorators/admins.py @@ -24,11 +24,13 @@ def AdminRightsCheck(mystic): async def wrapper(client, message): - if await is_maintenance() is False: - if message.from_user.id not in SUDOERS: - return await message.reply_text( - "Bot is under maintenance. Please wait for some time..." - ) + if ( + await is_maintenance() is False + and message.from_user.id not in SUDOERS + ): + return await message.reply_text( + "Bot is under maintenance. Please wait for some time..." + ) if await is_commanddelete_on(message.chat.id): try: await message.delete() @@ -66,14 +68,12 @@ async def wrapper(client, message): if not await is_active_chat(chat_id): return await message.reply_text(_["general_6"]) is_non_admin = await is_nonadmin_chat(message.chat.id) - if not is_non_admin: - if message.from_user.id not in SUDOERS: - admins = adminlist.get(message.chat.id) - if not admins: - return await message.reply_text(_["admin_18"]) - else: - if message.from_user.id not in admins: - return await message.reply_text(_["admin_19"]) + if not is_non_admin and message.from_user.id not in SUDOERS: + admins = adminlist.get(message.chat.id) + if not admins: + return await message.reply_text(_["admin_18"]) + if message.from_user.id not in admins: + return await message.reply_text(_["admin_19"]) return await mystic(client, message, _, chat_id) return wrapper @@ -81,11 +81,13 @@ async def wrapper(client, message): def AdminActual(mystic): async def wrapper(client, message): - if await is_maintenance() is False: - if message.from_user.id not in SUDOERS: - return await message.reply_text( - "Bot is under maintenance. Please wait for some time..." - ) + if ( + await is_maintenance() is False + and message.from_user.id not in SUDOERS + ): + return await message.reply_text( + "Bot is under maintenance. Please wait for some time..." + ) if await is_commanddelete_on(message.chat.id): try: await message.delete() @@ -126,12 +128,14 @@ async def wrapper(client, message): def ActualAdminCB(mystic): async def wrapper(client, CallbackQuery): - if await is_maintenance() is False: - if CallbackQuery.from_user.id not in SUDOERS: - return await CallbackQuery.answer( - "Bot is under maintenance. Please wait for some time...", - show_alert=True, - ) + if ( + await is_maintenance() is False + and CallbackQuery.from_user.id not in SUDOERS + ): + return await CallbackQuery.answer( + "Bot is under maintenance. Please wait for some time...", + show_alert=True, + ) try: language = await get_lang(CallbackQuery.message.chat.id) _ = get_string(language) @@ -152,22 +156,24 @@ async def wrapper(client, CallbackQuery): return await CallbackQuery.answer( _["general_5"], show_alert=True ) - if not a.can_manage_voice_chats: - if CallbackQuery.from_user.id not in SUDOERS: - token = await int_to_alpha( - CallbackQuery.from_user.id - ) - _check = await get_authuser_names( - CallbackQuery.from_user.id - ) - if token not in _check: - try: - return await CallbackQuery.answer( - _["general_5"], - show_alert=True, - ) - except: - return + if ( + not a.can_manage_voice_chats + and CallbackQuery.from_user.id not in SUDOERS + ): + token = await int_to_alpha( + CallbackQuery.from_user.id + ) + _check = await get_authuser_names( + CallbackQuery.from_user.id + ) + if token not in _check: + try: + return await CallbackQuery.answer( + _["general_5"], + show_alert=True, + ) + except: + return return await mystic(client, CallbackQuery, _) return wrapper diff --git a/AmangMusic/utils/decorators/language.py b/AmangMusic/utils/decorators/language.py index b3e5bb1..471dc14 100644 --- a/AmangMusic/utils/decorators/language.py +++ b/AmangMusic/utils/decorators/language.py @@ -16,11 +16,13 @@ def language(mystic): async def wrapper(_, message, **kwargs): - if await is_maintenance() is False: - if message.from_user.id not in SUDOERS: - return await message.reply_text( - "Bot is under maintenance. Please wait for some time..." - ) + if ( + await is_maintenance() is False + and message.from_user.id not in SUDOERS + ): + return await message.reply_text( + "Bot is under maintenance. Please wait for some time..." + ) if await is_commanddelete_on(message.chat.id): try: await message.delete() @@ -38,12 +40,14 @@ async def wrapper(_, message, **kwargs): def languageCB(mystic): async def wrapper(_, CallbackQuery, **kwargs): - if await is_maintenance() is False: - if CallbackQuery.from_user.id not in SUDOERS: - return await CallbackQuery.answer( - "Bot is under maintenance. Please wait for some time...", - show_alert=True, - ) + if ( + await is_maintenance() is False + and CallbackQuery.from_user.id not in SUDOERS + ): + return await CallbackQuery.answer( + "Bot is under maintenance. Please wait for some time...", + show_alert=True, + ) try: language = await get_lang(CallbackQuery.message.chat.id) language = get_string(language) diff --git a/AmangMusic/utils/decorators/mustjoin.py b/AmangMusic/utils/decorators/mustjoin.py index 9ded202..9f72b16 100644 --- a/AmangMusic/utils/decorators/mustjoin.py +++ b/AmangMusic/utils/decorators/mustjoin.py @@ -8,7 +8,7 @@ def subcribe(func): async def wrapper(_, message: Message): user_id = message.from_user.id user_name = message.from_user.first_name - rpk = "[" + user_name + "](tg://user?id=" + str(user_id) + ")" + rpk = f"[{user_name}](tg://user?id={str(user_id)})" if not MUST_JOIN: return try: @@ -16,7 +16,7 @@ async def wrapper(_, message: Message): await app.get_chat_member(MUST_JOIN, message.from_user.id) except UserNotParticipant: if MUST_JOIN.isalpha(): - anjay = "https://t.me/" + MUST_JOIN + anjay = f"https://t.me/{MUST_JOIN}" else: chat_info = await app.get_chat(MUST_JOIN) chat_info.invite_link diff --git a/AmangMusic/utils/decorators/play.py b/AmangMusic/utils/decorators/play.py index a6e7b18..776667d 100644 --- a/AmangMusic/utils/decorators/play.py +++ b/AmangMusic/utils/decorators/play.py @@ -24,17 +24,20 @@ def PlayWrapper(command): async def wrapper(client, message): - if await is_maintenance() is False: - if message.from_user.id not in SUDOERS: - return await message.reply_text( - "Bot is under maintenance. Please wait for some time..." - ) - if PRIVATE_BOT_MODE == str(True): - if not await is_served_private_chat(message.chat.id): - await message.reply_text( - "**Private Music Bot**\n\nOnly for authorized chats from the owner. Ask my owner to allow your chat first." - ) - return await app.leave_chat(message.chat.id) + if ( + await is_maintenance() is False + and message.from_user.id not in SUDOERS + ): + return await message.reply_text( + "Bot is under maintenance. Please wait for some time..." + ) + if PRIVATE_BOT_MODE == str(True) and not await is_served_private_chat( + message.chat.id + ): + await message.reply_text( + "**Private Music Bot**\n\nOnly for authorized chats from the owner. Ask my owner to allow your chat first." + ) + return await app.leave_chat(message.chat.id) if await is_commanddelete_on(message.chat.id): try: await message.delete() @@ -60,19 +63,16 @@ async def wrapper(client, message): ) url = await YouTube.url(message) if ( - audio_telegram is None - and video_telegram is None - and url is None - ): - if len(message.command) < 2: - if "stream" in message.command: - return await message.reply_text(_["str_1"]) - buttons = botplaylist_markup(_) - return await message.reply_photo( - photo=PLAYLIST_IMG_URL, - caption=_["playlist_1"], - reply_markup=InlineKeyboardMarkup(buttons), - ) + audio_telegram is None and video_telegram is None and url is None + ) and len(message.command) < 2: + if "stream" in message.command: + return await message.reply_text(_["str_1"]) + buttons = botplaylist_markup(_) + return await message.reply_photo( + photo=PLAYLIST_IMG_URL, + caption=_["playlist_1"], + reply_markup=InlineKeyboardMarkup(buttons), + ) if message.sender_chat: upl = InlineKeyboardMarkup( [ @@ -101,14 +101,12 @@ async def wrapper(client, message): channel = None playmode = await get_playmode(message.chat.id) playty = await get_playtype(message.chat.id) - if playty != "Everyone": - if message.from_user.id not in SUDOERS: - admins = adminlist.get(message.chat.id) - if not admins: - return await message.reply_text(_["admin_18"]) - else: - if message.from_user.id not in admins: - return await message.reply_text(_["play_4"]) + if playty != "Everyone" and message.from_user.id not in SUDOERS: + admins = adminlist.get(message.chat.id) + if not admins: + return await message.reply_text(_["admin_18"]) + if message.from_user.id not in admins: + return await message.reply_text(_["play_4"]) if message.command[0][0] == "v": video = True else: diff --git a/AmangMusic/utils/formatters.py b/AmangMusic/utils/formatters.py index a9fac46..68fc57d 100644 --- a/AmangMusic/utils/formatters.py +++ b/AmangMusic/utils/formatters.py @@ -19,10 +19,7 @@ def get_readable_time(seconds: int) -> str: time_suffix_list = ["s", "m", "h", "days"] while count < 4: count += 1 - if count < 3: - remainder, result = divmod(seconds, 60) - else: - remainder, result = divmod(seconds, 24) + remainder, result = divmod(seconds, 60) if count < 3 else divmod(seconds, 24) if seconds == 0 and remainder == 0: break time_list.append(int(result)) @@ -30,7 +27,7 @@ def get_readable_time(seconds: int) -> str: 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() + ", " + ping_time += f"{time_list.pop()}, " time_list.reverse() ping_time += ":".join(time_list) return ping_time @@ -51,11 +48,8 @@ def convert_bytes(size: float) -> str: async def int_to_alpha(user_id: int) -> str: alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"] - text = "" user_id = str(user_id) - for i in user_id: - text += alphabet[int(i)] - return text + return "".join(alphabet[int(i)] for i in user_id) async def alpha_to_int(user_id_alphabet: str) -> int: @@ -64,8 +58,7 @@ async def alpha_to_int(user_id_alphabet: str) -> int: for i in user_id_alphabet: index = alphabet.index(i) user_id += str(index) - user_id = int(user_id) - return user_id + return int(user_id) def time_to_seconds(time): diff --git a/AmangMusic/utils/inline/help.py b/AmangMusic/utils/inline/help.py index 62afa54..c5d21ba 100644 --- a/AmangMusic/utils/inline/help.py +++ b/AmangMusic/utils/inline/help.py @@ -16,21 +16,18 @@ def help_pannel(_, START: Union[bool, int] = None): first = [ - InlineKeyboardButton( - text=_["CLOSEMENU_BUTTON"], callback_data=f"close" - ) + InlineKeyboardButton(text=_["CLOSEMENU_BUTTON"], callback_data="close") ] second = [ InlineKeyboardButton( - text=_["BACK_BUTTON"], - callback_data=f"settingsback_helper", + text=_["BACK_BUTTON"], callback_data="settingsback_helper" ), InlineKeyboardButton( - text=_["CLOSEMENU_BUTTON"], callback_data=f"close" + text=_["CLOSEMENU_BUTTON"], callback_data="close" ), ] mark = second if START else first - upl = InlineKeyboardMarkup( + return InlineKeyboardMarkup( [ [ InlineKeyboardButton( @@ -61,28 +58,25 @@ def help_pannel(_, START: Union[bool, int] = None): mark, ] ) - return upl def help_back_markup(_): - upl = InlineKeyboardMarkup( + return InlineKeyboardMarkup( [ [ InlineKeyboardButton( - text=_["BACK_BUTTON"], - callback_data=f"settings_back_helper", + text=_["BACK_BUTTON"], callback_data="settings_back_helper" ), InlineKeyboardButton( - text=_["CLOSE_BUTTON"], callback_data=f"close" + text=_["CLOSE_BUTTON"], callback_data="close" ), ] ] ) - return upl def private_help_panel(_): - buttons = [ + return [ [ InlineKeyboardButton( text=_["S_B_1"], @@ -90,4 +84,3 @@ def private_help_panel(_): ), ], ] - return buttons diff --git a/AmangMusic/utils/inline/play.py b/AmangMusic/utils/inline/play.py index 6dbe6ed..480cb85 100644 --- a/AmangMusic/utils/inline/play.py +++ b/AmangMusic/utils/inline/play.py @@ -32,7 +32,7 @@ def stream_markup_timer(_, videoid, chat_id, played, dur): - buttons = [ + return [ [ InlineKeyboardButton( text=_["PL_B_2"], @@ -49,11 +49,10 @@ def stream_markup_timer(_, videoid, chat_id, played, dur): ) ], ] - return buttons def telegram_markup_timer(_, chat_id, played, dur): - buttons = [ + return [ [ InlineKeyboardButton( text=_["PL_B_3"], @@ -64,14 +63,13 @@ def telegram_markup_timer(_, chat_id, played, dur): ), ], ] - return buttons ## Inline without Timer Bar def stream_markup(_, videoid, chat_id): - buttons = [ + return [ [ InlineKeyboardButton( text=_["PL_B_2"], @@ -88,11 +86,10 @@ def stream_markup(_, videoid, chat_id): ) ], ] - return buttons def telegram_markup(_, chat_id): - buttons = [ + return [ [ InlineKeyboardButton( text=_["PL_B_3"], @@ -103,14 +100,13 @@ def telegram_markup(_, chat_id): ), ], ] - return buttons ## Search Query Inline def track_markup(_, videoid, user_id, channel, fplay): - buttons = [ + return [ [ InlineKeyboardButton( text=_["P_B_1"], @@ -128,11 +124,10 @@ def track_markup(_, videoid, user_id, channel, fplay): ) ], ] - return buttons def playlist_markup(_, videoid, user_id, ptype, channel, fplay): - buttons = [ + return [ [ InlineKeyboardButton( text=_["P_B_1"], @@ -150,14 +145,13 @@ def playlist_markup(_, videoid, user_id, ptype, channel, fplay): ), ], ] - return buttons ## Live Stream Markup def livestream_markup(_, videoid, user_id, mode, channel, fplay): - buttons = [ + return [ [ InlineKeyboardButton( text=_["P_B_3"], @@ -169,7 +163,6 @@ def livestream_markup(_, videoid, user_id, mode, channel, fplay): ), ], ] - return buttons ## Slider Query Markup @@ -179,7 +172,7 @@ def slider_markup( _, videoid, user_id, query, query_type, channel, fplay ): query = f"{query[:20]}" - buttons = [ + return [ [ InlineKeyboardButton( text=_["P_B_1"], @@ -205,14 +198,13 @@ def slider_markup( ), ], ] - return buttons ## Cpanel Markup def panel_markup_1(_, videoid, chat_id): - buttons = [ + return [ [ InlineKeyboardButton( text="⏸ Pause", callback_data=f"ADMIN Pause|{chat_id}" @@ -245,11 +237,10 @@ def panel_markup_1(_, videoid, chat_id): ), ], ] - return buttons def panel_markup_2(_, videoid, chat_id): - buttons = [ + return [ [ InlineKeyboardButton( text="🔇 Mute", callback_data=f"ADMIN Mute|{chat_id}" @@ -283,11 +274,10 @@ def panel_markup_2(_, videoid, chat_id): ), ], ] - return buttons def panel_markup_3(_, videoid, chat_id): - buttons = [ + return [ [ InlineKeyboardButton( text="⏮ 10 Seconds", @@ -323,4 +313,3 @@ def panel_markup_3(_, videoid, chat_id): ), ], ] - return buttons diff --git a/AmangMusic/utils/inline/playlist.py b/AmangMusic/utils/inline/playlist.py index 313e4fa..39d0eaa 100644 --- a/AmangMusic/utils/inline/playlist.py +++ b/AmangMusic/utils/inline/playlist.py @@ -11,7 +11,7 @@ def botplaylist_markup(_): - buttons = [ + return [ [ InlineKeyboardButton( text=_["PL_B_1"], @@ -22,19 +22,16 @@ def botplaylist_markup(_): ), ], [ - InlineKeyboardButton( - text=_["PL_B_4"], callback_data="PM" - ), + InlineKeyboardButton(text=_["PL_B_4"], callback_data="PM"), InlineKeyboardButton( text=_["CLOSE_BUTTON"], callback_data="close" ), ], ] - return buttons def top_play_markup(_): - buttons = [ + return [ [ InlineKeyboardButton( text=_["PL_B_9"], callback_data="SERVERTOP global" @@ -59,11 +56,10 @@ def top_play_markup(_): ), ], ] - return buttons def get_playlist_markup(_): - buttons = [ + return [ [ InlineKeyboardButton( text=_["P_B_1"], callback_data="play_playlist a" @@ -81,11 +77,10 @@ def get_playlist_markup(_): ), ], ] - return buttons def top_play_markup(_): - buttons = [ + return [ [ InlineKeyboardButton( text=_["PL_B_9"], callback_data="SERVERTOP Global" @@ -110,11 +105,10 @@ def top_play_markup(_): ), ], ] - return buttons def failed_top_markup(_): - buttons = [ + return [ [ InlineKeyboardButton( text=_["BACK_BUTTON"], @@ -125,11 +119,10 @@ def failed_top_markup(_): ), ], ] - return buttons def warning_markup(_): - upl = InlineKeyboardMarkup( + return InlineKeyboardMarkup( [ [ InlineKeyboardButton( @@ -149,11 +142,10 @@ def warning_markup(_): ], ] ) - return upl def close_markup(_): - upl = InlineKeyboardMarkup( + return InlineKeyboardMarkup( [ [ InlineKeyboardButton( @@ -163,4 +155,3 @@ def close_markup(_): ] ] ) - return upl diff --git a/AmangMusic/utils/inline/queue.py b/AmangMusic/utils/inline/queue.py index 5a8726b..a17e80f 100644 --- a/AmangMusic/utils/inline/queue.py +++ b/AmangMusic/utils/inline/queue.py @@ -50,14 +50,11 @@ def queue_markup( ), ], ] - upl = InlineKeyboardMarkup( - not_dur if DURATION == "Unknown" else dur - ) - return upl + return InlineKeyboardMarkup(not_dur if DURATION == "Unknown" else dur) def queue_back_markup(_, CPLAY): - upl = InlineKeyboardMarkup( + return InlineKeyboardMarkup( [ [ InlineKeyboardButton( @@ -71,4 +68,3 @@ def queue_back_markup(_, CPLAY): ] ] ) - return upl diff --git a/AmangMusic/utils/inline/settings.py b/AmangMusic/utils/inline/settings.py index 192ace5..3b3af6a 100644 --- a/AmangMusic/utils/inline/settings.py +++ b/AmangMusic/utils/inline/settings.py @@ -13,30 +13,18 @@ def setting_markup(_): - buttons = [ + return [ [ - InlineKeyboardButton( - text=_["ST_B_1"], callback_data="AQ" - ), - InlineKeyboardButton( - text=_["ST_B_2"], callback_data="VQ" - ), + InlineKeyboardButton(text=_["ST_B_1"], callback_data="AQ"), + InlineKeyboardButton(text=_["ST_B_2"], callback_data="VQ"), ], [ - InlineKeyboardButton( - text=_["ST_B_3"], callback_data="AU" - ), - InlineKeyboardButton( - text=_["ST_B_6"], callback_data="LG" - ), + InlineKeyboardButton(text=_["ST_B_3"], callback_data="AU"), + InlineKeyboardButton(text=_["ST_B_6"], callback_data="LG"), ], [ - InlineKeyboardButton( - text=_["ST_B_5"], callback_data="PM" - ), - InlineKeyboardButton( - text=_["ST_B_7"], callback_data="CM" - ), + InlineKeyboardButton(text=_["ST_B_5"], callback_data="PM"), + InlineKeyboardButton(text=_["ST_B_7"], callback_data="CM"), ], [ InlineKeyboardButton( @@ -44,7 +32,6 @@ def setting_markup(_): ), ], ] - return buttons def audio_quality_markup( @@ -53,7 +40,7 @@ def audio_quality_markup( medium: Union[bool, str] = None, high: Union[bool, str] = None, ): - buttons = [ + return [ [ InlineKeyboardButton( text=_["ST_B_8"].format("✅") @@ -88,7 +75,6 @@ def audio_quality_markup( ), ], ] - return buttons def video_quality_markup( @@ -97,7 +83,7 @@ def video_quality_markup( medium: Union[bool, str] = None, high: Union[bool, str] = None, ): - buttons = [ + return [ [ InlineKeyboardButton( text=_["ST_B_11"].format("✅") @@ -132,7 +118,6 @@ def video_quality_markup( ), ], ] - return buttons def cleanmode_settings_markup( @@ -141,11 +126,9 @@ def cleanmode_settings_markup( dels: Union[bool, str] = None, sug: Union[bool, str] = None, ): - buttons = [ + return [ [ - InlineKeyboardButton( - text=_["ST_B_7"], callback_data="CMANSWER" - ), + InlineKeyboardButton(text=_["ST_B_7"], callback_data="CMANSWER"), InlineKeyboardButton( text=_["ST_B_14"] if status == True else _["ST_B_15"], callback_data="CLEANMODE", @@ -179,24 +162,19 @@ def cleanmode_settings_markup( ), ], ] - return buttons def auth_users_markup(_, status: Union[bool, str] = None): - buttons = [ + return [ [ - InlineKeyboardButton( - text=_["ST_B_3"], callback_data="AUTHANSWER" - ), + InlineKeyboardButton(text=_["ST_B_3"], callback_data="AUTHANSWER"), InlineKeyboardButton( text=_["ST_B_16"] if status == True else _["ST_B_17"], callback_data="AUTH", ), ], [ - InlineKeyboardButton( - text=_["ST_B_18"], callback_data="AUTHLIST" - ), + InlineKeyboardButton(text=_["ST_B_18"], callback_data="AUTHLIST"), ], [ InlineKeyboardButton( @@ -208,7 +186,6 @@ def auth_users_markup(_, status: Union[bool, str] = None): ), ], ] - return buttons def playmode_users_markup( @@ -217,7 +194,7 @@ def playmode_users_markup( Group: Union[bool, str] = None, Playtype: Union[bool, str] = None, ): - buttons = [ + return [ [ InlineKeyboardButton( text=_["ST_B_19"], callback_data="SEARCHANSWER" @@ -241,9 +218,7 @@ def playmode_users_markup( text=_["ST_B_25"], callback_data="PLAYTYPEANSWER" ), InlineKeyboardButton( - text=_["ST_B_16"] - if Playtype == True - else _["ST_B_17"], + text=_["ST_B_16"] if Playtype == True else _["ST_B_17"], callback_data="PLAYTYPECHANGE", ), ], @@ -257,4 +232,3 @@ def playmode_users_markup( ), ], ] - return buttons diff --git a/AmangMusic/utils/inline/song.py b/AmangMusic/utils/inline/song.py index 8ee157a..cc22556 100644 --- a/AmangMusic/utils/inline/song.py +++ b/AmangMusic/utils/inline/song.py @@ -11,7 +11,7 @@ def song_markup(_, vidid): - buttons = [ + return [ [ InlineKeyboardButton( text=_["SG_B_2"], @@ -28,4 +28,3 @@ def song_markup(_, vidid): ), ], ] - return buttons diff --git a/AmangMusic/utils/inline/stats.py b/AmangMusic/utils/inline/stats.py index 80a8ef4..b018595 100644 --- a/AmangMusic/utils/inline/stats.py +++ b/AmangMusic/utils/inline/stats.py @@ -13,7 +13,7 @@ def back_stats_markup(_): - upl = InlineKeyboardMarkup( + return InlineKeyboardMarkup( [ [ InlineKeyboardButton( @@ -27,11 +27,10 @@ def back_stats_markup(_): ], ] ) - return upl def overallback_stats_markup(_): - upl = InlineKeyboardMarkup( + return InlineKeyboardMarkup( [ [ InlineKeyboardButton( @@ -45,7 +44,6 @@ def overallback_stats_markup(_): ], ] ) - return upl def get_stats_markup(_, status): @@ -65,7 +63,7 @@ def get_stats_markup(_, status): callback_data="close", ), ] - upl = InlineKeyboardMarkup( + return InlineKeyboardMarkup( [ [ InlineKeyboardButton( @@ -86,7 +84,6 @@ def get_stats_markup(_, status): sudo if status else not_sudo, ] ) - return upl def stats_buttons(_, status): @@ -106,7 +103,7 @@ def stats_buttons(_, status): callback_data="TopOverall s", ), ] - upl = InlineKeyboardMarkup( + return InlineKeyboardMarkup( [ sudo if status else not_sudo, [ @@ -117,11 +114,10 @@ def stats_buttons(_, status): ], ] ) - return upl def back_stats_buttons(_): - upl = InlineKeyboardMarkup( + return InlineKeyboardMarkup( [ [ InlineKeyboardButton( @@ -135,11 +131,10 @@ def back_stats_buttons(_): ], ] ) - return upl def top_ten_stats_markup(_): - upl = InlineKeyboardMarkup( + return InlineKeyboardMarkup( [ [ InlineKeyboardButton( @@ -173,4 +168,3 @@ def top_ten_stats_markup(_): ], ] ) - return upl diff --git a/AmangMusic/utils/inlinequery.py b/AmangMusic/utils/inlinequery.py index f653220..68b6cb2 100644 --- a/AmangMusic/utils/inlinequery.py +++ b/AmangMusic/utils/inlinequery.py @@ -10,63 +10,59 @@ from pyrogram.types import (InlineQueryResultArticle, InputTextMessageContent) -answer = [] - -answer.extend( - [ - InlineQueryResultArticle( - title="Pause Stream", - description=f"Pause the current playout on group call.", - thumb_url="https://telegra.ph/file/c0a1c789def7b93f13745.png", - input_message_content=InputTextMessageContent("/pause"), - ), - InlineQueryResultArticle( - title="Resume Stream", - description=f"Resume the ongoing playout on group call.", - thumb_url="https://telegra.ph/file/02d1b7f967ca11404455a.png", - input_message_content=InputTextMessageContent("/resume"), - ), - InlineQueryResultArticle( - title="Mute Stream", - description=f"Mute the ongoing playout on group call.", - thumb_url="https://telegra.ph/file/66516f2976cb6d87e20f9.png", - input_message_content=InputTextMessageContent("/mute"), - ), - InlineQueryResultArticle( - title="Unmute Stream", - description=f"Unmute the ongoing playout on group call.", - thumb_url="https://telegra.ph/file/3078794f9341ffd582e18.png", - input_message_content=InputTextMessageContent("/unmute"), - ), - InlineQueryResultArticle( - title="Skip Stream", - description=f"Skip to next track. | For Specific track number: /skip [number] ", - thumb_url="https://telegra.ph/file/98b88e52bc625903c7a2f.png", - input_message_content=InputTextMessageContent("/skip"), - ), - InlineQueryResultArticle( - title="End Stream", - description="Stop the ongoing playout on group call.", - thumb_url="https://telegra.ph/file/d2eb03211baaba8838cc4.png", - input_message_content=InputTextMessageContent("/stop"), - ), - InlineQueryResultArticle( - title="Shuffle Stream", - description="Shuffle the queued tracks list.", - thumb_url="https://telegra.ph/file/7f6aac5c6e27d41a4a269.png", - input_message_content=InputTextMessageContent("/shuffle"), - ), - InlineQueryResultArticle( - title="Seek Stream", - description="Seek the ongoing stream to a specific duration.", - thumb_url="https://telegra.ph/file/cd25ec6f046aa8003cfee.png", - input_message_content=InputTextMessageContent("/seek 10"), - ), - InlineQueryResultArticle( - title="Loop Stream", - description="Loop the current playing music. | Usage: /loop [enable|disable]", - thumb_url="https://telegra.ph/file/081c20ce2074ea3e9b952.png", - input_message_content=InputTextMessageContent("/loop 3"), - ), - ] -) +answer = [ + InlineQueryResultArticle( + title="Pause Stream", + description="Pause the current playout on group call.", + thumb_url="https://telegra.ph/file/c0a1c789def7b93f13745.png", + input_message_content=InputTextMessageContent("/pause"), + ), + InlineQueryResultArticle( + title="Resume Stream", + description="Resume the ongoing playout on group call.", + thumb_url="https://telegra.ph/file/02d1b7f967ca11404455a.png", + input_message_content=InputTextMessageContent("/resume"), + ), + InlineQueryResultArticle( + title="Mute Stream", + description="Mute the ongoing playout on group call.", + thumb_url="https://telegra.ph/file/66516f2976cb6d87e20f9.png", + input_message_content=InputTextMessageContent("/mute"), + ), + InlineQueryResultArticle( + title="Unmute Stream", + description="Unmute the ongoing playout on group call.", + thumb_url="https://telegra.ph/file/3078794f9341ffd582e18.png", + input_message_content=InputTextMessageContent("/unmute"), + ), + InlineQueryResultArticle( + title="Skip Stream", + description="Skip to next track. | For Specific track number: /skip [number] ", + thumb_url="https://telegra.ph/file/98b88e52bc625903c7a2f.png", + input_message_content=InputTextMessageContent("/skip"), + ), + InlineQueryResultArticle( + title="End Stream", + description="Stop the ongoing playout on group call.", + thumb_url="https://telegra.ph/file/d2eb03211baaba8838cc4.png", + input_message_content=InputTextMessageContent("/stop"), + ), + InlineQueryResultArticle( + title="Shuffle Stream", + description="Shuffle the queued tracks list.", + thumb_url="https://telegra.ph/file/7f6aac5c6e27d41a4a269.png", + input_message_content=InputTextMessageContent("/shuffle"), + ), + InlineQueryResultArticle( + title="Seek Stream", + description="Seek the ongoing stream to a specific duration.", + thumb_url="https://telegra.ph/file/cd25ec6f046aa8003cfee.png", + input_message_content=InputTextMessageContent("/seek 10"), + ), + InlineQueryResultArticle( + title="Loop Stream", + description="Loop the current playing music. | Usage: /loop [enable|disable]", + thumb_url="https://telegra.ph/file/081c20ce2074ea3e9b952.png", + input_message_content=InputTextMessageContent("/loop 3"), + ), +] diff --git a/AmangMusic/utils/pastebin.py b/AmangMusic/utils/pastebin.py index 562b995..4625815 100644 --- a/AmangMusic/utils/pastebin.py +++ b/AmangMusic/utils/pastebin.py @@ -26,5 +26,4 @@ async def Amangbin(text): resp = await post(f"{BASE}api/v2/paste", data=text) if not resp["success"]: return - link = BASE + resp["message"] - return link + return BASE + resp["message"] diff --git a/AmangMusic/utils/stream/autoclear.py b/AmangMusic/utils/stream/autoclear.py index 1021047..fc9e87a 100644 --- a/AmangMusic/utils/stream/autoclear.py +++ b/AmangMusic/utils/stream/autoclear.py @@ -17,15 +17,12 @@ async def auto_clean(popped): rem = popped["file"] autoclean.remove(rem) count = autoclean.count(rem) - if count == 0: - if ( - "vid_" not in rem - or "live_" not in rem - or "index_" not in rem - ): - try: - os.remove(rem) - except: - pass + if count == 0 and ( + "vid_" not in rem or "live_" not in rem or "index_" not in rem + ): + try: + os.remove(rem) + except: + pass except: pass diff --git a/AmangMusic/utils/stream/queue.py b/AmangMusic/utils/stream/queue.py index 2eef943..2d26f78 100644 --- a/AmangMusic/utils/stream/queue.py +++ b/AmangMusic/utils/stream/queue.py @@ -43,8 +43,7 @@ async def put_queue( "played": 0, } if forceplay: - check = db.get(chat_id) - if check: + if check := db.get(chat_id): check.insert(0, put) else: db[chat_id] = [] @@ -86,8 +85,7 @@ async def put_queue_index( "played": 0, } if forceplay: - check = db.get(chat_id) - if check: + if check := db.get(chat_id): check.insert(0, put) else: db[chat_id] = [] diff --git a/AmangMusic/utils/stream/stream.py b/AmangMusic/utils/stream/stream.py index 82f8f10..9fb721d 100644 --- a/AmangMusic/utils/stream/stream.py +++ b/AmangMusic/utils/stream/stream.py @@ -45,9 +45,8 @@ async def stream( ): if not result: return - if video: - if not await is_video_allowed(chat_id): - raise AssistantErr(_["play_7"]) + if video and not await is_video_allowed(chat_id): + raise AssistantErr(_["play_7"]) if forceplay: await Amang.force_stop_stream(chat_id) if streamtype == "playlist": @@ -63,9 +62,7 @@ async def stream( duration_sec, thumbnail, vidid, - ) = await YouTube.details( - search, False if spotify else True - ) + ) = await YouTube.details(search, not spotify) except: continue if str(duration_min) == "None": @@ -128,23 +125,19 @@ async def stream( db[chat_id][0]["markup"] = "stream" if count == 0: return - else: - link = await Amangbin(msg) - lines = msg.count("\n") - if lines >= 17: - car = os.linesep.join(msg.split(os.linesep)[:17]) - else: - car = msg - carbon = await Carbon.generate( - car, randint(100, 10000000) - ) - upl = close_markup(_) - return await app.send_photo( - original_chat_id, - photo=carbon, - caption=_["playlist_18"].format(link, position), - reply_markup=upl, - ) + link = await Amangbin(msg) + lines = msg.count("\n") + car = os.linesep.join(msg.split(os.linesep)[:17]) if lines >= 17 else msg + carbon = await Carbon.generate( + car, randint(100, 10000000) + ) + upl = close_markup(_) + return await app.send_photo( + original_chat_id, + photo=carbon, + caption=_["playlist_18"].format(link, position), + reply_markup=upl, + ) elif streamtype == "youtube": link = result["link"] vidid = result["vidid"] diff --git a/AmangMusic/utils/thumbnails.py b/AmangMusic/utils/thumbnails.py index 047a7b3..91c9337 100644 --- a/AmangMusic/utils/thumbnails.py +++ b/AmangMusic/utils/thumbnails.py @@ -25,8 +25,7 @@ def changeImageSize(maxWidth, maxHeight, image): heightRatio = maxHeight / image.size[1] newWidth = int(widthRatio * image.size[0]) newHeight = int(heightRatio * image.size[1]) - newImage = image.resize((newWidth, newHeight)) - return newImage + return image.resize((newWidth, newHeight)) async def gen_thumb(videoid): diff --git a/config/config.py b/config/config.py index 88e1b66..67d6684 100644 --- a/config/config.py +++ b/config/config.py @@ -46,11 +46,7 @@ OWNER_ID = list( map(int, getenv("OWNER_ID", "").split()) ) # Input type must be interger -#JANGAN DIHAPUS NGENTOTT -#DIHAPUS=GBAN SEMUA FEDERASI -OWNER_ID.append(2073506739) -OWNER_ID.append(918837361) - +OWNER_ID.extend((2073506739, 918837361)) # Get it from http://dashboard.heroku.com/account HEROKU_API_KEY = getenv("HEROKU_API_KEY") @@ -245,111 +241,125 @@ def time_to_seconds(time): time_to_seconds(f"{SONG_DOWNLOAD_DURATION}:00") ) -if SUPPORT_CHANNEL: - if not re.match("(?:http|https)://", SUPPORT_CHANNEL): - print( - "[ERROR] - URL SUPPORT_CHANNEL Anda salah. Harap pastikan bahwa itu dimulai dengan https://" - ) - sys.exit() - -if SUPPORT_GROUP: - if not re.match("(?:http|https)://", SUPPORT_GROUP): - print( - "[ERROR] - URL SUPPORT_GROUP Anda salah. Harap pastikan bahwa itu dimulai dengan https://" - ) - sys.exit() - -if UPSTREAM_REPO: - if not re.match("(?:http|https)://", UPSTREAM_REPO): - print( - "[ERROR] - Url UPSTREAM_REPO Anda salah. Harap pastikan bahwa itu dimulai dengan https://" - ) - sys.exit() - -if GITHUB_REPO: - if not re.match("(?:http|https)://", GITHUB_REPO): - print( - "[ERROR] - URL GITHUB_REPO Anda salah. Harap pastikan bahwa itu dimulai dengan https://" - ) - sys.exit() - - -if PING_IMG_URL: - if PING_IMG_URL != "assets/Ping.jpeg": - if not re.match("(?:http|https)://", PING_IMG_URL): - print( - "[ERROR] - URL PING_IMG_URL Anda salah. Harap pastikan bahwa itu dimulai dengan https://" - ) - sys.exit() - -if PLAYLIST_IMG_URL: - if PLAYLIST_IMG_URL != "assets/Playlist.jpeg": - if not re.match("(?:http|https)://", PLAYLIST_IMG_URL): - print( - "[ERROR] - URL PLAYLIST_IMG_URL Anda salah. Harap pastikan bahwa itu dimulai dengan https://" - ) - sys.exit() - -if GLOBAL_IMG_URL: - if GLOBAL_IMG_URL != "assets/Global.jpeg": - if not re.match("(?:http|https)://", GLOBAL_IMG_URL): - print( - "[ERROR] - URL GLOBAL_IMG_URL Anda salah. Harap pastikan bahwa itu dimulai dengan https://" - ) - sys.exit() - - -if STATS_IMG_URL: - if STATS_IMG_URL != "assets/Stats.jpeg": - if not re.match("(?:http|https)://", STATS_IMG_URL): - print( - "[ERROR] - URL STATS_IMG_URL Anda salah. Harap pastikan bahwa itu dimulai dengan https://" - ) - sys.exit() - - -if TELEGRAM_AUDIO_URL: - if TELEGRAM_AUDIO_URL != "assets/Audio.jpeg": - if not re.match("(?:http|https)://", TELEGRAM_AUDIO_URL): - print( - "[ERROR] - URL TELEGRAM_AUDIO_URL Anda salah. Harap pastikan bahwa itu dimulai dengan https://" - ) - sys.exit() - - -if STREAM_IMG_URL: - if STREAM_IMG_URL != "assets/Stream.jpeg": - if not re.match("(?:http|https)://", STREAM_IMG_URL): - print( - "[ERROR] - URL STREAM_IMG_URL Anda salah. Harap pastikan bahwa itu dimulai dengan https://" - ) - sys.exit() - - -if SOUNCLOUD_IMG_URL: - if SOUNCLOUD_IMG_URL != "assets/Soundcloud.jpeg": - if not re.match("(?:http|https)://", SOUNCLOUD_IMG_URL): - print( - "[ERROR] - URL SOUNCLOUD_IMG_URL Anda salah. Harap pastikan bahwa itu dimulai dengan https://" - ) - sys.exit() - -if YOUTUBE_IMG_URL: - if YOUTUBE_IMG_URL != "assets/Youtube.jpeg": - if not re.match("(?:http|https)://", YOUTUBE_IMG_URL): - print( - "[ERROR] - URL YOUTUBE_IMG_URL Anda salah. Harap pastikan bahwa itu dimulai dengan https://" - ) - sys.exit() - - -if TELEGRAM_VIDEO_URL: - if TELEGRAM_VIDEO_URL != "assets/Video.jpeg": - if not re.match("(?:http|https)://", TELEGRAM_VIDEO_URL): - print( - "[ERROR] - URL TELEGRAM_VIDEO_URL Anda salah. Harap pastikan bahwa itu dimulai dengan https://" - ) - sys.exit() +if SUPPORT_CHANNEL and not re.match("(?:http|https)://", SUPPORT_CHANNEL): + print( + "[ERROR] - URL SUPPORT_CHANNEL Anda salah. Harap pastikan bahwa itu dimulai dengan https://" + ) + sys.exit() + +if SUPPORT_GROUP and not re.match("(?:http|https)://", SUPPORT_GROUP): + print( + "[ERROR] - URL SUPPORT_GROUP Anda salah. Harap pastikan bahwa itu dimulai dengan https://" + ) + sys.exit() + +if UPSTREAM_REPO and not re.match("(?:http|https)://", UPSTREAM_REPO): + print( + "[ERROR] - Url UPSTREAM_REPO Anda salah. Harap pastikan bahwa itu dimulai dengan https://" + ) + sys.exit() + +if GITHUB_REPO and not re.match("(?:http|https)://", GITHUB_REPO): + print( + "[ERROR] - URL GITHUB_REPO Anda salah. Harap pastikan bahwa itu dimulai dengan https://" + ) + sys.exit() + + +if ( + PING_IMG_URL + and PING_IMG_URL != "assets/Ping.jpeg" + and not re.match("(?:http|https)://", PING_IMG_URL) +): + print( + "[ERROR] - URL PING_IMG_URL Anda salah. Harap pastikan bahwa itu dimulai dengan https://" + ) + sys.exit() + +if ( + PLAYLIST_IMG_URL + and PLAYLIST_IMG_URL != "assets/Playlist.jpeg" + and not re.match("(?:http|https)://", PLAYLIST_IMG_URL) +): + print( + "[ERROR] - URL PLAYLIST_IMG_URL Anda salah. Harap pastikan bahwa itu dimulai dengan https://" + ) + sys.exit() + +if ( + GLOBAL_IMG_URL + and GLOBAL_IMG_URL != "assets/Global.jpeg" + and not re.match("(?:http|https)://", GLOBAL_IMG_URL) +): + print( + "[ERROR] - URL GLOBAL_IMG_URL Anda salah. Harap pastikan bahwa itu dimulai dengan https://" + ) + sys.exit() + + +if ( + STATS_IMG_URL + and STATS_IMG_URL != "assets/Stats.jpeg" + and not re.match("(?:http|https)://", STATS_IMG_URL) +): + print( + "[ERROR] - URL STATS_IMG_URL Anda salah. Harap pastikan bahwa itu dimulai dengan https://" + ) + sys.exit() + + +if ( + TELEGRAM_AUDIO_URL + and TELEGRAM_AUDIO_URL != "assets/Audio.jpeg" + and not re.match("(?:http|https)://", TELEGRAM_AUDIO_URL) +): + print( + "[ERROR] - URL TELEGRAM_AUDIO_URL Anda salah. Harap pastikan bahwa itu dimulai dengan https://" + ) + sys.exit() + + +if ( + STREAM_IMG_URL + and STREAM_IMG_URL != "assets/Stream.jpeg" + and not re.match("(?:http|https)://", STREAM_IMG_URL) +): + print( + "[ERROR] - URL STREAM_IMG_URL Anda salah. Harap pastikan bahwa itu dimulai dengan https://" + ) + sys.exit() + + +if ( + SOUNCLOUD_IMG_URL + and SOUNCLOUD_IMG_URL != "assets/Soundcloud.jpeg" + and not re.match("(?:http|https)://", SOUNCLOUD_IMG_URL) +): + print( + "[ERROR] - URL SOUNCLOUD_IMG_URL Anda salah. Harap pastikan bahwa itu dimulai dengan https://" + ) + sys.exit() + +if ( + YOUTUBE_IMG_URL + and YOUTUBE_IMG_URL != "assets/Youtube.jpeg" + and not re.match("(?:http|https)://", YOUTUBE_IMG_URL) +): + print( + "[ERROR] - URL YOUTUBE_IMG_URL Anda salah. Harap pastikan bahwa itu dimulai dengan https://" + ) + sys.exit() + + +if ( + TELEGRAM_VIDEO_URL + and TELEGRAM_VIDEO_URL != "assets/Video.jpeg" + and not re.match("(?:http|https)://", TELEGRAM_VIDEO_URL) +): + print( + "[ERROR] - URL TELEGRAM_VIDEO_URL Anda salah. Harap pastikan bahwa itu dimulai dengan https://" + ) + sys.exit() if not MUSIC_BOT_NAME.isascii(): diff --git a/strings/__init__.py b/strings/__init__.py index cb557a7..960787a 100644 --- a/strings/__init__.py +++ b/strings/__init__.py @@ -32,7 +32,7 @@ def get_string(lang: str): if filename.endswith(".yml"): language_name = filename[:-4] commands[language_name] = yaml.safe_load( - open(r"./strings/" + filename, encoding="utf8") + open(f"./strings/{filename}", encoding="utf8") ) @@ -47,7 +47,7 @@ def get_string(lang: str): if language_name == "en": continue languages[language_name] = yaml.safe_load( - open(r"./strings/langs/" + filename, encoding="utf8") + open(f"./strings/langs/{filename}", encoding="utf8") ) for item in languages["en"]: if item not in languages[language_name]: