From 57640036558915a163411866879071743aa2a337 Mon Sep 17 00:00:00 2001 From: Ndpropavel <141354293+Ndpropavel@users.noreply.github.com> Date: Mon, 23 Dec 2024 17:13:49 +0500 Subject: [PATCH] Update utils.py --- hikka/utils.py | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/hikka/utils.py b/hikka/utils.py index 0f7f0c1..608b830 100644 --- a/hikka/utils.py +++ b/hikka/utils.py @@ -1003,19 +1003,41 @@ def get_platform_emoji() -> str: def uptime() -> int: """ 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: """ - Returnes formmated uptime + Returns formatted uptime including days if applicable. :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: """ Returnes cute ASCII-art face