Skip to content

Conversation

@sourcery-ai
Copy link

@sourcery-ai sourcery-ai bot commented Jan 29, 2022

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 AmirulAndalib January 29, 2022 03:59
Comment on lines -9 to +11
class Var(object):


class Var((object)):
Copy link
Author

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:

Comment on lines -31 to +37
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.'
)

Copy link
Author

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:

Comment on lines -96 to +103
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",
)
Copy link
Author

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:

Comment on lines -113 to +147
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",
)

Copy link
Author

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:

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)}",

Comment on lines -60 to +61
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)}"
Copy link
Author

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:

Comment on lines -33 to +36
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"
Copy link
Author

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:

Comment on lines +112 to -148
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
Copy link
Author

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:

Comment on lines 148 to -156

current_part = 1
Copy link
Author

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:

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)
Copy link
Author

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:

async def get_all_users(self):
all_users = self.col.find({})
return all_users
return self.col.find({})
Copy link
Author

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:

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant