-
Notifications
You must be signed in to change notification settings - Fork 1
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 #1
base: master
Are you sure you want to change the base?
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.
class Config(object): | ||
|
||
|
||
class Config((object)): |
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.
Lines 9-80
refactored with the following changes:
- Replace list(), dict() or set() with comprehension (
collection-builtin-to-comprehension
)
for p in props: | ||
if not p in dic: | ||
return False | ||
return True | ||
return all(p in dic for p in props) |
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 Main.dict_has_props
refactored with the following changes:
- Use any() instead of for loop (
use-any
) - Invert any/all to simplify comparisons (
invert-any-all
)
buffer_size = self.options.buffer | ||
|
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 Main.request_download
refactored with the following changes:
- Move assignments closer to their usage (
move-assign
)
if not file_name is None: | ||
if file_name is not 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 Main.download
refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan
)
if not (str(event.chat_id) in CHAT_FLOOD): | ||
if str(event.chat_id) not in CHAT_FLOOD: |
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 _
refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan
)
await event.delete() | ||
else: | ||
await event.reply(help_string + "\n\n" + s_help_string) | ||
await event.delete() | ||
|
||
await event.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 _
refactored with the following changes:
- Hoist repeated code outside conditional statement (
hoist-statement-from-if
)
if "\\n" in names: | ||
if "\\n" in first_name: |
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 _
refactored with the following changes:
- Use previously assigned local variable (
use-assigned-variable
)
@borg.on(events.NewMessage(pattern=r"\.afk ?(.*)", outgoing=True)) | ||
@borg.on(events.NewMessage(pattern=r"\.afk ?(.*)", outgoing=True)) | ||
async def _(event): | ||
if event.fwd_from: | ||
return | ||
global USER_AFK | ||
global afk_time | ||
global last_afk_message | ||
global USER_AFK | ||
global afk_time | ||
global last_afk_message | ||
global reason | ||
USER_AFK = {} | ||
afk_time = datetime.datetime.now() | ||
last_afk_message = {} | ||
reason = event.pattern_match.group(1) | ||
if not USER_AFK: | ||
reason = event.pattern_match.group(1) | ||
last_seen_status = await borg( | ||
functions.account.GetPrivacyRequest( | ||
types.InputPrivacyKeyStatusTimestamp() | ||
) | ||
) | ||
if isinstance(last_seen_status.rules, types.PrivacyValueAllowAll): | ||
afk_time = datetime.datetime.now() | ||
USER_AFK = f"yes: {reason}" | ||
afk_time = datetime.datetime.now() | ||
USER_AFK = f"yes: {reason}" |
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 _
refactored with the following changes:
- Move assignments closer to their usage (
move-assign
)
global USER_AFK | ||
global afk_time | ||
global last_afk_message | ||
global USER_AFK | ||
global afk_time | ||
global last_afk_message |
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 on_afk
refactored with the following changes:
- Replace assignment with augmented assignment (
aug-assign
)
output = "output.txt" | ||
downloads = aria2.get_downloads() | ||
downloads = aria2.get_downloads() |
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 show_all
refactored with the following changes:
- Move assignments closer to their usage (
move-assign
)
CARBONLANG = "en" | ||
textx = await e.get_reply_message() | ||
pcode = e.text | ||
if pcode[8:]: | ||
pcode = str(pcode[8:]) | ||
elif textx: | ||
pcode = str(textx.message) # Importing message to module | ||
code = quote_plus(pcode) # Converting to urlencoded | ||
url = CARBON.format(code=code, lang=CARBONLANG) | ||
chrome_options = Options() | ||
chrome_options.add_argument("--headless") | ||
chrome_options.binary_location = Config.GOOGLE_CHROME_BIN | ||
chrome_options.add_argument("--window-size=1920x1080") | ||
chrome_options.add_argument("--disable-dev-shm-usage") | ||
chrome_options.add_argument("--no-sandbox") | ||
chrome_options.add_argument('--disable-gpu') | ||
prefs = {'download.default_directory' : './'} | ||
chrome_options.add_experimental_option('prefs', prefs) | ||
await e.edit("⬛⬛⬜⬜⬜ 30%") | ||
if e.text[0].isalpha() or e.text[0] in ("/", "#", "@", "!"): | ||
return | ||
|
||
driver = webdriver.Chrome(executable_path=Config.GOOGLE_CHROME_DRIVER, options=chrome_options) | ||
driver.get(url) | ||
download_path = './' | ||
driver.command_executor._commands["send_command"] = ("POST", '/session/$sessionId/chromium/send_command') | ||
params = {'cmd': 'Page.setDownloadBehavior', 'params': {'behavior': 'allow', 'downloadPath': download_path}} | ||
command_result = driver.execute("send_command", params) | ||
""" A Wrapper for carbon.now.sh """ | ||
await e.edit("⬜⬜⬜⬜⬜ 00%") | ||
CARBON = 'https://carbon.now.sh/?l={lang}&code={code}' | ||
CARBONLANG = "en" | ||
textx = await e.get_reply_message() | ||
pcode = e.text | ||
if pcode[8:]: | ||
pcode = str(pcode[8:]) | ||
elif textx: | ||
pcode = str(textx.message) # Importing message to module | ||
code = quote_plus(pcode) # Converting to urlencoded | ||
url = CARBON.format(code=code, lang=CARBONLANG) | ||
chrome_options = Options() | ||
chrome_options.add_argument("--headless") | ||
chrome_options.binary_location = Config.GOOGLE_CHROME_BIN | ||
chrome_options.add_argument("--window-size=1920x1080") | ||
chrome_options.add_argument("--disable-dev-shm-usage") | ||
chrome_options.add_argument("--no-sandbox") | ||
chrome_options.add_argument('--disable-gpu') | ||
prefs = {'download.default_directory' : './'} | ||
chrome_options.add_experimental_option('prefs', prefs) | ||
await e.edit("⬛⬛⬜⬜⬜ 30%") | ||
|
||
driver.find_element_by_xpath("//button[contains(text(),'Export')]").click() | ||
sleep(5) # this might take a bit. | ||
driver.find_element_by_xpath("//button[contains(text(),'4x')]").click() | ||
sleep(5) | ||
await e.edit("⬛⬛⬛⬜⬜ 50%") | ||
driver.find_element_by_xpath("//button[contains(text(),'PNG')]").click() | ||
sleep(5) #Waiting for downloading | ||
driver = webdriver.Chrome(executable_path=Config.GOOGLE_CHROME_DRIVER, options=chrome_options) | ||
driver.get(url) | ||
download_path = './' | ||
driver.command_executor._commands["send_command"] = ("POST", '/session/$sessionId/chromium/send_command') | ||
params = {'cmd': 'Page.setDownloadBehavior', 'params': {'behavior': 'allow', 'downloadPath': download_path}} | ||
command_result = driver.execute("send_command", params) | ||
|
||
await e.edit("⬛⬛⬛⬛⬛ 100%") | ||
file = './carbon.png' | ||
await e.edit("✅Carbon Completed, Uploading Carbon✅") | ||
await e.client.send_file( | ||
e.chat_id, | ||
file, | ||
caption="Carbon by [@NeoMatrix90](https://t.me/NeoMatrix90)/", | ||
force_document=True, | ||
reply_to=e.message.reply_to_msg_id, | ||
) | ||
driver.find_element_by_xpath("//button[contains(text(),'Export')]").click() | ||
sleep(5) # this might take a bit. | ||
driver.find_element_by_xpath("//button[contains(text(),'4x')]").click() | ||
sleep(5) | ||
await e.edit("⬛⬛⬛⬜⬜ 50%") | ||
driver.find_element_by_xpath("//button[contains(text(),'PNG')]").click() | ||
sleep(5) #Waiting for downloading | ||
|
||
os.remove('./carbon.png') | ||
# Removing carbon.png after uploading | ||
await e.delete() # Deleting msg | ||
await e.edit("⬛⬛⬛⬛⬛ 100%") | ||
file = './carbon.png' | ||
await e.edit("✅Carbon Completed, Uploading Carbon✅") | ||
await e.client.send_file( | ||
e.chat_id, | ||
file, | ||
caption="Carbon by [@NeoMatrix90](https://t.me/NeoMatrix90)/", | ||
force_document=True, | ||
reply_to=e.message.reply_to_msg_id, | ||
) | ||
|
||
os.remove('./carbon.png') | ||
# Removing carbon.png after uploading | ||
await e.delete() # Deleting msg |
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 carbon_api
refactored with the following changes:
- Add guard clause (
last-if-guard
)
elif type_of_group == "g" or type_of_group == "c": | ||
elif type_of_group in ["g", "c"]: |
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 _
refactored with the following changes:
- Replace multiple comparisons of same variable with
in
operator (merge-comparisons
)
CHUNK_SIZE = 2341 | ||
downloaded = 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 download_coroutine
refactored with the following changes:
- Remove redundant pass statement (
remove-redundant-pass
) - Move assignments closer to their usage (
move-assign
)
animation_ttl = range(0, 16) | ||
animation_ttl = range(16) |
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 _
refactored with the following changes:
- Replace range(0, x) with range(x) (
remove-zero-from-range
)
@@ -43,7 +43,6 @@ async def _(event): | |||
new_required_file_name = "" | |||
new_required_file_caption = "" | |||
command_to_run = [] | |||
force_document = 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 _
refactored with the following changes:
- Move assignments closer to their usage (
move-assign
)
download_url = response.get("webContentLink") | ||
return download_url | ||
return response.get("webContentLink") |
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 upload_file
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
BASE_URL = "http://www.google.com" | ||
OUTPUT_STR = "Reply to an image to do Google Reverse Search" | ||
if event.reply_to_msg_id: | ||
await event.edit("Pre Processing Media") | ||
previous_message = await event.get_reply_message() | ||
previous_message_text = previous_message.message | ||
BASE_URL = "http://www.google.com" |
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 _
refactored with the following changes:
- Move assignments closer to their usage (
move-assign
)
if info: | ||
mov_country = [] | ||
mov_language = [] | ||
for node in info: | ||
a = node.findAll('a') | ||
for i in a: | ||
if "country_of_origin" in i['href']: | ||
mov_country.append(i.text) | ||
elif "primary_language" in i['href']: | ||
mov_language.append(i.text) | ||
if soup.findAll('div',"ratingValue"): | ||
for r in soup.findAll('div',"ratingValue"): | ||
mov_rating = r.strong['title'] | ||
else: | ||
mov_rating = 'Not available' | ||
await e.edit('<a href='+poster+'>​</a>' | ||
'<b>Title : </b><code>'+mov_title+ | ||
'</code>\n<code>'+mov_details+ | ||
'</code>\n<b>Rating : </b><code>'+mov_rating+ | ||
'</code>\n<b>Country : </b><code>'+mov_country[0]+ | ||
'</code>\n<b>Language : </b><code>'+mov_language[0]+ | ||
'</code>\n<b>Director : </b><code>'+director+ | ||
'</code>\n<b>Writer : </b><code>'+writer+ | ||
'</code>\n<b>Stars : </b><code>'+stars+ | ||
'</code>\n<b>IMDB Url : </b>'+mov_link+ | ||
'\n<b>Story Line : </b>'+story_line, | ||
link_preview = True , parse_mode = 'HTML' | ||
) | ||
movie_name = e.pattern_match.group(1) | ||
remove_space = movie_name.split(' ') | ||
final_name = '+'.join(remove_space) | ||
page = requests.get("https://www.imdb.com/find?ref_=nv_sr_fn&q="+final_name+"&s=all") | ||
lnk = str(page.status_code) | ||
soup = bs4.BeautifulSoup(page.content,'lxml') | ||
odds = soup.findAll("tr","odd") | ||
mov_title = odds[0].findNext('td').findNext('td').text | ||
mov_link = "http://www.imdb.com/"+odds[0].findNext('td').findNext('td').a['href'] | ||
page1 = requests.get(mov_link) | ||
soup = bs4.BeautifulSoup(page1.content,'lxml') | ||
if soup.find('div','poster'): | ||
poster = soup.find('div','poster').img['src'] | ||
else: | ||
poster = '' | ||
if soup.find('div','title_wrapper'): | ||
pg = soup.find('div','title_wrapper').findNext('div').text | ||
mov_details = re.sub(r'\s+',' ',pg) | ||
else: | ||
mov_details = '' | ||
credits = soup.findAll('div', 'credit_summary_item') | ||
director = credits[0].a.text | ||
if len(credits)==1: | ||
writer = 'Not available' | ||
stars = 'Not available' | ||
elif len(credits)>2: | ||
writer = credits[1].a.text | ||
actors = [] | ||
for x in credits[2].findAll('a'): | ||
actors.append(x.text) | ||
actors.pop() | ||
stars = actors[0]+','+actors[1]+','+actors[2] | ||
else: | ||
writer = 'Not available' | ||
actors = [] | ||
for x in credits[1].findAll('a'): | ||
actors.append(x.text) | ||
actors.pop() | ||
stars = actors[0]+','+actors[1]+','+actors[2] | ||
if soup.find('div', "inline canwrap"): | ||
story_line = soup.find('div', "inline canwrap").findAll('p')[0].text | ||
else: | ||
story_line = 'Not available' | ||
info = soup.findAll('div', "txt-block") | ||
if info: | ||
mov_country = [] | ||
mov_language = [] | ||
for node in info: | ||
a = node.findAll('a') | ||
for i in a: | ||
if "country_of_origin" in i['href']: | ||
mov_country.append(i.text) | ||
elif "primary_language" in i['href']: | ||
mov_language.append(i.text) | ||
if soup.findAll('div',"ratingValue"): | ||
for r in soup.findAll('div',"ratingValue"): | ||
mov_rating = r.strong['title'] | ||
else: | ||
mov_rating = 'Not available' | ||
await e.edit('<a href='+poster+'>​</a>' | ||
'<b>Title : </b><code>'+mov_title+ | ||
'</code>\n<code>'+mov_details+ | ||
'</code>\n<b>Rating : </b><code>'+mov_rating+ | ||
'</code>\n<b>Country : </b><code>'+mov_country[0]+ | ||
'</code>\n<b>Language : </b><code>'+mov_language[0]+ | ||
'</code>\n<b>Director : </b><code>'+director+ | ||
'</code>\n<b>Writer : </b><code>'+writer+ | ||
'</code>\n<b>Stars : </b><code>'+stars+ | ||
'</code>\n<b>IMDB Url : </b>'+mov_link+ | ||
'\n<b>Story Line : </b>'+story_line, | ||
link_preview = True , parse_mode = 'HTML' | ||
) |
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 imdb
refactored with the following changes:
- Hoist repeated code outside conditional statement (
hoist-statement-from-if
)
@@ -27,7 +27,6 @@ async def _(event): | |||
)) | |||
except Exception as e: | |||
await event.reply(str(e)) | |||
await event.edit("Invited Successfully") |
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 _
refactored with the following changes:
- Hoist repeated code outside conditional statement (
hoist-statement-from-if
)
if Config.NC_LOG_P_M_S: | ||
if event.is_private: | ||
if chat.id not in NO_PM_LOG_USERS: | ||
NO_PM_LOG_USERS.append(chat.id) | ||
await event.edit("Won't Log Messages from this chat") | ||
await asyncio.sleep(3) | ||
await event.delete() | ||
if ( | ||
Config.NC_LOG_P_M_S | ||
and event.is_private | ||
and chat.id not in NO_PM_LOG_USERS | ||
): | ||
NO_PM_LOG_USERS.append(chat.id) | ||
await event.edit("Won't Log Messages from this chat") | ||
await asyncio.sleep(3) | ||
await event.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 approve_p_m
refactored with the following changes:
- Merge nested if conditions (
merge-nested-ifs
)
languages = {} | ||
languages["English"] = "eng" | ||
languages["Arabic"] = "ara" | ||
languages["Bulgarian"] = "bul" | ||
languages["Chinese (Simplified)"] = "chs" | ||
languages["Chinese (Traditional)"] = "cht" | ||
languages["Croatian"] = "hrv" | ||
languages["Czech"] = "cze" | ||
languages["Danish"] = "dan" | ||
languages["Dutch"] = "dut" | ||
languages["Finnish"] = "fin" | ||
languages["French"] = "fre" | ||
languages["German"] = "ger" | ||
languages["Greek"] = "gre" | ||
languages["Hungarian"] = "hun" | ||
languages["Korean"] = "kor" | ||
languages["Italian"] = "ita" | ||
languages["Japanese"] = "jpn" | ||
languages["Polish"] = "pol" | ||
languages["Portuguese"] = "por" | ||
languages["Russian"] = "rus" | ||
languages["Slovenian"] = "slv" | ||
languages["Spanish"] = "spa" | ||
languages["Swedish"] = "swe" | ||
languages["Turkish"] = "tur" | ||
languages = { | ||
"English": "eng", | ||
"Arabic": "ara", | ||
"Bulgarian": "bul", | ||
"Chinese (Simplified)": "chs", | ||
"Chinese (Traditional)": "cht", | ||
"Croatian": "hrv", | ||
"Czech": "cze", | ||
"Danish": "dan", | ||
"Dutch": "dut", | ||
"Finnish": "fin", | ||
"French": "fre", | ||
"German": "ger", | ||
"Greek": "gre", | ||
"Hungarian": "hun", | ||
"Korean": "kor", | ||
"Italian": "ita", | ||
"Japanese": "jpn", | ||
"Polish": "pol", | ||
"Portuguese": "por", | ||
"Russian": "rus", | ||
"Slovenian": "slv", | ||
"Spanish": "spa", | ||
"Swedish": "swe", | ||
"Turkish": "tur", | ||
} | ||
|
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_ocr_languages
refactored with the following changes:
- Merge dictionary assignment with declaration (
merge-dict-assign
)
if reply_message.media is None: | ||
await event.edit("Please reply to a media_type == @gPoll to view the questions and answers") | ||
elif reply_message.media.poll is None: | ||
if reply_message.media is None or reply_message.media.poll is 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 _
refactored with the following changes:
- Merge duplicate blocks in conditional (
merge-duplicate-blocks
) - Remove redundant conditional (
remove-redundant-if
)
i = i + 1 | ||
i += 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 _
refactored with the following changes:
- Replace assignment with augmented assignment (
aug-assign
)
@@ -35,7 +35,6 @@ | |||
|
|||
@borg.on(admin_cmd(pattern="remove\.bg ?(.*)")) | |||
async def _(event): | |||
HELP_STR = "`.remove.bg` as reply to a media, or give a link as an argument to this command" |
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 _
refactored with the following changes:
- Move assignments closer to their usage (
move-assign
)
r = requests.post( | ||
return requests.post( | ||
"https://api.remove.bg/v1.0/removebg", | ||
headers=headers, | ||
files=files, | ||
allow_redirects=True, | ||
stream=True | ||
) | ||
return r |
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 ReTrieveFile
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
p = p + 1 | ||
p += 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 _
refactored with the following changes:
- Replace assignment with augmented assignment (
aug-assign
)
u = u + 1 | ||
u += 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 _
refactored with the following changes:
- Replace assignment with augmented assignment (
aug-assign
)
await mone.edit("Found `{}` in {} seconds.".format(input_str, ms)) | ||
await mone.edit("Found `{}` in {} seconds.".format(required_file_name, ms)) |
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 _
refactored with the following changes:
- Move assignments closer to their usage (
move-assign
) - Use previously assigned local variable (
use-assigned-variable
)
if not show.text[0].isalpha() and show.text[0] not in ("/", "#", "@", "!"): | ||
if not show.is_group: | ||
await show.edit("Are you sure this is a group?") | ||
return | ||
info = await show.client.get_entity(show.chat_id) | ||
title = info.title if info.title else "this chat" | ||
mentions = 'Users in {}: \n'.format(title) | ||
try: | ||
if not show.pattern_match.group(1): | ||
async for user in show.client.iter_participants(show.chat_id): | ||
if not user.deleted: | ||
mentions += f"\n[{user.first_name}](tg://user?id={user.id}) `{user.id}`" | ||
else: | ||
mentions += f"\nDeleted Account `{user.id}`" | ||
else: | ||
searchq = show.pattern_match.group(1) | ||
async for user in show.client.iter_participants(show.chat_id, search=f'{searchq}'): | ||
if not user.deleted: | ||
mentions += f"\n[{user.first_name}](tg://user?id={user.id}) `{user.id}`" | ||
else: | ||
mentions += f"\nDeleted Account `{user.id}`" | ||
except ChatAdminRequiredError as err: | ||
mentions += " " + str(err) + "\n" | ||
try: | ||
await show.edit(mentions) | ||
except MessageTooLongError: | ||
await show.edit("Damn, this is a huge group. Uploading users lists as file.") | ||
file = open("userslist.txt", "w+") | ||
file.write(mentions) | ||
file.close() | ||
await show.client.send_file( | ||
show.chat_id, | ||
"userslist.txt", | ||
caption='Users in {}'.format(title), | ||
reply_to=show.id, | ||
) | ||
remove("userslist.txt") | ||
if show.text[0].isalpha() or show.text[0] in ("/", "#", "@", "!"): | ||
return | ||
if not show.is_group: | ||
await show.edit("Are you sure this is a group?") | ||
return | ||
info = await show.client.get_entity(show.chat_id) | ||
title = info.title if info.title else "this chat" | ||
mentions = 'Users in {}: \n'.format(title) | ||
try: | ||
if show.pattern_match.group(1): | ||
searchq = show.pattern_match.group(1) | ||
async for user in show.client.iter_participants(show.chat_id, search=f'{searchq}'): | ||
if user.deleted: | ||
mentions += f"\nDeleted Account `{user.id}`" | ||
else: | ||
mentions += f"\n[{user.first_name}](tg://user?id={user.id}) `{user.id}`" | ||
else: | ||
async for user in show.client.iter_participants(show.chat_id): | ||
if not user.deleted: | ||
mentions += f"\n[{user.first_name}](tg://user?id={user.id}) `{user.id}`" | ||
else: | ||
mentions += f"\nDeleted Account `{user.id}`" | ||
except ChatAdminRequiredError as err: | ||
mentions += " " + str(err) + "\n" | ||
try: | ||
await show.edit(mentions) | ||
except MessageTooLongError: | ||
await show.edit("Damn, this is a huge group. Uploading users lists as file.") | ||
file = open("userslist.txt", "w+") | ||
file.write(mentions) | ||
file.close() | ||
await show.client.send_file( | ||
show.chat_id, | ||
"userslist.txt", | ||
caption='Users in {}'.format(title), | ||
reply_to=show.id, | ||
) | ||
remove("userslist.txt") |
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_users
refactored with the following changes:
- Add guard clause (
last-if-guard
)
else: | ||
pass | ||
|
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 _
refactored with the following changes:
- Remove redundant pass statement (
remove-redundant-pass
)
Hello @sourcery-ai[bot]! Thanks for opening this PR. We checked the lines you've touched for PEP 8 issues, and found:
|
Branch
master
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
master
branch, then run: