mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 03:08:55 -05:00
[core_commands] Using humanize_timedelta for [p]uptime command (#2735)
* Update core_commands.py
This commit is contained in:
parent
132545e057
commit
b4f4e080af
@ -33,7 +33,7 @@ from redbot.core import (
|
|||||||
i18n,
|
i18n,
|
||||||
)
|
)
|
||||||
from .utils.predicates import MessagePredicate
|
from .utils.predicates import MessagePredicate
|
||||||
from .utils.chat_formatting import pagify, box, inline
|
from .utils.chat_formatting import humanize_timedelta, pagify, box, inline
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from redbot.core.bot import Red
|
from redbot.core.bot import Red
|
||||||
@ -333,28 +333,12 @@ class Core(commands.Cog, CoreLogic):
|
|||||||
async def uptime(self, ctx: commands.Context):
|
async def uptime(self, ctx: commands.Context):
|
||||||
"""Shows Red's uptime"""
|
"""Shows Red's uptime"""
|
||||||
since = ctx.bot.uptime.strftime("%Y-%m-%d %H:%M:%S")
|
since = ctx.bot.uptime.strftime("%Y-%m-%d %H:%M:%S")
|
||||||
passed = self.get_bot_uptime()
|
delta = datetime.datetime.utcnow() - self.bot.uptime
|
||||||
await ctx.send(_("Been up for: **{}** (since {} UTC)").format(passed, since))
|
await ctx.send(
|
||||||
|
_("Been up for: **{}** (since {} UTC)").format(
|
||||||
def get_bot_uptime(self, *, brief: bool = False):
|
humanize_timedelta(timedelta=delta), since
|
||||||
# Courtesy of Danny
|
)
|
||||||
now = datetime.datetime.utcnow()
|
)
|
||||||
delta = now - self.bot.uptime
|
|
||||||
hours, remainder = divmod(int(delta.total_seconds()), 3600)
|
|
||||||
minutes, seconds = divmod(remainder, 60)
|
|
||||||
days, hours = divmod(hours, 24)
|
|
||||||
|
|
||||||
if not brief:
|
|
||||||
if days:
|
|
||||||
fmt = _("{d} days, {h} hours, {m} minutes, and {s} seconds")
|
|
||||||
else:
|
|
||||||
fmt = _("{h} hours, {m} minutes, and {s} seconds")
|
|
||||||
else:
|
|
||||||
fmt = _("{h}h {m}m {s}s")
|
|
||||||
if days:
|
|
||||||
fmt = _("{d}d ") + fmt
|
|
||||||
|
|
||||||
return fmt.format(d=days, h=hours, m=minutes, s=seconds)
|
|
||||||
|
|
||||||
@commands.group()
|
@commands.group()
|
||||||
async def embedset(self, ctx: commands.Context):
|
async def embedset(self, ctx: commands.Context):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user