forked from swatv3nub/PyrogramBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathping.py
More file actions
71 lines (60 loc) · 2.17 KB
/
ping.py
File metadata and controls
71 lines (60 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from PyrogramBot import app, bot_start_time
from PyrogramBot.__main__ import BOT_DC_ID
from PyrogramBot.utils.errors import capture_err
from psutil import cpu_percent, virtual_memory, disk_usage, boot_time
from pyrogram import filters, __version__
from platform import python_version
import time
__MODULE__ = "Bot Status"
__HELP__ = "/ping - Check Bot Ping and Uptime\n/status - Check Bot Stats"
#Formatter
def get_readable_time(seconds: int) -> str:
count = 0
ping_time = ""
time_list = []
time_suffix_list = ["s", "m", "h", "days"]
while count < 4:
count += 1
if count < 3:
remainder, obtained = divmod(seconds, 60)
else:
remainder, obtained = divmod(seconds, 24)
if seconds == 0 and remainder == 0:
break
time_list.append(int(obtained))
seconds = int(remainder)
for i in range(len(time_list)):
time_list[i] = str(time_list[i]) + time_suffix_list[i]
if len(time_list) == 4:
ping_time += time_list.pop() + ", "
time_list.reverse()
ping_time += ":".join(time_list)
return ping_time
#Uptime
bot_uptime = int(time.time() - bot_start_time)
# Ping
@app.on_message(filters.command("ping"))
@capture_err
async def ping(_, message):
start_time = time.time()
pong = await message.reply_text("Calculating...")
end_time = time.time()
ping = round((end_time - start_time) * 1000, 3)
await pong.edit_text(
f"**Ping [DC-{BOT_DC_ID}]:** {ping}ms\n\n**Uptime:** {get_readable_time((bot_uptime))}.", parse_mode='markdown')
# System Info Example
@app.on_message(filters.command("status"))
@capture_err
async def status(_, message):
ram = virtual_memory().percent
cpu = cpu_percent().percent
disk = disk_usage("/").percent
text = "*>-------< System >-------<*\n\n"
text += f"Uptime: `{get_readable_time((bot_uptime))}`\n"
text += f"**CPU:** `{cpu}%`\n"
text += f"**RAM:** `{ram}%`\n"
text += f"**Disk:** `{disk}%`\n"
text += f"**Python Version:** `{python_version}`\n"
text += "**Library:** `Pyrogram`\n"
text += f"**Pyrogram Version:** `{__version__}`"
await message.reply_text(text, parse_mode="markdown")