-
Notifications
You must be signed in to change notification settings - Fork 1
Sourcery refactored main branch #4
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
base: main
Are you sure you want to change the base?
Conversation
| class Var(object): | ||
|
|
||
|
|
||
| class Var((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-33 refactored with the following changes:
- Replace list(), dict() or set() with comprehension (
collection-builtin-to-comprehension)
| broadcast_id = ''.join([random.choice(string.ascii_letters) for i in range(3)]) | ||
| broadcast_id = ''.join([random.choice(string.ascii_letters) for _ 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.' | ||
| ) | ||
|
|
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 unused for index with underscore (
for-index-underscore) - Replace f-string with no interpolated values with string (
remove-redundant-fstring)
| print(f"Sleeping for {str(e.x)}s") | ||
| print(f'Sleeping for {e.x}s') | ||
| await asyncio.sleep(e.x) | ||
| await c.send_message(chat_id=Var.BIN_CHANNEL, text=f"Gᴏᴛ FʟᴏᴏᴅWᴀɪᴛ ᴏғ {str(e.x)}s from [{m.from_user.first_name}](tg://user?id={m.from_user.id})\n\n**𝚄𝚜𝚎𝚛 𝙸𝙳 :** `{str(m.from_user.id)}`", disable_web_page_preview=True, parse_mode="Markdown") | ||
| await c.send_message( | ||
| chat_id=Var.BIN_CHANNEL, | ||
| text=f'Gᴏᴛ FʟᴏᴏᴅWᴀɪᴛ ᴏғ {e.x}s from [{m.from_user.first_name}](tg://user?id={m.from_user.id})\n\n**𝚄𝚜𝚎𝚛 𝙸𝙳 :** `{m.from_user.id}`', | ||
| disable_web_page_preview=True, | ||
| parse_mode="Markdown", | ||
| ) |
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 private_receive_handler refactored with the following changes:
- Simplify unnecessary nesting, casting and constant values in f-strings (
simplify-fstring-formatting)
| text=f"**Cʜᴀɴɴᴇʟ Nᴀᴍᴇ:** `{broadcast.chat.title}`\n**Cʜᴀɴɴᴇʟ ID:** `{broadcast.chat.id}`\n**Rᴇǫᴜᴇsᴛ ᴜʀʟ:** https://t.me/{(await bot.get_me()).username}?start=AvishkarPatil_{str(log_msg.message_id)}", | ||
| # text=f"**Cʜᴀɴɴᴇʟ Nᴀᴍᴇ:** `{broadcast.chat.title}`\n**Cʜᴀɴɴᴇʟ ID:** `{broadcast.chat.id}`\n**Rᴇǫᴜᴇsᴛ ᴜʀʟ:** https://t.me/FxStreamBot?start=AvishkarPatil_{str(log_msg.message_id)}", | ||
| text=f'**Cʜᴀɴɴᴇʟ Nᴀᴍᴇ:** `{broadcast.chat.title}`\n**Cʜᴀɴɴᴇʟ ID:** `{broadcast.chat.id}`\n**Rᴇǫᴜᴇsᴛ ᴜʀʟ:** https://t.me/{(await bot.get_me()).username}?start=AvishkarPatil_{log_msg.message_id}', | ||
| quote=True, | ||
| parse_mode="Markdown" | ||
| parse_mode="Markdown", | ||
| ) | ||
|
|
||
| await bot.edit_message_reply_markup( | ||
| chat_id=broadcast.chat.id, | ||
| message_id=broadcast.message_id, | ||
| reply_markup=InlineKeyboardMarkup( | ||
| [[InlineKeyboardButton("Dᴏᴡɴʟᴏᴀᴅ ʟɪɴᴋ 📥", url=f"https://t.me/{(await bot.get_me()).username}?start=AvishkarPatil_{str(log_msg.message_id)}")]]) | ||
| # [[InlineKeyboardButton("Dᴏᴡɴʟᴏᴀᴅ ʟɪɴᴋ 📥", url=f"https://t.me/FxStreamBot?start=AvishkarPatil_{str(log_msg.message_id)}")]]) | ||
| [ | ||
| [ | ||
| InlineKeyboardButton( | ||
| "Dᴏᴡɴʟᴏᴀᴅ ʟɪɴᴋ 📥", | ||
| url=f'https://t.me/{(await bot.get_me()).username}?start=AvishkarPatil_{log_msg.message_id}', | ||
| ) | ||
| ] | ||
| ] | ||
| ), | ||
| ) | ||
|
|
||
| except FloodWait as w: | ||
| print(f"Sleeping for {str(w.x)}s") | ||
| print(f'Sleeping for {w.x}s') | ||
| await asyncio.sleep(w.x) | ||
| await bot.send_message(chat_id=Var.BIN_CHANNEL, | ||
| text=f"Gᴏᴛ FʟᴏᴏᴅWᴀɪᴛ ᴏғ {str(w.x)}s from {broadcast.chat.title}\n\n**Cʜᴀɴɴᴇʟ ID:** `{str(broadcast.chat.id)}`", | ||
| disable_web_page_preview=True, parse_mode="Markdown") | ||
| await bot.send_message( | ||
| chat_id=Var.BIN_CHANNEL, | ||
| text=f'Gᴏᴛ FʟᴏᴏᴅWᴀɪᴛ ᴏғ {w.x}s from {broadcast.chat.title}\n\n**Cʜᴀɴɴᴇʟ ID:** `{broadcast.chat.id}`', | ||
| disable_web_page_preview=True, | ||
| parse_mode="Markdown", | ||
| ) | ||
|
|
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 channel_receive_handler refactored with the following changes:
- Simplify unnecessary nesting, casting and constant values in f-strings (
simplify-fstring-formatting)
This removes the following comments ( why? ):
# [[InlineKeyboardButton("Dᴏᴡɴʟᴏᴀᴅ ʟɪɴᴋ 📥", url=f"https://t.me/FxStreamBot?start=AvishkarPatil_{str(log_msg.message_id)}")]])
# text=f"**Cʜᴀɴɴᴇʟ Nᴀᴍᴇ:** `{broadcast.chat.title}`\n**Cʜᴀɴɴᴇʟ ID:** `{broadcast.chat.id}`\n**Rᴇǫᴜᴇsᴛ ᴜʀʟ:** https://t.me/FxStreamBot?start=AvishkarPatil_{str(log_msg.message_id)}",
| file_name = file_properties.file_name if file_properties.file_name \ | ||
| else f"{secrets.token_hex(2)}.jpeg" | ||
| mime_type = file_properties.mime_type if file_properties.mime_type \ | ||
| else f"{mimetypes.guess_type(file_name)}" | ||
| file_name = file_properties.file_name or f"{secrets.token_hex(2)}.jpeg" | ||
| mime_type = file_properties.mime_type or f"{mimetypes.guess_type(file_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 media_streamer refactored with the following changes:
- Simplify if expression by using or (
or-if-exp-identity)
| error_message = "This message doesn't contain any downloadable media" | ||
| available_media = ("audio", "document", "photo", "sticker", "animation", "video", "voice", "video_note") | ||
|
|
||
| if isinstance(msg, Message): | ||
| error_message = "This message doesn't contain any downloadable media" |
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 TGCustomYield.generate_file_properties refactored with the following changes:
- Move assignments closer to their usage (
move-assign) - Replace if statement with if expression (
assign-if-exp)
| elif file_id.chat_access_hash == 0: | ||
| peer = raw.types.InputPeerChat( | ||
| chat_id=-file_id.chat_id | ||
| ) | ||
| else: | ||
| if file_id.chat_access_hash == 0: | ||
| peer = raw.types.InputPeerChat( | ||
| chat_id=-file_id.chat_id | ||
| ) | ||
| else: | ||
| peer = raw.types.InputPeerChannel( | ||
| channel_id=utils.get_channel_id(file_id.chat_id), | ||
| access_hash=file_id.chat_access_hash | ||
| ) | ||
| peer = raw.types.InputPeerChannel( | ||
| channel_id=utils.get_channel_id(file_id.chat_id), | ||
| access_hash=file_id.chat_access_hash | ||
| ) | ||
|
|
||
| location = raw.types.InputPeerPhotoFileLocation( | ||
| return raw.types.InputPeerPhotoFileLocation( | ||
| peer=peer, | ||
| volume_id=file_id.volume_id, | ||
| local_id=file_id.local_id, | ||
| big=file_id.thumbnail_source == ThumbnailSource.CHAT_PHOTO_BIG | ||
| ) | ||
| elif file_type == FileType.PHOTO: | ||
| location = raw.types.InputPhotoFileLocation( | ||
| return raw.types.InputPhotoFileLocation( | ||
| id=file_id.media_id, | ||
| access_hash=file_id.access_hash, | ||
| file_reference=file_id.file_reference, | ||
| thumb_size=file_id.thumbnail_size | ||
| ) | ||
| else: | ||
| location = raw.types.InputDocumentFileLocation( | ||
| return raw.types.InputDocumentFileLocation( | ||
| id=file_id.media_id, | ||
| access_hash=file_id.access_hash, | ||
| file_reference=file_id.file_reference, | ||
| thumb_size=file_id.thumbnail_size | ||
| ) | ||
|
|
||
| return location |
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 TGCustomYield.get_location refactored with the following changes:
- Lift return into if (
lift-return-into-if) - Merge else clause's nested if statement into elif (
merge-else-if-into-elif)
|
|
||
| current_part = 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 TGCustomYield.yield_file refactored with the following changes:
- Move assignments closer to their usage (
move-assign)
| async def is_user_exist(self, id): | ||
| user = await self.col.find_one({'id': int(id)}) | ||
| return True if user else False | ||
| return bool(user) |
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 Database.is_user_exist refactored with the following changes:
- Simplify boolean if expression (
boolean-if-exp-identity)
| async def get_all_users(self): | ||
| all_users = self.col.find({}) | ||
| return all_users | ||
| return self.col.find({}) |
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 Database.get_all_users refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
Branch
mainrefactored 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
mainbranch, then run:Help us improve this pull request!