Skip to content

Commit

Permalink
chore: small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
SantiiRepair committed Oct 12, 2023
1 parent c1cca6c commit c4766fc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
21 changes: 13 additions & 8 deletions bot/commands/play_song.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
@only_groups_or_channels
async def _(client: Client, message: Message):
data = await user_info(message.from_user)
file_name = f"/tmp/{str(uuid.uuid4())}.mp3"
if not message.reply_to_message and " " not in message.text:
return await message.reply(
"**__How to use this command.\n\nNext we show two ways to use this command, click on the button with the mode you are looking for to know details.__**",
Expand Down Expand Up @@ -107,13 +106,19 @@ async def _(client: Client, message: Message):
)
return await _message.pin()
if not message.reply_to_message.audio and not message.reply_to_message.voice:
return await message.reply(
"**__You need to reply to an audio file or a voice note, other files are not supported__**",
return await _message.edit(
"**__Reply to an audio file or a voice note.__**",
)
type_of = (
"Audio File"
if message.reply_to_message and message.reply_to_message.audio
else "Voice Note"
file_name = (
f"/tmp/{str(uuid.uuid4())}.{message.reply_to_message.audio.mime_type.split('/', 1)[1]}"
if message.reply_to_message.audio
else f"/tmp/{str(uuid.uuid4())}.mp3"
)
type_of = "Audio File" if message.reply_to_message.audio else "Voice Note"
duration = (
round((message.reply_to_message.audio.duration / 60), 2)
if message.reply_to_message.audio
else round((message.reply_to_message.voice.duration / 60), 2)
)
mention = (
f"https://t.me/c/{message.chat.id}/{message.reply_to_message.id}".replace(
Expand Down Expand Up @@ -148,7 +153,7 @@ async def _(client: Client, message: Message):

await _message.edit("💾 **__Downloading...__**")
media = await client.download_media(
message.reply_to_message.audio,
message.reply_to_message,
file_name=file_name,
progress=progress,
progress_args=(client, message.chat.id, _message.id),
Expand Down
17 changes: 5 additions & 12 deletions bot/helpers/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,21 @@ def bytes_to_string(byte_count):

async def progress(current_bytes, total_bytes, client, chat_id, message_id):
try:
percentage = current_bytes / total_bytes
print(percentage)
text = f"💾 **__Downloading...__** **{percentage:.2%}**"
if percentage >= randint(20, 30):
percentage = round(((current_bytes / total_bytes) * 100), 2)
text = f"💾 **__Downloading...__** **{percentage}%**"
if percentage >= 25 and percentage <= 35:
await client.edit_message_text(
chat_id=chat_id,
message_id=message_id,
text=text,
)
if percentage >= randint(50, 60):
if percentage >= 50 and percentage <= 60:
await client.edit_message_text(
chat_id=chat_id,
message_id=message_id,
text=text,
)
if percentage >= randint(70, 80):
await client.edit_message_text(
chat_id=chat_id,
message_id=message_id,
text=text,
)
if percentage >= randint(90, 100):
if percentage >= 90:
await client.edit_message_text(
chat_id=chat_id,
message_id=message_id,
Expand Down

0 comments on commit c4766fc

Please sign in to comment.