Fix timestamps being wrong

This commit is contained in:
Zeva Rose 2022-03-26 03:27:26 -06:00
parent 0c97e8096a
commit 5d3af23f0e
4 changed files with 21 additions and 14 deletions

View file

@ -2,7 +2,7 @@
import logging
import re
import traceback
from datetime import datetime
from datetime import datetime, timezone
from aiohttp import ClientSession
from dis_snek import Snake, listen
@ -104,7 +104,7 @@ class Jarvis(Snake):
return
guild = await self.fetch_guild(DEFAULT_GUILD)
channel = await guild.fetch_channel(DEFAULT_ERROR_CHANNEL)
error_time = datetime.utcnow().strftime("%d-%m-%Y %H:%M-%S.%f UTC")
error_time = datetime.now(tz=timezone.utc).strftime("%d-%m-%Y %H:%M-%S.%f UTC")
timestamp = int(datetime.now().timestamp())
timestamp = f"<t:{timestamp}:T>"
arg_str = ""
@ -124,18 +124,19 @@ class Jarvis(Snake):
callback_args=callback_args,
callback_kwargs=callback_kwargs,
)
if len(full_message) >= 1900:
error_message = " ".join(traceback.format_exception(error))
error_message = "".join(traceback.format_exception(error))
if len(full_message + error_message) >= 1800:
error_message = " ".join(error_message.split("\n"))
full_message += "Exception: |\n " + error_message
paste = Paste(content=full_message)
await paste.save(DEFAULT_SITE)
self.logger.debug(f"Large traceback, saved to Pasty {paste.id}")
await channel.send(
f"JARVIS encountered an error at {timestamp}. Log too big to send over Discord."
f"\nPlease see log at {paste.url}"
)
else:
error_message = "".join(traceback.format_exception(error))
await channel.send(
f"JARVIS encountered an error at {timestamp}:"
f"\n```yaml\n{full_message}\n```"

View file

@ -1,6 +1,6 @@
"""J.A.R.V.I.S. MuteCog."""
import logging
from datetime import datetime
from datetime import datetime, timedelta, timezone
from dis_snek import InteractionContext, Permissions, Snake
from dis_snek.models.discord.embed import EmbedField
@ -76,7 +76,8 @@ class MuteCog(ModcaseCog):
await ctx.send("Mute must be less than 4 weeks (2419200 seconds)", ephemeral=True)
return
await user.timeout(communication_disabled_until=duration, reason=reason)
until = datetime.now(tz=timezone.utc) + timedelta(minutes=duration)
await user.timeout(communication_disabled_until=until, reason=reason)
m = Mute(
user=user.id,
reason=reason,
@ -86,11 +87,15 @@ class MuteCog(ModcaseCog):
active=True,
)
await m.commit()
ts = int(until.timestamp())
embed = build_embed(
title="User Muted",
description=f"{user.mention} has been muted",
fields=[EmbedField(name="Reason", value=reason)],
fields=[
EmbedField(name="Reason", value=reason),
EmbedField(name="Until", value=f"<t:{ts}:F> <t:{ts}:R>"),
],
)
embed.set_author(name=user.display_name, icon_url=user.display_avatar.url)
embed.set_thumbnail(url=user.display_avatar.url)
@ -109,7 +114,8 @@ class MuteCog(ModcaseCog):
async def _unmute(self, ctx: InteractionContext, user: Member) -> None:
if (
not user.communication_disabled_until
or user.communication_disabled_until < datetime.now() # noqa: W503
or user.communication_disabled_until.timestamp()
< datetime.now(tz=timezone.utc).timestamp() # noqa: W503
):
await ctx.send("User is not muted", ephemeral=True)
return

View file

@ -2,7 +2,7 @@
import asyncio
import logging
import re
from datetime import datetime
from datetime import datetime, timezone
from typing import List
from bson import ObjectId
@ -126,13 +126,13 @@ class RemindmeCog(Scale):
)
return
if remind_at < datetime.utcnow():
if remind_at < datetime.now(tz=timezone.utc):
await response.send(
f"`{delay}` is in the past. Past reminders aren't allowed", ephemeral=True
)
return
elif remind_at < datetime.utcnow():
elif remind_at < datetime.now(tz=timezone.utc):
pass
r = Reminder(

View file

@ -1,5 +1,5 @@
"""Cog wrapper for command caching."""
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from dis_snek import Context, Scale, Snake
from dis_snek.client.utils.misc_utils import find
@ -35,7 +35,7 @@ class CacheCog(Scale):
async def _expire_interaction(self) -> None:
keys = list(self.cache.keys())
for key in keys:
if self.cache[key]["timeout"] <= datetime.utcnow() + timedelta(minutes=1):
if self.cache[key]["timeout"] <= datetime.now(tz=timezone.utc) + timedelta(minutes=1):
del self.cache[key]