misc(moderation): improved timestamp formatting in embeds and response messages
All checks were successful
Pylint / Pylint (push) Successful in 1m11s

This commit is contained in:
Seaswimmer 2023-10-04 13:11:18 -04:00
parent 98f91b8ba3
commit a9ec5044a2
No known key found for this signature in database
GPG key ID: 5019678FD9CF50D8
3 changed files with 21 additions and 4 deletions

View file

@ -1,11 +1,13 @@
from datetime import datetime, timedelta, timezone
import logging
import time
from datetime import datetime, timedelta, timezone
import discord
import humanize
import mysql.connector
from pytimeparse2 import disable_dateutil, parse
from redbot.core import Config, checks, commands
class Moderation(commands.Cog):
"""Custom cog moderation cog, meant to copy GalacticBot.
Developed by SeaswimmerTheFsh."""
@ -182,9 +184,9 @@ class Moderation(commands.Cog):
await ctx.message.reply(f"Please provide a valid duration!\nSee `{ctx.prefix}tdc`")
return
await target.timeout(parsed_time)
response = await ctx.send(content=f"{target.mention} has been muted for {str(parsed_time)}!\n**Reason** - `{reason}`")
response = await ctx.send(content=f"{target.mention} has been muted for {humanize.precisedelta(parsed_time)}!\n**Reason** - `{reason}`")
try:
embed = discord.Embed(title="Muted", description=f"You have been muted for `{str(parsed_time)}` in [{ctx.guild.name}]({response.jump_url}).", color=await self.bot.get_embed_color(None))
embed = discord.Embed(title="Muted", description=f"You have been muted for `{humanize.precisedelta(parsed_time)}` in [{ctx.guild.name}]({response.jump_url}).", color=await self.bot.get_embed_color(None))
embed.add_field(name='Reason', value=f"`{reason}`")
await target.send(embed=embed)
except discord.errors.HTTPException:

16
poetry.lock generated
View file

@ -805,6 +805,20 @@ cli = ["click (==8.*)", "pygments (==2.*)", "rich (>=10,<14)"]
http2 = ["h2 (>=3,<5)"]
socks = ["socksio (==1.*)"]
[[package]]
name = "humanize"
version = "4.8.0"
description = "Python humanize utilities"
optional = false
python-versions = ">=3.8"
files = [
{file = "humanize-4.8.0-py3-none-any.whl", hash = "sha256:8bc9e2bb9315e61ec06bf690151ae35aeb65651ab091266941edf97c90836404"},
{file = "humanize-4.8.0.tar.gz", hash = "sha256:9783373bf1eec713a770ecaa7c2d7a7902c98398009dfa3d8a2df91eec9311e8"},
]
[package.extras]
tests = ["freezegun", "pytest", "pytest-cov"]
[[package]]
name = "idna"
version = "3.4"
@ -2407,4 +2421,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p
[metadata]
lock-version = "2.0"
python-versions = ">=3.11,<3.12"
content-hash = "08f482e464da76e9f2720b46520c5a93c8fe5c7d8ecd8c894ccc5be9416f7d30"
content-hash = "ba518ebf98dfa9fbbbc3c9acbbde5916796d7aafde79d455e13eb5ef46089717"

View file

@ -13,6 +13,7 @@ pytimeparse2 = "^1.7.1"
yt-dlp = "^2023.9.24"
prisma = "^0.10.0"
mysql-connector-python = "^8.1.0"
humanize = "^4.8.0"
[tool.poetry.group.dev]
optional = true