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 Professor-99 branch #1
Conversation
There was a problem hiding this 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.
elif (chat_type == "group") or (chat_type == "supergroup"): | ||
elif chat_type in ["group", "supergroup"]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function cb_handler
refactored with the following changes:
- Hoist repeated code outside conditional statement (
hoist-statement-from-if
) - Replace if statement with if expression (
assign-if-exp
) - Replace multiple comparisons of same variable with
in
operator (merge-comparisons
) - Replace f-string with no interpolated values with string (
remove-redundant-fstring
)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function start
refactored with the following changes:
- Use x is None rather than x == None (
none-compare
)
elif (chat_type == "group") or (chat_type == "supergroup"): | ||
elif chat_type in ["group", "supergroup"]: | ||
grp_id = message.chat.id | ||
title = message.chat.title | ||
else: | ||
return | ||
st = await client.get_chat_member(grp_id, userid) | ||
if not ((st.status == "administrator") or (st.status == "creator") or (str(userid) in Config.DEV_ID)): | ||
if ( | ||
st.status != "administrator" | ||
and st.status != "creator" | ||
and str(userid) not in Config.DEV_ID | ||
): | ||
return | ||
if len(args) < 2: | ||
await message.reply_text("https://youtu.be/neJ4jHC9Hng", quote=True) | ||
return | ||
return | ||
extracted = split_quotes(args[1]) | ||
text = extracted[0].lower() | ||
text = extracted[0].lower() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function addfilter
refactored with the following changes:
- Replace multiple comparisons of same variable with
in
operator (merge-comparisons
) - Simplify logical expression using De Morgan identities (
de-morgan
)
elif (chat_type == "group") or (chat_type == "supergroup"): | ||
elif chat_type in ["group", "supergroup"]: | ||
grp_id = message.chat.id | ||
title = message.chat.title | ||
else: | ||
return | ||
userid = message.from_user.id | ||
st = await client.get_chat_member(grp_id, userid) | ||
if not ((st.status == "administrator") or (st.status == "creator") or (str(userid) in Config.AUTH_USERS)): | ||
if ( | ||
st.status != "administrator" | ||
and st.status != "creator" | ||
and str(userid) not in Config.AUTH_USERS | ||
): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function get_all
refactored with the following changes:
- Replace multiple comparisons of same variable with
in
operator (merge-comparisons
) - Simplify logical expression using De Morgan identities (
de-morgan
)
elif (chat_type == "group") or (chat_type == "supergroup"): | ||
elif chat_type in ["group", "supergroup"]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function deletefilter
refactored with the following changes:
- Replace multiple comparisons of same variable with
in
operator (merge-comparisons
) - Simplify logical expression using De Morgan identities (
de-morgan
)
|
||
if user_id not in VERIFY.get(str(chat_id)): | ||
return | ||
|
||
channel_id, channel_name = re.findall(r"connect\((.+)\)", query_data)[0].split("|", 1) | ||
|
||
f_count = await db.cf_count(chat_id, int(channel_id)) | ||
|
||
remove_active = await db.del_active(chat_id, int(channel_id)) | ||
|
||
if not remove_active: | ||
await update.answer("Couldnt Full Fill YOur Request...\n Report This @CrazyBotszGrp Along With Bot's Log", show_alert=True) | ||
return | ||
|
||
text= f"😑Sucessfully Disconnected From <code>{channel_name}</code>\n" | ||
text+=f"\n😮💨Info About <b>{channel_name}</b>\n" | ||
text+=f"\n😶🌫️Channel Name: <code>{channel_name}</code>\n" | ||
text+=f"\n🆔Channel ID: <code>{channel_id}</code>\n" | ||
text+=f"\n🗂️Channel Files: <code>{f_count}</code>\n" | ||
text+=f"\n🤨Current Status: <code>Disconnected</code>\n" | ||
text += '\n🤨Current Status: <code>Disconnected</code>\n' | ||
|
||
buttons = [ | ||
[ | ||
InlineKeyboardButton | ||
( | ||
"💠 Connect 💠", callback_data=f"warn({channel_id}|{channel_name}|connect)" | ||
), | ||
|
||
InlineKeyboardButton | ||
( | ||
"Delete ❌", callback_data=f"warn({channel_id}|{channel_name}|c_delete)" | ||
) | ||
] | ||
] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function cb_disconnect
refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring
)
|
||
if user_id not in VERIFY.get(str(chat_id)): | ||
return | ||
|
||
channel_id, channel_name = re.findall(r"c_delete\((.+)\)", query_data)[0].split("|", 1) | ||
channel_id = int(channel_id) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function cb_channel_delete
refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring
)
|
||
if user_id not in VERIFY.get(str(chat_id)): | ||
return | ||
|
||
chat_id = re.findall(r"types\((.+)\)", query_data)[0] | ||
|
||
_types = await db.find_chat(int(chat_id)) | ||
|
||
text=f"<i>Filter Types Enabled/Disbled In <code>{chat_name}</code></i>\n" | ||
|
||
_types = _types["types"] | ||
vid = _types["video"] | ||
doc = _types["document"] | ||
aud = _types["audio"] | ||
|
||
buttons = [] | ||
|
||
if vid: | ||
text+="\n<i><b>Video Index:</b> Enabled</i>\n" | ||
v_e = "✅" | ||
vcb_data = f"toggle({chat_id}|video|False)" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function cb_types
refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring
)
|
||
if user_id not in VERIFY.get(str(chat_id)): | ||
return | ||
|
||
chat_id, types, val = re.findall(r"toggle\((.+)\)", query_data)[0].split("|", 2) | ||
|
||
_types = await db.find_chat(int(chat_id)) | ||
|
||
_types = _types["types"] | ||
vid = _types["video"] | ||
doc = _types["document"] | ||
aud = _types["audio"] | ||
|
||
if types == "video": | ||
vid = True if val=="True" else False | ||
elif types == "audio": | ||
aud = True if val=="True" else False | ||
|
||
if types == "audio": | ||
aud = val=="True" | ||
elif types == "document": | ||
doc = True if val=="True" else False | ||
|
||
|
||
doc = val=="True" | ||
|
||
|
||
elif types == "video": | ||
vid = val=="True" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function cb_toggle
refactored with the following changes:
- Simplify conditional into switch-like form (
switch
) - Simplify boolean if expression (
boolean-if-exp-identity
) - Replace f-string with no interpolated values with string (
remove-redundant-fstring
)
|
||
if user_id not in VERIFY.get(str(chat_id)): | ||
return | ||
|
||
chat_id = re.findall(r"config\((.+)\)", query_data)[0] | ||
|
||
settings = await db.find_chat(int(chat_id)) | ||
|
||
mp_count = settings["configs"]["max_pages"] | ||
mf_count = settings["configs"]["max_results"] | ||
mr_count = settings["configs"]["max_per_page"] | ||
show_invite = settings["configs"]["show_invite_link"] | ||
pm_file_chat = settings["configs"].get("pm_fchat", False) | ||
accuracy_point = settings["configs"].get("accuracy", 0.80) | ||
|
||
text=f"<b>Configure Your <u><code>{chat_name}</code></u> Group's Filter Settings...</b>\n" | ||
|
||
text+=f"\n{chat_name} Current Settings:\n" | ||
|
||
text+=f"\n • Max Filter: <code>{mf_count}</code>\n" | ||
|
||
text+=f"\n • Max Pages: <code>{mp_count}</code>\n" | ||
|
||
text+=f"\n • Max Filter Per Page: <code>{mr_count}</code>\n" | ||
|
||
text+=f"\n • Accuracy Percentage: <code>{accuracy_point}</code>\n" | ||
|
||
text+=f"\n • Show Invitation Link: <code>{show_invite}</code>\n" | ||
|
||
text+=f"\n • Provide File In Bot PM: <code>{pm_file_chat}</code>\n" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function cb_config
refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring
)
|
||
if user_id not in VERIFY.get(str(chat_id)): | ||
return | ||
|
||
value, chat_id = re.findall(r"show_invites\((.+)\)", query_data)[0].split("|", 1) | ||
value = True if value=="True" else False | ||
|
||
value = value=="True" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function cb_show_invites
refactored with the following changes:
- Simplify boolean if expression (
boolean-if-exp-identity
) - Replace f-string with no interpolated values with string (
remove-redundant-fstring
)
|
||
if user_id not in VERIFY.get(str(chat_id)): | ||
return | ||
|
||
value, chat_id = re.findall(r"inPM\((.+)\)", query_data)[0].split("|", 1) | ||
|
||
value = True if value=="True" else False | ||
value = value=="True" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function cb_pm_file
refactored with the following changes:
- Simplify boolean if expression (
boolean-if-exp-identity
) - Replace f-string with no interpolated values with string (
remove-redundant-fstring
)
|
||
|
||
if user_id not in VERIFY.get(str(chat_id)): | ||
return | ||
|
||
val, chat_id = re.findall(r"accuracy\((.+)\)", query_data)[0].split("|", 1) | ||
|
||
text = f"<i>Choose Your Desired 'Accuracy Perceentage' For Every Filter Results Shown In</i> <code>{chat_name}</code>\n\n" | ||
text+= f"<i>NB: Higher The Value Better Matching Results Will Be Provided... And If Value Is Lower It Will Show More Results \ | ||
Which Is Fimilary To Query Search (Wont Be Accurate)....</i>" | ||
text += '<i>NB: Higher The Value Better Matching Results Will Be Provided... And If Value Is Lower It Will Show More Results \\\x1f Which Is Fimilary To Query Search (Wont Be Accurate)....</i>' | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function cb_accuracy
refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring
)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function cb_set
refactored with the following changes:
- Simplify conditional into switch-like form (
switch
) - Simplify boolean if expression (
boolean-if-exp-identity
) - Replace f-string with no interpolated values with string (
remove-redundant-fstring
)
This removes the following comments ( why? ):
# Scophisticated way 😂🤣
|
||
if user_id not in VERIFY.get(str(chat_id)): | ||
return | ||
|
||
text=f"<b><u>🤖Bot's Status</u></b>\n" | ||
text = "<b><u>🤖Bot's Status</u></b>\n" | ||
text+=f"\n🕐Bot's Uptime: <code>{time_formatter(time.time() - start_uptime)}</code>\n" | ||
text+=f"\nBot Funtion: <b><>Auto Filter & Manual Filters</b>" | ||
text += '\nBot Funtion: <b><>Auto Filter & Manual Filters</b>' | ||
|
||
buttons = [[ | ||
InlineKeyboardButton("🔙 Back", callback_data="settings"), | ||
InlineKeyboardButton("Close 🔐", callback_data="close") | ||
]] | ||
]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function cb_about
refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring
)
collections = mydb.list_collection_names() | ||
collections = mydb.list_collection_names() | ||
|
||
if "CONNECTION" in collections: | ||
collections.remove("CONNECTION") | ||
if "USERS" in collections: | ||
collections.remove("USERS") | ||
if "CONNECTION" in collections: | ||
collections.remove("CONNECTION") | ||
if "USERS" in collections: | ||
collections.remove("USERS") | ||
|
||
totalcount = 0 | ||
for collection in collections: | ||
mycol = mydb[collection] | ||
count = mycol.count() | ||
totalcount = totalcount + count | ||
totalcount = 0 | ||
for collection in collections: | ||
mycol = mydb[collection] | ||
count = mycol.count() | ||
totalcount += count | ||
|
||
totalcollections = len(collections) | ||
totalcollections = len(collections) | ||
|
||
return totalcollections, totalcount | ||
return totalcollections, totalcount |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function filter_stats
refactored with the following changes:
- Replace assignment with augmented assignment (
aug-assign
)
query = mycol.find_one( | ||
{ "_id": user_id }, | ||
{ "_id": 0, "active_group": 0 } | ||
) | ||
if query is not None: | ||
group_ids = [] | ||
for x in query["group_details"]: | ||
group_ids.append(x["group_id"]) | ||
|
||
if group_id in group_ids: | ||
return False | ||
|
||
group_details = { | ||
"group_id" : group_id | ||
} | ||
|
||
data = { | ||
'_id': user_id, | ||
'group_details' : [group_details], | ||
'active_group' : group_id, | ||
} | ||
|
||
if mycol.count_documents( {"_id": user_id} ) == 0: | ||
try: | ||
mycol.insert_one(data) | ||
return True | ||
except: | ||
print('Some error occured!') | ||
|
||
else: | ||
try: | ||
mycol.update_one( | ||
{'_id': user_id}, | ||
{ | ||
"$push": {"group_details": group_details}, | ||
"$set": {"active_group" : group_id} | ||
} | ||
query = mycol.find_one( | ||
{ "_id": user_id }, | ||
{ "_id": 0, "active_group": 0 } | ||
) | ||
return True | ||
except: | ||
print('Some error occured!') | ||
if query is not None: | ||
group_ids = [x["group_id"] for x in query["group_details"]] | ||
if group_id in group_ids: | ||
return False | ||
|
||
group_details = { | ||
"group_id" : group_id | ||
} | ||
|
||
data = { | ||
'_id': user_id, | ||
'group_details' : [group_details], | ||
'active_group' : group_id, | ||
} | ||
|
||
if mycol.count_documents( {"_id": user_id} ) == 0: | ||
try: | ||
mycol.insert_one(data) | ||
return True | ||
except: | ||
print('Some error occured!') | ||
|
||
else: | ||
try: | ||
mycol.update_one( | ||
{'_id': user_id}, | ||
{ | ||
"$push": {"group_details": group_details}, | ||
"$set": {"active_group" : group_id} | ||
} | ||
) | ||
return True | ||
except: | ||
print('Some error occured!') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function add_connection
refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension
)
query = mycol.find_one( | ||
{ "_id": user_id }, | ||
{ "_id": 0, "group_details": 0 } | ||
) | ||
if query: | ||
group_id = query['active_group'] | ||
if group_id != None: | ||
return int(group_id) | ||
else: | ||
return None | ||
else: | ||
return None | ||
query = mycol.find_one( | ||
{ "_id": user_id }, | ||
{ "_id": 0, "group_details": 0 } | ||
) | ||
if not query: | ||
return None | ||
group_id = query['active_group'] | ||
if group_id != None: | ||
return int(group_id) | ||
else: | ||
return None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function active_connection
refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
)
query = mycol.find_one( | ||
{ "_id": user_id }, | ||
{ "_id": 0, "active_group": 0 } | ||
) | ||
if query is not None: | ||
group_ids = [] | ||
for x in query["group_details"]: | ||
group_ids.append(x["group_id"]) | ||
return group_ids | ||
else: | ||
return None | ||
query = mycol.find_one( | ||
{ "_id": user_id }, | ||
{ "_id": 0, "active_group": 0 } | ||
) | ||
if query is not None: | ||
return [x["group_id"] for x in query["group_details"]] | ||
else: | ||
return None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function all_connections
refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
)
query = mycol.find_one( | ||
{ "_id": user_id }, | ||
{ "_id": 0, "group_details": 0 } | ||
) | ||
if query is not None: | ||
if query['active_group'] == group_id: | ||
return True | ||
else: | ||
return False | ||
else: | ||
return False | ||
query = mycol.find_one( | ||
{ "_id": user_id }, | ||
{ "_id": 0, "group_details": 0 } | ||
) | ||
return query is not None and query['active_group'] == group_id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function if_active
refactored with the following changes:
- Merge duplicate blocks in conditional (
merge-duplicate-blocks
) - Simplify conditional into return statement (
return-identity
)
update = mycol.update_one( | ||
{'_id': user_id}, | ||
{"$set": {"active_group" : group_id}} | ||
) | ||
if update.modified_count == 0: | ||
return False | ||
else: | ||
return True | ||
update = mycol.update_one( | ||
{'_id': user_id}, | ||
{"$set": {"active_group" : group_id}} | ||
) | ||
return update.modified_count != 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function make_active
refactored with the following changes:
- Simplify conditional into return statement (
return-identity
)
update = mycol.update_one( | ||
{'_id': user_id}, | ||
{"$set": {"active_group" : None}} | ||
) | ||
if update.modified_count == 0: | ||
return False | ||
else: | ||
return True | ||
update = mycol.update_one( | ||
{'_id': user_id}, | ||
{"$set": {"active_group" : None}} | ||
) | ||
return update.modified_count != 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function make_inactive
refactored with the following changes:
- Simplify conditional into return statement (
return-identity
)
try: | ||
update = mycol.update_one( | ||
{"_id": user_id}, | ||
{"$pull" : { "group_details" : {"group_id":group_id} } } | ||
) | ||
if update.modified_count == 0: | ||
return False | ||
else: | ||
query = mycol.find_one( | ||
{ "_id": user_id }, | ||
{ "_id": 0 } | ||
) | ||
if len(query["group_details"]) >= 1: | ||
if query['active_group'] == group_id: | ||
prvs_group_id = query["group_details"][len(query["group_details"]) - 1]["group_id"] | ||
|
||
mycol.update_one( | ||
{'_id': user_id}, | ||
{"$set": {"active_group" : prvs_group_id}} | ||
) | ||
else: | ||
mycol.update_one( | ||
{'_id': user_id}, | ||
{"$set": {"active_group" : None}} | ||
) | ||
return True | ||
except Exception as e: | ||
print(e) | ||
return False | ||
try: | ||
update = mycol.update_one( | ||
{"_id": user_id}, | ||
{"$pull" : { "group_details" : {"group_id":group_id} } } | ||
) | ||
if update.modified_count == 0: | ||
return False | ||
query = mycol.find_one( | ||
{ "_id": user_id }, | ||
{ "_id": 0 } | ||
) | ||
if len(query["group_details"]) >= 1: | ||
if query['active_group'] == group_id: | ||
prvs_group_id = query["group_details"][len(query["group_details"]) - 1]["group_id"] | ||
|
||
mycol.update_one( | ||
{'_id': user_id}, | ||
{"$set": {"active_group" : prvs_group_id}} | ||
) | ||
else: | ||
mycol.update_one( | ||
{'_id': user_id}, | ||
{"$set": {"active_group" : None}} | ||
) | ||
return True | ||
except Exception as e: | ||
print(e) | ||
return False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function delete_connection
refactored with the following changes:
- Remove unnecessary else after guard condition (
remove-unnecessary-else
)
count = aambro.count() | ||
return count | ||
return aambro.count() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function all_users
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
if any(text.startswith(char) for char in START_CHAR): | ||
counter = 1 # ignore first char -> is some kind of quote | ||
while counter < len(text): | ||
if text[counter] == "\\": | ||
if not any(text.startswith(char) for char in START_CHAR): | ||
return text.split(None, 1) | ||
counter = 1 # ignore first char -> is some kind of quote | ||
while counter < len(text): | ||
if text[counter] == "\\": | ||
counter += 1 | ||
elif text[counter] == text[0] or (text[0] == SMART_OPEN and text[counter] == SMART_CLOSE): | ||
break | ||
counter += 1 | ||
elif text[counter] == text[0] or (text[0] == SMART_OPEN and text[counter] == SMART_CLOSE): | ||
break | ||
counter += 1 | ||
else: | ||
return text.split(None, 1) | ||
|
||
# 1 to avoid starting quote, and counter is exclusive so avoids ending | ||
key = remove_escapes(text[1:counter].strip()) | ||
# index will be in range, or `else` would have been executed and returned | ||
rest = text[counter + 1:].strip() | ||
if not key: | ||
key = text[0] + text[0] | ||
return list(filter(None, [key, rest])) | ||
else: | ||
return text.split(None, 1) | ||
|
||
def parser(text, keyword): | ||
if "buttonalert" in text: | ||
text = (text.replace("\n", "\\n").replace("\t", "\\t")) | ||
buttons = [] | ||
note_data = "" | ||
prev = 0 | ||
i = 0 | ||
alerts = [] | ||
for match in BTN_URL_REGEX.finditer(text): | ||
# Check if btnurl is escaped | ||
n_escapes = 0 | ||
to_check = match.start(1) - 1 | ||
while to_check > 0 and text[to_check] == "\\": | ||
n_escapes += 1 | ||
to_check -= 1 | ||
|
||
# if even, not escaped -> create button | ||
if n_escapes % 2 == 0: | ||
note_data += text[prev:match.start(1)] | ||
prev = match.end(1) | ||
if match.group(3) == "buttonalert": | ||
# create a thruple with button label, url, and newline status | ||
if bool(match.group(5)) and buttons: | ||
buttons[-1].append(InlineKeyboardButton( | ||
text=match.group(2), | ||
callback_data=f"alertmessage:{i}:{keyword}" | ||
)) | ||
else: | ||
buttons.append([InlineKeyboardButton( | ||
text=match.group(2), | ||
callback_data=f"alertmessage:{i}:{keyword}" | ||
)]) | ||
i = i + 1 | ||
alerts.append(match.group(4)) | ||
else: | ||
if bool(match.group(5)) and buttons: | ||
buttons[-1].append(InlineKeyboardButton( | ||
text=match.group(2), | ||
url=match.group(4).replace(" ", "") | ||
)) | ||
else: | ||
buttons.append([InlineKeyboardButton( | ||
text=match.group(2), | ||
url=match.group(4).replace(" ", "") | ||
)]) | ||
return text.split(None, 1) | ||
|
||
# if odd, escaped -> move along | ||
else: | ||
note_data += text[prev:to_check] | ||
prev = match.start(1) - 1 | ||
else: | ||
note_data += text[prev:] | ||
# 1 to avoid starting quote, and counter is exclusive so avoids ending | ||
key = remove_escapes(text[1:counter].strip()) | ||
# index will be in range, or `else` would have been executed and returned | ||
rest = text[counter + 1:].strip() | ||
if not key: | ||
key = text[0] + text[0] | ||
return list(filter(None, [key, rest])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function split_quotes
refactored with the following changes:
- Add guard clause (
last-if-guard
)
if not len(message.command) > 1: | ||
if len(message.command) <= 1: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function temp_ban_user
refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan
)
|
||
while True: | ||
broadcast_id = ''.join([random.choice(string.ascii_letters) for i in range(3)]) | ||
if not broadcast_ids.get(broadcast_id): | ||
break | ||
|
||
out = await m.reply_text( | ||
text = f"Broadcast initiated! You will be notified with log file when all the users are notified." | ||
text='Broadcast initiated! You will be notified with log file when all the users are notified.' | ||
) | ||
|
||
start_time = time.time() | ||
total_users = await db.total_users_count() | ||
done = 0 | ||
failed = 0 | ||
success = 0 | ||
|
||
broadcast_ids[broadcast_id] = dict( | ||
total = total_users, | ||
current = done, | ||
failed = failed, | ||
success = success | ||
) | ||
|
||
async with aiofiles.open('broadcast.txt', 'w') as broadcast_log_file: | ||
async for user in all_users: | ||
|
||
sts, msg = await send_msg( | ||
user_id = int(user['id']), | ||
message = broadcast_msg | ||
) | ||
if msg is not None: | ||
await broadcast_log_file.write(msg) | ||
|
||
if sts == 200: | ||
success += 1 | ||
else: | ||
failed += 1 | ||
|
||
if sts == 400: | ||
await db.delete_user(user['id']) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function broadcast_
refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring
)
covid_info = f"""<b>Covid 19 Information</b> | ||
return f"""<b>Covid 19 Information</b> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function covid_info
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
if not len(message.command) > 1: | ||
if len(message.command) <= 1: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function temp_mute_user
refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan
)
elif message.reply_to_message.text: | ||
else: | ||
message_s = message.reply_to_message.text | ||
|
||
ext = "py" | ||
x = await p_paste(message_s, ext) | ||
p_link = x["url"] | ||
p_raw = x["raw"] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function pasty
refactored with the following changes:
- Remove redundant conditional (
remove-redundant-if
)
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 0.36%.
Here are some functions in these files that still need a tune-up:
Legend and ExplanationThe emojis denote the absolute quality of the code:
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! |
Branch
Professor-99
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
Professor-99
branch, then run:Help us improve this pull request!