Update utils.py

pull/41/head
Ndpropavel 2024-12-23 17:13:49 +05:00 committed by GitHub
parent 96352f2aef
commit 5764003655
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 26 additions and 4 deletions

View File

@ -1003,19 +1003,41 @@ def get_platform_emoji() -> str:
def uptime() -> int: def uptime() -> int:
""" """
Returns userbot uptime in seconds Returns userbot uptime in seconds
:return: Uptime in seconds
""" """
return round(time.perf_counter() - init_ts) current_uptime = round(time.perf_counter() - init_ts)
return current_uptime
def formatted_uptime() -> str: def formatted_uptime() -> str:
""" """
Returnes formmated uptime Returns formatted uptime including days if applicable.
:return: Formatted uptime :return: Formatted uptime
""" """
return str(timedelta(seconds=uptime())) total_seconds = uptime()
days, remainder = divmod(total_seconds, 86400)
time_formatted = str(timedelta(seconds=remainder))
if days > 0:
return f"{days} day(s), {time_formatted}"
return time_formatted
def add_uptime(minutes: int) -> None:
"""
Adds a custom uptime in minutes to the current uptime.
:param minutes: The custom uptime in minutes to add
"""
global init_ts
seconds = minutes * 60
init_ts -= seconds
def set_uptime(minutes: int) -> None:
"""
Sets a custom uptime in minutes. This will adjust the init_ts accordingly.
:param minutes: The custom uptime in minutes to set
"""
global init_ts
seconds = minutes * 60
init_ts = time.perf_counter() - seconds
def ascii_face() -> str: def ascii_face() -> str:
""" """
Returnes cute ASCII-art face Returnes cute ASCII-art face