From e38c08ab12fb5cf730dcb39180ed9ce034fa2ec0 Mon Sep 17 00:00:00 2001 From: Michael H Date: Sat, 28 Sep 2019 15:35:26 -0400 Subject: [PATCH] fix uptime for uptime of less than a second (#3009) * fix uptime for uptime of less than a second * changelog * More conclusive fix --- changelog.d/3008.bugfix.rst | 1 + redbot/core/core_commands.py | 5 +++-- redbot/core/global_checks.py | 10 +++++++++- 3 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 changelog.d/3008.bugfix.rst diff --git a/changelog.d/3008.bugfix.rst b/changelog.d/3008.bugfix.rst new file mode 100644 index 000000000..2df20bfaf --- /dev/null +++ b/changelog.d/3008.bugfix.rst @@ -0,0 +1 @@ +Uptime command works with uptimes of under a second \ No newline at end of file diff --git a/redbot/core/core_commands.py b/redbot/core/core_commands.py index 86278b297..a647e46c4 100644 --- a/redbot/core/core_commands.py +++ b/redbot/core/core_commands.py @@ -327,9 +327,10 @@ class Core(commands.Cog, CoreLogic): """Shows Red's uptime""" since = ctx.bot.uptime.strftime("%Y-%m-%d %H:%M:%S") delta = datetime.datetime.utcnow() - self.bot.uptime + uptime_str = humanize_timedelta(timedelta=delta) or _("Less than one second") await ctx.send( - _("Been up for: **{}** (since {} UTC)").format( - humanize_timedelta(timedelta=delta), since + _("Been up for: **{time_quantity}** (since {timestamp} UTC)").format( + time_quantity=uptime_str, timestamp=since ) ) diff --git a/redbot/core/global_checks.py b/redbot/core/global_checks.py index df4000f7a..1adbe76a4 100644 --- a/redbot/core/global_checks.py +++ b/redbot/core/global_checks.py @@ -3,11 +3,19 @@ from . import commands def init_global_checks(bot): + @bot.check_once + def actually_up(ctx): + """ + Uptime is set during the initial startup process. + If this hasn't been set, we should assume the bot isn't ready yet. + """ + return ctx.bot.uptime is not None + @bot.check_once async def whiteblacklist_checks(ctx): return await ctx.bot.allowed_by_whitelist_blacklist(ctx.author) @bot.check_once - async def bots(ctx): + def bots(ctx): """Check the user is not another bot.""" return not ctx.author.bot