Skip to content

Commit

Permalink
feat: switch to discord timestamps and drop humanize
Browse files Browse the repository at this point in the history
  • Loading branch information
onerandomusername committed Jan 24, 2022
1 parent 3190c8f commit eeb41e8
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 35 deletions.
2 changes: 1 addition & 1 deletion bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,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
Expand Down
7 changes: 2 additions & 5 deletions bot/exts/utils/bot_stats.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from datetime import datetime
from platform import python_version

import humanize
from disnake import Embed, __version__
from disnake.ext import commands

from bot.bot import Bot
from bot.constants import Colours
from bot.utils.time import TimeStampEnum, get_timestamp


class BotStats(commands.Cog):
Expand Down Expand Up @@ -35,9 +34,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(),
Expand Down
11 changes: 7 additions & 4 deletions bot/exts/utils/reminder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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."""
Expand Down Expand Up @@ -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,
),
),
)
Expand Down Expand Up @@ -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)
]
Expand Down
3 changes: 0 additions & 3 deletions bot/utils/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,3 @@ def get_timestamp(
`format` must be an enum member of TimeStampEnum. Default style is SHORT_DATE_TIME
"""
return f"<t:{int(timestamp.timestamp())}:{format.value}>"


get_discord_formatted_timestamp = get_timestamp
22 changes: 1 addition & 21 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ Pillow = "^9.0.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]
Expand Down

0 comments on commit eeb41e8

Please sign in to comment.