From 0588f225044b56547887c658aa62f2d844072aee Mon Sep 17 00:00:00 2001 From: onerandomusername Date: Thu, 16 Dec 2021 23:25:37 -0500 Subject: [PATCH] feat: switch to discord timestamps and drop humanize --- bot/bot.py | 2 +- bot/exts/utils/bot_stats.py | 9 ++++----- bot/exts/utils/reminder.py | 11 +++++++---- bot/utils/time.py | 3 --- poetry.lock | 22 +--------------------- pyproject.toml | 1 - 6 files changed, 13 insertions(+), 35 deletions(-) diff --git a/bot/bot.py b/bot/bot.py index 22f25afa..09f28329 100644 --- a/bot/bot.py +++ b/bot/bot.py @@ -45,7 +45,7 @@ def __init__(self) -> None: self.loop.create_task(self._db_setup()) - self.launch_time = datetime.utcnow().timestamp() + self.launch_time = datetime.utcnow() async def notify_dev_alert( self, content: Optional[str] = None, embed: Optional[Embed] = None diff --git a/bot/exts/utils/bot_stats.py b/bot/exts/utils/bot_stats.py index 81c78afd..d08eced5 100644 --- a/bot/exts/utils/bot_stats.py +++ b/bot/exts/utils/bot_stats.py @@ -1,7 +1,8 @@ -from datetime import datetime from platform import python_version -import humanize +from bot.bot import Bot +from bot.constants import Colours +from bot.utils.time import TimeStampEnum, get_timestamp from disnake import Embed, __version__ from disnake.ext import commands @@ -35,9 +36,7 @@ async def stats(self, ctx: commands.Context) -> None: embed.set_thumbnail(url=self.bot.user.display_avatar.url) - uptime = humanize.precisedelta( - datetime.utcnow().timestamp() - self.bot.launch_time - ) + uptime = get_timestamp(self.bot.launch_time, format=TimeStampEnum.RELATIVE_TIME) fields = { "Python version": python_version(), diff --git a/bot/exts/utils/reminder.py b/bot/exts/utils/reminder.py index 065fef76..724628e5 100644 --- a/bot/exts/utils/reminder.py +++ b/bot/exts/utils/reminder.py @@ -5,7 +5,6 @@ from typing import Optional, Union import disnake -import humanize from asyncpg import Record from disnake import Embed from disnake.ext.commands import Cog, Context, group @@ -14,11 +13,14 @@ from bot.bot import Bot from bot.constants import Colours from bot.postgres.utils import db_execute, db_fetch +from bot.utils import time from bot.utils.pagination import LinePaginator from bot.utils.parsers import parse_duration REMINDER_DESCRIPTION = "**Arrives in**: {arrive_in}\n" +TIMESTAMP_FORMAT = time.TimeStampEnum.RELATIVE_TIME + class Reminder(Cog): """Reminder for events, tasks, etc.""" @@ -159,8 +161,9 @@ async def append_reminder( title=":white_check_mark: Reminder set", color=Colours.green, description=REMINDER_DESCRIPTION.format( - arrive_in=humanize.precisedelta( - timestamp - datetime.utcnow(), format="%0.0f" + arrive_in=time.get_timestamp( + timestamp, + format=TIMESTAMP_FORMAT, ), ), ) @@ -197,7 +200,7 @@ async def list_reminders(self, ctx: Context) -> None: ] lines = [ - f"**Arrives in {humanize.precisedelta(reminder['end_time'] - datetime.utcnow(), format='%0.0f')}" + f"**Arrives in {time.get_timestamp(reminder['end_time'], format=TIMESTAMP_FORMAT)}**" f"** (ID: {reminder['reminder_id']})\n{reminder['content']}\n" for i, reminder in enumerate(reminders, start=1) ] diff --git a/bot/utils/time.py b/bot/utils/time.py index b3413174..1838ddf1 100644 --- a/bot/utils/time.py +++ b/bot/utils/time.py @@ -59,6 +59,3 @@ def get_timestamp( `format` must be an enum member of TimeStampEnum. Default style is SHORT_DATE_TIME """ return f"" - - -get_discord_formatted_timestamp = get_timestamp diff --git a/poetry.lock b/poetry.lock index c34fe377..f4821f62 100644 --- a/poetry.lock +++ b/poetry.lock @@ -310,17 +310,6 @@ python-versions = "*" [package.extras] speedup = ["python-levenshtein (>=0.12)"] -[[package]] -name = "humanize" -version = "3.13.1" -description = "Python humanize utilities" -category = "main" -optional = false -python-versions = ">=3.6" - -[package.extras] -tests = ["freezegun", "pytest", "pytest-cov"] - [[package]] name = "identify" version = "2.4.2" @@ -663,7 +652,7 @@ multidict = ">=4.0" [metadata] lock-version = "1.1" python-versions = "^3.9.0" -content-hash = "4f1816e80f1e4f41f3d239900f125bd78ab185b61edb2961853f6d58494c1ee2" +content-hash = "9aeba7b282dfa4d6a107a7c5c9a7163d7d58d82492f9f396da4bceb9fecb7c63" [metadata.files] aiohttp = [ @@ -918,10 +907,6 @@ fuzzywuzzy = [ {file = "fuzzywuzzy-0.18.0-py2.py3-none-any.whl", hash = "sha256:928244b28db720d1e0ee7587acf660ea49d7e4c632569cad4f1cd7e68a5f0993"}, {file = "fuzzywuzzy-0.18.0.tar.gz", hash = "sha256:45016e92264780e58972dca1b3d939ac864b78437422beecebb3095f8efd00e8"}, ] -humanize = [ - {file = "humanize-3.13.1-py3-none-any.whl", hash = "sha256:a6f7cc1597db69a4e571ad5e19b4da07ee871da5a9de2b233dbfab02d98e9754"}, - {file = "humanize-3.13.1.tar.gz", hash = "sha256:12f113f2e369dac7f35d3823f49262934f4a22a53a6d3d4c86b736f50db88c7b"}, -] identify = [ {file = "identify-2.4.2-py2.py3-none-any.whl", hash = "sha256:67c1e66225870dce721228176637a8ef965e8dd58450bcc7592249d0dfc4da6c"}, {file = "identify-2.4.2.tar.gz", hash = "sha256:93e8ec965e888f2212aa5c24b2b662f4832c39acb1d7196a70ea45acb626a05e"}, @@ -1103,11 +1088,6 @@ psutil = [ {file = "psutil-5.9.0-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:742c34fff804f34f62659279ed5c5b723bb0195e9d7bd9907591de9f8f6558e2"}, {file = "psutil-5.9.0-cp310-cp310-win32.whl", hash = "sha256:8293942e4ce0c5689821f65ce6522ce4786d02af57f13c0195b40e1edb1db61d"}, {file = "psutil-5.9.0-cp310-cp310-win_amd64.whl", hash = "sha256:9b51917c1af3fa35a3f2dabd7ba96a2a4f19df3dec911da73875e1edaf22a40b"}, - {file = "psutil-5.9.0-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:e9805fed4f2a81de98ae5fe38b75a74c6e6ad2df8a5c479594c7629a1fe35f56"}, - {file = "psutil-5.9.0-cp36-cp36m-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:c51f1af02334e4b516ec221ee26b8fdf105032418ca5a5ab9737e8c87dafe203"}, - {file = "psutil-5.9.0-cp36-cp36m-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:32acf55cb9a8cbfb29167cd005951df81b567099295291bcfd1027365b36591d"}, - {file = "psutil-5.9.0-cp36-cp36m-win32.whl", hash = "sha256:e5c783d0b1ad6ca8a5d3e7b680468c9c926b804be83a3a8e95141b05c39c9f64"}, - {file = "psutil-5.9.0-cp36-cp36m-win_amd64.whl", hash = "sha256:d62a2796e08dd024b8179bd441cb714e0f81226c352c802fca0fd3f89eeacd94"}, {file = "psutil-5.9.0-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:3d00a664e31921009a84367266b35ba0aac04a2a6cad09c550a89041034d19a0"}, {file = "psutil-5.9.0-cp37-cp37m-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:7779be4025c540d1d65a2de3f30caeacc49ae7a2152108adeaf42c7534a115ce"}, {file = "psutil-5.9.0-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:072664401ae6e7c1bfb878c65d7282d4b4391f1bc9a56d5e03b5a490403271b5"}, diff --git a/pyproject.toml b/pyproject.toml index 274e0ea3..60e5cd53 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,7 +20,6 @@ Pillow = "^8.2.0" fuzzywuzzy = "^0.18.0" asyncpg = "^0.23.0" python-dateutil = "^2.8.2" -humanize = "^3.11.0" mcstatus = "^6.5.0" [tool.poetry.dev-dependencies]