Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sourcery refactored master branch #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AmangMusic/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
4 changes: 2 additions & 2 deletions AmangMusic/core/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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}")
11 changes: 4 additions & 7 deletions AmangMusic/core/call.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion AmangMusic/core/dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
4 changes: 2 additions & 2 deletions AmangMusic/core/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 5 additions & 15 deletions AmangMusic/core/userbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
25 changes: 12 additions & 13 deletions AmangMusic/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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:
Expand All @@ -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."
)
5 changes: 1 addition & 4 deletions AmangMusic/platforms/Apple.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 3 additions & 6 deletions AmangMusic/platforms/Carbon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions AmangMusic/platforms/Resso.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 1 addition & 4 deletions AmangMusic/platforms/Soundcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 1 addition & 4 deletions AmangMusic/platforms/Spotify.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 8 additions & 10 deletions AmangMusic/platforms/Telegram.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)
Expand All @@ -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
)
Expand Down
16 changes: 4 additions & 12 deletions AmangMusic/platforms/Youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"]
Expand Down
10 changes: 3 additions & 7 deletions AmangMusic/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Loading