1
1
from telegram import InlineKeyboardMarkup
2
2
from telegram .message import Message
3
3
from telegram .update import Update
4
+ import psutil
4
5
import time
5
6
from bot import AUTO_DELETE_MESSAGE_DURATION , LOGGER , bot , \
6
- status_reply_dict , status_reply_dict_lock
7
- from bot .helper .ext_utils .bot_utils import get_readable_message
7
+ status_reply_dict , status_reply_dict_lock , download_dict , download_dict_lock
8
+ from bot .helper .ext_utils .bot_utils import get_readable_message , get_readable_file_size , MirrorStatus
8
9
from telegram .error import TimedOut , BadRequest
9
- from bot import bot
10
10
11
11
12
12
def sendMessage (text : str , bot , update : Update ):
@@ -68,6 +68,27 @@ def delete_all_messages():
68
68
69
69
def update_all_messages ():
70
70
msg = get_readable_message ()
71
+ msg += f"<b>CPU:</b> { psutil .cpu_percent ()} %" \
72
+ f" <b>DISK:</b> { psutil .disk_usage ('/' ).percent } %" \
73
+ f" <b>RAM:</b> { psutil .virtual_memory ().percent } %"
74
+ with download_dict_lock :
75
+ dlspeed_bytes = 0
76
+ uldl_bytes = 0
77
+ for download in list (download_dict .values ()):
78
+ speedy = download .speed ()
79
+ if download .status () == MirrorStatus .STATUS_DOWNLOADING :
80
+ if 'KiB/s' in speedy :
81
+ dlspeed_bytes += float (speedy .split ('K' )[0 ]) * 1024
82
+ elif 'MiB/s' in speedy :
83
+ dlspeed_bytes += float (speedy .split ('M' )[0 ]) * 1048576
84
+ if download .status () == MirrorStatus .STATUS_UPLOADING :
85
+ if 'KB/s' in speedy :
86
+ uldl_bytes += float (speedy .split ('K' )[0 ]) * 1024
87
+ elif 'MB/s' in speedy :
88
+ uldl_bytes += float (speedy .split ('M' )[0 ]) * 1048576
89
+ dlspeed = get_readable_file_size (dlspeed_bytes )
90
+ ulspeed = get_readable_file_size (uldl_bytes )
91
+ msg += f"\n <b>DL:</b>{ dlspeed } ps 🔻| <b>UL:</b>{ ulspeed } ps 🔺\n "
71
92
with status_reply_dict_lock :
72
93
for chat_id in list (status_reply_dict .keys ()):
73
94
if status_reply_dict [chat_id ] and msg != status_reply_dict [chat_id ].text :
@@ -83,6 +104,27 @@ def update_all_messages():
83
104
84
105
def sendStatusMessage (msg , bot ):
85
106
progress = get_readable_message ()
107
+ progress += f"<b>CPU:</b> { psutil .cpu_percent ()} %" \
108
+ f" <b>DISK:</b> { psutil .disk_usage ('/' ).percent } %" \
109
+ f" <b>RAM:</b> { psutil .virtual_memory ().percent } %"
110
+ with download_dict_lock :
111
+ dlspeed_bytes = 0
112
+ uldl_bytes = 0
113
+ for download in list (download_dict .values ()):
114
+ speedy = download .speed ()
115
+ if download .status () == MirrorStatus .STATUS_DOWNLOADING :
116
+ if 'KiB/s' in speedy :
117
+ dlspeed_bytes += float (speedy .split ('K' )[0 ]) * 1024
118
+ elif 'MiB/s' in speedy :
119
+ dlspeed_bytes += float (speedy .split ('M' )[0 ]) * 1048576
120
+ if download .status () == MirrorStatus .STATUS_UPLOADING :
121
+ if 'KB/s' in speedy :
122
+ uldl_bytes += float (speedy .split ('K' )[0 ]) * 1024
123
+ elif 'MB/s' in speedy :
124
+ uldl_bytes += float (speedy .split ('M' )[0 ]) * 1048576
125
+ dlspeed = get_readable_file_size (dlspeed_bytes )
126
+ ulspeed = get_readable_file_size (uldl_bytes )
127
+ progress += f"\n <b>DL:</b>{ dlspeed } ps 🔻| <b>UL:</b>{ ulspeed } ps 🔺\n "
86
128
with status_reply_dict_lock :
87
129
if msg .message .chat .id in list (status_reply_dict .keys ()):
88
130
try :
0 commit comments