Fix timestamps being wrong
This commit is contained in:
parent
0c97e8096a
commit
5d3af23f0e
4 changed files with 21 additions and 14 deletions
|
@ -2,7 +2,7 @@
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
import traceback
|
import traceback
|
||||||
from datetime import datetime
|
from datetime import datetime, timezone
|
||||||
|
|
||||||
from aiohttp import ClientSession
|
from aiohttp import ClientSession
|
||||||
from dis_snek import Snake, listen
|
from dis_snek import Snake, listen
|
||||||
|
@ -104,7 +104,7 @@ class Jarvis(Snake):
|
||||||
return
|
return
|
||||||
guild = await self.fetch_guild(DEFAULT_GUILD)
|
guild = await self.fetch_guild(DEFAULT_GUILD)
|
||||||
channel = await guild.fetch_channel(DEFAULT_ERROR_CHANNEL)
|
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 = int(datetime.now().timestamp())
|
||||||
timestamp = f"<t:{timestamp}:T>"
|
timestamp = f"<t:{timestamp}:T>"
|
||||||
arg_str = ""
|
arg_str = ""
|
||||||
|
@ -124,18 +124,19 @@ class Jarvis(Snake):
|
||||||
callback_args=callback_args,
|
callback_args=callback_args,
|
||||||
callback_kwargs=callback_kwargs,
|
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
|
full_message += "Exception: |\n " + error_message
|
||||||
paste = Paste(content=full_message)
|
paste = Paste(content=full_message)
|
||||||
await paste.save(DEFAULT_SITE)
|
await paste.save(DEFAULT_SITE)
|
||||||
|
self.logger.debug(f"Large traceback, saved to Pasty {paste.id}")
|
||||||
|
|
||||||
await channel.send(
|
await channel.send(
|
||||||
f"JARVIS encountered an error at {timestamp}. Log too big to send over Discord."
|
f"JARVIS encountered an error at {timestamp}. Log too big to send over Discord."
|
||||||
f"\nPlease see log at {paste.url}"
|
f"\nPlease see log at {paste.url}"
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
error_message = "".join(traceback.format_exception(error))
|
|
||||||
await channel.send(
|
await channel.send(
|
||||||
f"JARVIS encountered an error at {timestamp}:"
|
f"JARVIS encountered an error at {timestamp}:"
|
||||||
f"\n```yaml\n{full_message}\n```"
|
f"\n```yaml\n{full_message}\n```"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
"""J.A.R.V.I.S. MuteCog."""
|
"""J.A.R.V.I.S. MuteCog."""
|
||||||
import logging
|
import logging
|
||||||
from datetime import datetime
|
from datetime import datetime, timedelta, timezone
|
||||||
|
|
||||||
from dis_snek import InteractionContext, Permissions, Snake
|
from dis_snek import InteractionContext, Permissions, Snake
|
||||||
from dis_snek.models.discord.embed import EmbedField
|
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)
|
await ctx.send("Mute must be less than 4 weeks (2419200 seconds)", ephemeral=True)
|
||||||
return
|
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(
|
m = Mute(
|
||||||
user=user.id,
|
user=user.id,
|
||||||
reason=reason,
|
reason=reason,
|
||||||
|
@ -86,11 +87,15 @@ class MuteCog(ModcaseCog):
|
||||||
active=True,
|
active=True,
|
||||||
)
|
)
|
||||||
await m.commit()
|
await m.commit()
|
||||||
|
ts = int(until.timestamp())
|
||||||
|
|
||||||
embed = build_embed(
|
embed = build_embed(
|
||||||
title="User Muted",
|
title="User Muted",
|
||||||
description=f"{user.mention} has been 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_author(name=user.display_name, icon_url=user.display_avatar.url)
|
||||||
embed.set_thumbnail(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:
|
async def _unmute(self, ctx: InteractionContext, user: Member) -> None:
|
||||||
if (
|
if (
|
||||||
not user.communication_disabled_until
|
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)
|
await ctx.send("User is not muted", ephemeral=True)
|
||||||
return
|
return
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
from datetime import datetime
|
from datetime import datetime, timezone
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from bson import ObjectId
|
from bson import ObjectId
|
||||||
|
@ -126,13 +126,13 @@ class RemindmeCog(Scale):
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
if remind_at < datetime.utcnow():
|
if remind_at < datetime.now(tz=timezone.utc):
|
||||||
await response.send(
|
await response.send(
|
||||||
f"`{delay}` is in the past. Past reminders aren't allowed", ephemeral=True
|
f"`{delay}` is in the past. Past reminders aren't allowed", ephemeral=True
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
elif remind_at < datetime.utcnow():
|
elif remind_at < datetime.now(tz=timezone.utc):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
r = Reminder(
|
r = Reminder(
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
"""Cog wrapper for command caching."""
|
"""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 import Context, Scale, Snake
|
||||||
from dis_snek.client.utils.misc_utils import find
|
from dis_snek.client.utils.misc_utils import find
|
||||||
|
@ -35,7 +35,7 @@ class CacheCog(Scale):
|
||||||
async def _expire_interaction(self) -> None:
|
async def _expire_interaction(self) -> None:
|
||||||
keys = list(self.cache.keys())
|
keys = list(self.cache.keys())
|
||||||
for key in 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]
|
del self.cache[key]
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue