Skip to content
This repository was archived by the owner on Jun 24, 2023. It is now read-only.

Sourcery refactored main branch#3

Open
sourcery-ai[bot] wants to merge 1 commit intomainfrom
sourcery/main
Open

Sourcery refactored main branch#3
sourcery-ai[bot] wants to merge 1 commit intomainfrom
sourcery/main

Conversation

@sourcery-ai
Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot commented Jan 18, 2023

Branch main refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the main branch, then run:

git fetch origin sourcery/main
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from saifalisew1508 January 18, 2023 14:39
Copy link
Copy Markdown
Author

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to GitHub API limits, only the first 60 comments can be shown.

Comment on lines -28 to +67
if str(getenv("SUPPORT_CHANNEL")).strip() == "":
SUPPORT_CHANNEL = None
else:
SUPPORT_CHANNEL = str(getenv("SUPPORT_CHANNEL"))
if str(getenv("SUPPORT_GROUP")).strip() == "":
SUPPORT_GROUP = None
else:
SUPPORT_GROUP = str(getenv("SUPPORT_GROUP"))


if str(getenv("STRING_SESSION1")).strip() == "":
STRING1 = str(None)
else:
STRING1 = str(getenv("STRING_SESSION1"))

if str(getenv("STRING_SESSION2")).strip() == "":
STRING2 = str(None)
else:
STRING2 = str(getenv("STRING_SESSION2"))

if str(getenv("STRING_SESSION3")).strip() == "":
STRING3 = str(None)
else:
STRING3 = str(getenv("STRING_SESSION3"))

if str(getenv("STRING_SESSION4")).strip() == "":
STRING4 = str(None)
else:
STRING4 = str(getenv("STRING_SESSION4"))

if str(getenv("STRING_SESSION5")).strip() == "":
STRING5 = str(None)
else:
STRING5 = str(getenv("STRING_SESSION5"))

if str(getenv("LOG_SESSION")).strip() == "":
LOG_SESSION = str(None)
else:
LOG_SESSION = str(getenv("LOG_SESSION"))
SUPPORT_CHANNEL = (
str(getenv("SUPPORT_CHANNEL"))
if str(getenv("SUPPORT_CHANNEL")).strip()
else None
)
SUPPORT_GROUP = (
str(getenv("SUPPORT_GROUP"))
if str(getenv("SUPPORT_GROUP")).strip()
else None
)
STRING1 = (
str(getenv("STRING_SESSION1"))
if str(getenv("STRING_SESSION1")).strip()
else str(None)
)
STRING2 = (
str(getenv("STRING_SESSION2"))
if str(getenv("STRING_SESSION2")).strip()
else str(None)
)
STRING3 = (
str(getenv("STRING_SESSION3"))
if str(getenv("STRING_SESSION3")).strip()
else str(None)
)
STRING4 = (
str(getenv("STRING_SESSION4"))
if str(getenv("STRING_SESSION4")).strip()
else str(None)
)
STRING5 = (
str(getenv("STRING_SESSION5"))
if str(getenv("STRING_SESSION5")).strip()
else str(None)
)
LOG_SESSION = (
str(getenv("LOG_SESSION"))
if str(getenv("LOG_SESSION")).strip()
else str(None)
)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 28-66 refactored with the following changes:

Comment on lines -108 to +109
"[magenta] MissCutie Music Bot Booting...",
) as status:
"[magenta] MissCutie Music Bot Booting...",
) as status:
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function initiate_bot refactored with the following changes:

Comment on lines -36 to +37
"[magenta] Finalizing Booting...",
) as status:
"[magenta] Finalizing Booting...",
) as status:
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function initiate_bot refactored with the following changes:

Comment on lines -256 to +254
user = (
user.first_name if not user.mention else user.mention
)
user = user.mention or user.first_name
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function start_command refactored with the following changes:

Comment on lines -409 to +402
module = mod_match.group(1)
text = (
"{} **{}**:\n".format(
"Here is the help for", HELPABLE[module].__MODULE__
)
+ HELPABLE[module].__HELP__
)
module = mod_match[1]
text = f"Here is the help for **{HELPABLE[module].__MODULE__}**:\n{HELPABLE[module].__HELP__}"
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function help_button refactored with the following changes:

Comment on lines -17 to +14
if not _notes:
return {}
return _notes["notes"]
return _notes["notes"] if _notes else {}
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _get_assistant refactored with the following changes:

Comment on lines -25 to +20
if name in _notes:
return _notes[name]
else:
return False
return _notes[name] if name in _notes else False
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_assistant refactored with the following changes:

if not user:
return False
return True
return bool(user)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function is_nonadmin_chat refactored with the following changes:

Comment on lines -49 to +47
if not _notes:
return {}
return _notes["notes"]
return _notes["notes"] if _notes else {}
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _get_authusers refactored with the following changes:

Comment on lines -55 to +51
_notes = []
for note in await _get_authusers(chat_id):
_notes.append(note)
return _notes
return list(await _get_authusers(chat_id))
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_authuser_names refactored with the following changes:

Comment on lines -64 to +57
if name in _notes:
return _notes[name]
else:
return False
return _notes[name] if name in _notes else False
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_authuser refactored with the following changes:

for chat in await chats.to_list(length=1000000000):
chats_list.append(chat)
return chats_list
return list(await chats.to_list(length=1000000000)) if chats else []
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_served_chats refactored with the following changes:

Comment on lines -20 to +15
if not chat:
return False
return True
return bool(chat)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function is_served_chat refactored with the following changes:

if not user:
return False
return True
return bool(user)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function is_gbanned_user refactored with the following changes:

if not onoff:
return False
return True
return bool(onoff)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function is_on_off refactored with the following changes:

if not sudoers:
return []
return sudoers["sudoers"]
return sudoers["sudoers"] if sudoers else []
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_sudoers refactored with the following changes:

if not _notes:
return {}
return _notes["notes"]
return _notes["notes"] if _notes else {}
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _get_theme refactored with the following changes:

Comment on lines -18 to +16
if name in _notes:
return _notes[name]
else:
return False
return _notes[name] if name in _notes else False
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_theme refactored with the following changes:

if not limit:
return ""
return limit["limit"]
return limit["limit"] if limit else ""
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_video_limit refactored with the following changes:

Comment on lines -29 to +27
if not chats:
return []
chats_list = []
for chat in await chats.to_list(length=1000000000):
chats_list.append(chat)
return chats_list
return list(await chats.to_list(length=1000000000)) if chats else []
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_active_video_chats refactored with the following changes:

Comment on lines -39 to +32
if not chat:
return False
return True
return bool(chat)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function is_active_video_chat refactored with the following changes:

Comment on lines -22 to +31
if not member.can_manage_voice_chats:
if message.from_user.id not in SUDOERS:
token = await int_to_alpha(message.from_user.id)
_check = await get_authuser_names(message.chat.id)
if token not in _check:
return await message.reply(
"You don't have the required permission to perform this action.\n\n__REQUIRES ADMIN WITH MANAGE VC RIGHTS__"
)
if (
not member.can_manage_voice_chats
and message.from_user.id not in SUDOERS
):
token = await int_to_alpha(message.from_user.id)
_check = await get_authuser_names(message.chat.id)
if token not in _check:
return await message.reply(
"You don't have the required permission to perform this action.\n\n__REQUIRES ADMIN WITH MANAGE VC RIGHTS__"
)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function AdminRightsCheck refactored with the following changes:

Comment on lines -44 to +52
if not member.can_manage_voice_chats:
return await message.reply(
return (
await mystic(_, message)
if member.can_manage_voice_chats
else await message.reply(
"You don't have the required permission to perform this action.\n\n__REQUIRES ADMIN WITH MANAGE VC RIGHTS__"
)
return await mystic(_, message)
)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function AdminActual refactored with the following changes:

Comment on lines -60 to -70
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 (
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:
return await CallbackQuery.answer(
"You don't have the required permission to perform this action.\nPermission: MANAGE VOICE CHATS",
show_alert=True,
)
if token not in _check:
return await CallbackQuery.answer(
"You don't have the required permission to perform this action.\nPermission: MANAGE VOICE CHATS",
show_alert=True,
)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function AdminRightsCheckCB refactored with the following changes:

Comment on lines -81 to +94
if not a.can_manage_voice_chats:
return await CallbackQuery.answer(
return (
await mystic(_, CallbackQuery)
if a.can_manage_voice_chats
else await CallbackQuery.answer(
"You don't have the required permission to perform this action.\nPermission: MANAGE VOICE CHATS",
show_alert=True,
)
return await mystic(_, CallbackQuery)
)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ActualAdminCB refactored with the following changes:

Comment on lines -167 to -181
buttons = [
return [
[
InlineKeyboardButton(text="▶️", callback_data=f"resumecb"),
InlineKeyboardButton(text="⏸️", callback_data=f"pausecb"),
InlineKeyboardButton(text="⏭️", callback_data=f"skipcb"),
InlineKeyboardButton(text="⏹️", callback_data=f"stopcb"),
InlineKeyboardButton(text="▶️", callback_data="resumecb"),
InlineKeyboardButton(text="⏸️", callback_data="pausecb"),
InlineKeyboardButton(text="⏭️", callback_data="skipcb"),
InlineKeyboardButton(text="⏹️", callback_data="stopcb"),
],
[
InlineKeyboardButton(
text="🔗 More Menu", callback_data=f"other {videoid}|{user_id}"
),
InlineKeyboardButton(text="🗑 Close Menu", callback_data=f"close"),
InlineKeyboardButton(text="🗑 Close Menu", callback_data="close"),
],
]
return buttons
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function secondary_markup refactored with the following changes:

Comment on lines -185 to -196
buttons = [
return [
[
InlineKeyboardButton(text="▶️", callback_data=f"resumecb"),
InlineKeyboardButton(text="⏸️", callback_data=f"pausecb"),
InlineKeyboardButton(text="⏭️", callback_data=f"skipcb"),
InlineKeyboardButton(text="⏹️", callback_data=f"stopcb"),
],
[
InlineKeyboardButton(text="🗑 Close Menu", callback_data=f"close"),
InlineKeyboardButton(text="▶️", callback_data="resumecb"),
InlineKeyboardButton(text="⏸️", callback_data="pausecb"),
InlineKeyboardButton(text="⏭️", callback_data="skipcb"),
InlineKeyboardButton(text="⏹️", callback_data="stopcb"),
],
[InlineKeyboardButton(text="🗑 Close Menu", callback_data="close")],
]
return buttons
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function secondary_markup2 refactored with the following changes:

Comment on lines -203 to +200
buttons = [
return [
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function primary_markup refactored with the following changes:

Comment on lines -227 to +223
buttons = [
return [
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function timer_markup refactored with the following changes:

Comment on lines -254 to +249
buttons = [
return [
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function audio_markup refactored with the following changes:

@sourcery-ai
Copy link
Copy Markdown
Author

sourcery-ai bot commented Jan 18, 2023

Sourcery Code Quality Report

Merging this PR leaves code quality unchanged.

Quality metrics Before After Change
Complexity 26.35 😞 22.98 😞 -3.37 👍
Method Length 122.16 😞 120.14 😞 -2.02 👍
Working memory 14.36 😞 14.63 😞 0.27 👎
Quality 41.33% 😞 41.33% 😞 0.00%
Other metrics Before After Change
Lines 9648 9341 -307
Changed files Quality Before Quality After Quality Change
config.py 47.35% 😞 58.14% 🙂 10.79% 👍
MissCutie/__init__.py 17.32% ⛔ 17.32% ⛔ 0.00%
MissCutie/__main__.py 22.55% ⛔ 22.71% ⛔ 0.16% 👍
MissCutie/Core/Clients/cli.py 46.63% 😞 53.86% 🙂 7.23% 👍
MissCutie/Core/PyTgCalls/Downloader.py 6.12% ⛔ 9.18% ⛔ 3.06% 👍
MissCutie/Core/PyTgCalls/MissCutie.py 46.07% 😞 45.48% 😞 -0.59% 👎
MissCutie/Core/PyTgCalls/Queues.py 94.19% ⭐ 93.77% ⭐ -0.42% 👎
MissCutie/Database/assistant.py 93.23% ⭐ 93.11% ⭐ -0.12% 👎
MissCutie/Database/auth.py 92.25% ⭐ 91.93% ⭐ -0.32% 👎
MissCutie/Database/chats.py 93.77% ⭐ 95.62% ⭐ 1.85% 👍
MissCutie/Database/gban.py 95.30% ⭐ 95.69% ⭐ 0.39% 👍
MissCutie/Database/onoff.py 95.62% ⭐ 96.17% ⭐ 0.55% 👍
MissCutie/Database/playlist.py 66.82% 🙂 64.91% 🙂 -1.91% 👎
MissCutie/Database/pmpermit.py 95.62% ⭐ 96.17% ⭐ 0.55% 👍
MissCutie/Database/queue.py 94.47% ⭐ 95.83% ⭐ 1.36% 👍
MissCutie/Database/start.py 93.23% ⭐ 93.11% ⭐ -0.12% 👎
MissCutie/Database/sudo.py 95.89% ⭐ 95.85% ⭐ -0.04% 👎
MissCutie/Database/theme.py 92.22% ⭐ 92.16% ⭐ -0.06% 👎
MissCutie/Database/videocalls.py 93.81% ⭐ 95.31% ⭐ 1.50% 👍
MissCutie/Decorators/admins.py 66.13% 🙂 68.51% 🙂 2.38% 👍
MissCutie/Decorators/assistant.py 30.20% 😞 31.24% 😞 1.04% 👍
MissCutie/Decorators/checker.py 63.02% 🙂 65.88% 🙂 2.86% 👍
MissCutie/Decorators/logger.py 42.52% 😞 44.06% 😞 1.54% 👍
MissCutie/Inline/others.py 80.43% ⭐ 81.37% ⭐ 0.94% 👍
MissCutie/Inline/play.py 74.27% 🙂 76.45% ⭐ 2.18% 👍
MissCutie/Inline/playlist.py 78.93% ⭐ 81.71% ⭐ 2.78% 👍
MissCutie/Inline/song.py 82.37% ⭐ 85.38% ⭐ 3.01% 👍
MissCutie/Inline/start.py 71.98% 🙂 74.14% 🙂 2.16% 👍
MissCutie/Inline/stats.py 58.52% 🙂 59.28% 🙂 0.76% 👍
MissCutie/Inline/videocalls.py 81.26% ⭐ 84.24% ⭐ 2.98% 👍
MissCutie/Plugins/Admins.py 3.54% ⛔ 3.70% ⛔ 0.16% 👍
MissCutie/Plugins/Assistant.py 69.07% 🙂 69.21% 🙂 0.14% 👍
MissCutie/Plugins/Auth.py 47.39% 😞 50.93% 🙂 3.54% 👍
MissCutie/Plugins/Callback.py 21.16% ⛔ 22.82% ⛔ 1.66% 👍
MissCutie/Plugins/Developer.py 42.31% 😞 42.32% 😞 0.01% 👍
MissCutie/Plugins/Download.py 53.63% 🙂 54.10% 🙂 0.47% 👍
MissCutie/Plugins/Ping.py 77.18% ⭐ 78.42% ⭐ 1.24% 👍
MissCutie/Plugins/Play.py 25.84% 😞 27.54% 😞 1.70% 👍
MissCutie/Plugins/Playlist.py 56.26% 🙂 56.61% 🙂 0.35% 👍
MissCutie/Plugins/Server.py 35.54% 😞 36.33% 😞 0.79% 👍
MissCutie/Plugins/Song.py 40.40% 😞 44.78% 😞 4.38% 👍
MissCutie/Plugins/Start.py 22.30% ⛔ 22.55% ⛔ 0.25% 👍
MissCutie/Plugins/Stats.py 9.08% ⛔ 8.92% ⛔ -0.16% 👎
MissCutie/Plugins/Stream.py 49.97% 😞 51.38% 🙂 1.41% 👍
MissCutie/Plugins/SudoUsers.py 38.48% 😞 40.77% 😞 2.29% 👍
MissCutie/Plugins/Theme.py 74.51% 🙂 75.14% ⭐ 0.63% 👍
MissCutie/Plugins/Voicechat.py 54.85% 🙂 56.14% 🙂 1.29% 👍
MissCutie/Plugins/Watcher.py 76.15% ⭐ 77.41% ⭐ 1.26% 👍
MissCutie/Plugins/__init__.py 88.44% ⭐ 91.22% ⭐ 2.78% 👍
MissCutie/Plugins/Multi-Assistant/Assistant.py 62.85% 🙂 63.14% 🙂 0.29% 👍
MissCutie/Utilities/assistant.py 61.74% 🙂 63.12% 🙂 1.38% 👍
MissCutie/Utilities/changers.py 81.09% ⭐ 79.85% ⭐ -1.24% 👎
MissCutie/Utilities/chat.py 35.00% 😞 34.82% 😞 -0.18% 👎
MissCutie/Utilities/download.py 28.98% 😞 27.34% 😞 -1.64% 👎
MissCutie/Utilities/inline.py 65.36% 🙂 65.64% 🙂 0.28% 👍
MissCutie/Utilities/paste.py 77.36% ⭐ 78.08% ⭐ 0.72% 👍
MissCutie/Utilities/ping.py 57.60% 🙂 58.91% 🙂 1.31% 👍
MissCutie/Utilities/thumbnails.py 60.29% 🙂 59.94% 🙂 -0.35% 👎
MissCutie/Utilities/timer.py 1.55% ⛔ 2.07% ⛔ 0.52% 👍
MissCutie/Utilities/url.py 56.48% 🙂 56.63% 🙂 0.15% 👍
MissCutie/Utilities/videostream.py 32.67% 😞 32.68% 😞 0.01% 👍
MissCutie/Utilities/youtube.py 73.37% 🙂 72.69% 🙂 -0.68% 👎

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
MissCutie/Plugins/Stats.py stats_markup 93 ⛔ 1142 ⛔ 37 ⛔ 0.54% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
MissCutie/Utilities/timer.py start_timer 82 ⛔ 601 ⛔ 27 ⛔ 2.07% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
MissCutie/Plugins/Admins.py admins 52 ⛔ 1010 ⛔ 30 ⛔ 3.70% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
MissCutie/Plugins/Callback.py admin_risghts 53 ⛔ 1158 ⛔ 28 ⛔ 3.86% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
MissCutie/__main__.py start_command 47 ⛔ 572 ⛔ 29 ⛔ 5.02% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants