Skip to content

Commit

Permalink
chore: small change
Browse files Browse the repository at this point in the history
  • Loading branch information
SantiiRepair committed Oct 12, 2023
1 parent 60daa80 commit 92abff9
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .vm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fi

CHROME_PATH=$(which google-chrome 2>&1)

if ! [ -x $CHROME_PATH ]; then
if ! [ -x $CHROME_PATH || -z $CHROME_PATH ]; then
wget -O /tmp/google-chrome-stable_current_amd64.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i /tmp/google-chrome-stable_current_amd64.deb; sudo apt-get -fy install
rm -rf /tmp/google-chrome-stable_current_amd64.deb
Expand Down
2 changes: 1 addition & 1 deletion bot/commands/play_book.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async def _(client: Client, message: Message):
f = await message.reply_to_message.download(
file_name=file_name,
progress=progress,
progress_args=(client, message.chat.id, _message),
progress_args=(client, message.chat.id, _message.id),
)

if " " not in message.text and file_type == "pdf":
Expand Down
4 changes: 2 additions & 2 deletions bot/commands/play_song.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ async def _(client: Client, message: Message):
message.reply_to_message.audio,
file_name=file_name,
progress=progress,
progress_args=(client, message.chat.id, _message),
progress_args=(client, message.chat.id, _message.id),
)
elif message.reply_to_message and message.reply_to_message.voice:
name = "Voice Note"
Expand All @@ -174,7 +174,7 @@ async def _(client: Client, message: Message):
message.reply_to_message.voice,
file_name=file_name,
progress=progress,
progress_args=(client, message.chat.id, _message),
progress_args=(client, message.chat.id, _message.id),
)
if VOICE_CHATS.get(message.chat.id) is None:
await _message.edit("🪄 **__Joining the voice chat...__**")
Expand Down
2 changes: 1 addition & 1 deletion bot/commands/play_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ async def _(client: Client, message: Message):
message.reply_to_message.video,
file_name=file_name,
progress=progress,
progress_args=(client, message.chat.id, _message),
progress_args=(client, message.chat.id, _message.id),
)
if str(message.chat.id) in get_queues():
position = get_last_position_in_queue(str(message.chat.id)) + 1
Expand Down
4 changes: 2 additions & 2 deletions bot/commands/streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ async def _(client: Client, message: Message):
media["file_id"],
file_name=serie_name,
progress=progress,
progress_args=(client, message.chat.id, _message),
progress_args=(client, message.chat.id, _message.id),
)
if media["type"] == "movie":
video = await assistant.download_media(
media["file_id"],
file_name=movie_name,
progress=progress,
progress_args=(client, message.chat.id, _message),
progress_args=(client, message.chat.id, _message.id),
)
if VOICE_CHATS.get(message.chat.id) is None:
await _message.edit("🪄 **__Joining the voice chat...__**")
Expand Down
37 changes: 29 additions & 8 deletions bot/helpers/progress.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging

from random import randint

def bytes_to_string(byte_count):
"""Converts a byte count to a string (in KB, MB...)"""
Expand All @@ -13,13 +13,34 @@ def bytes_to_string(byte_count):
)


async def progress(current_bytes, total_bytes, client, chat_id, _message):
async def progress(current_bytes, total_bytes, client, chat_id, message_id):
try:
await client.edit_message_text(
chat_id=chat_id,
message_id=_message.id,
text=f"💾 **__Downloading...__** **{(current_bytes / total_bytes):.2%}**",
)

percentage = current_bytes / total_bytes
print(percentage)
text = f"💾 **__Downloading...__** **{percentage:.2%}**"
if percentage >= randint(20, 30):
await client.edit_message_text(
chat_id=chat_id,
message_id=message_id,
text=text,
)
if percentage >= randint(50, 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):
await client.edit_message_text(
chat_id=chat_id,
message_id=message_id,
text=text,
)
except Exception as err:
logging.error(err)

0 comments on commit 92abff9

Please sign in to comment.