From 33f3888304cbc3651584bbd797067669d6c02063 Mon Sep 17 00:00:00 2001 From: "Konstantin O'D-D (xoreax)" <57073484+koyakonsta@users.noreply.github.com> Date: Thu, 1 Feb 2024 10:06:05 +0000 Subject: [PATCH 1/5] Merge /uptime fork into branch (#34) Co-authored-by: James Hackett --- src/extensions/uptime.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/extensions/uptime.py diff --git a/src/extensions/uptime.py b/src/extensions/uptime.py new file mode 100644 index 0000000..f137240 --- /dev/null +++ b/src/extensions/uptime.py @@ -0,0 +1,18 @@ +import time as t + +start_time = t.time() + +import arc +import hikari +import datetime as dt + +plugin = arc.GatewayPlugin("Blockbot Uptime") + +@plugin.include +@arc.slash_command("uptime", "Show formatted uptime of Blockbot") +async def uptime(ctx): + await ctx.respond(f"Uptime: **{dt.timedelta(seconds=t.time()-start_time)!s}**") + +@arc.loader +def loader(client): + client.add_plugin(plugin) From bec3143a7d1a73b67761b9ddf1e683c39e8a3d12 Mon Sep 17 00:00:00 2001 From: "Konstantin O'D-D (xoreax)" <57073484+koyakonsta@users.noreply.github.com> Date: Thu, 1 Feb 2024 11:21:15 +0100 Subject: [PATCH 2/5] Nobody likes microseconds {{{(>_<)}}} --- src/extensions/uptime.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/extensions/uptime.py b/src/extensions/uptime.py index f137240..bac83d9 100644 --- a/src/extensions/uptime.py +++ b/src/extensions/uptime.py @@ -11,7 +11,7 @@ @plugin.include @arc.slash_command("uptime", "Show formatted uptime of Blockbot") async def uptime(ctx): - await ctx.respond(f"Uptime: **{dt.timedelta(seconds=t.time()-start_time)!s}**") + await ctx.respond(f"Uptime: **{dt.timedelta(seconds=(t.time()-start_time) // 1)!s}**") @arc.loader def loader(client): From f1ce6f92d1707119e26d58369c25ac15e41a6cca Mon Sep 17 00:00:00 2001 From: Regaus <42419910+Regaus@users.noreply.github.com> Date: Thu, 1 Feb 2024 10:53:13 +0000 Subject: [PATCH 3/5] Add formatting of the timedelta to the uptime command (#36) Co-authored-by: nova <110734810+novanai@users.noreply.github.com> --- .gitignore | 1 + src/extensions/uptime.py | 14 ++++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 916db7b..f62cd07 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .vscode/ +.idea/ # Byte-compiled / optimized / DLL files __pycache__/ diff --git a/src/extensions/uptime.py b/src/extensions/uptime.py index bac83d9..87a9cb7 100644 --- a/src/extensions/uptime.py +++ b/src/extensions/uptime.py @@ -1,17 +1,19 @@ -import time as t - -start_time = t.time() +from datetime import datetime import arc -import hikari -import datetime as dt + +start_time = datetime.now() plugin = arc.GatewayPlugin("Blockbot Uptime") + @plugin.include @arc.slash_command("uptime", "Show formatted uptime of Blockbot") async def uptime(ctx): - await ctx.respond(f"Uptime: **{dt.timedelta(seconds=(t.time()-start_time) // 1)!s}**") + up_time = datetime.now() - start_time + h, ms = divmod(up_time.seconds, 3600) + m, s = divmod(ms, 60) + await ctx.respond(f"Uptime: **{up_time.days} days, {h} hours, {m} minutes, and {s} seconds**.") @arc.loader def loader(client): From fc87f077b4d8cacb27ed423525133f272d6dcf33 Mon Sep 17 00:00:00 2001 From: "Konstantin O'D-D (xoreax)" <57073484+koyakonsta@users.noreply.github.com> Date: Thu, 1 Feb 2024 23:14:49 +0100 Subject: [PATCH 4/5] remove empty line Co-authored-by: Jed Hazaymeh --- src/extensions/uptime.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/extensions/uptime.py b/src/extensions/uptime.py index 87a9cb7..7ac005b 100644 --- a/src/extensions/uptime.py +++ b/src/extensions/uptime.py @@ -6,7 +6,6 @@ plugin = arc.GatewayPlugin("Blockbot Uptime") - @plugin.include @arc.slash_command("uptime", "Show formatted uptime of Blockbot") async def uptime(ctx): From 67268443293f92bc23d035a918940d2b8e4c7983 Mon Sep 17 00:00:00 2001 From: "Konstantin O'D-D (xoreax)" <57073484+koyakonsta@users.noreply.github.com> Date: Fri, 2 Feb 2024 00:54:26 +0100 Subject: [PATCH 5/5] /uptime timestamp string formatting update Co-authored-by: Jed Hazaymeh --- src/extensions/uptime.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/extensions/uptime.py b/src/extensions/uptime.py index 7ac005b..45ddb4d 100644 --- a/src/extensions/uptime.py +++ b/src/extensions/uptime.py @@ -10,9 +10,15 @@ @arc.slash_command("uptime", "Show formatted uptime of Blockbot") async def uptime(ctx): up_time = datetime.now() - start_time + d = up_time.days h, ms = divmod(up_time.seconds, 3600) m, s = divmod(ms, 60) - await ctx.respond(f"Uptime: **{up_time.days} days, {h} hours, {m} minutes, and {s} seconds**.") + + format = lambda val, str: f"{val} {str}{'s' if val != 1 else ''}" + message_parts = [(d, "day"), (h, "hour"), (m, "minute"), (s, "second")] + formatted_parts = [format(val, str) for val, str in message_parts if val] + + await ctx.respond(f"Uptime: **{', '.join(formatted_parts)}**") @arc.loader def loader(client):