fix(aurora): fixed the changes_factory

This commit is contained in:
Seaswimmer 2024-05-04 21:15:39 -04:00
parent ee331b7544
commit 94f6d6c3b5
Signed by untrusted user: cswimr
GPG key ID: 5D671B5D03D65A7F
2 changed files with 28 additions and 24 deletions

View file

@ -106,6 +106,10 @@ class Change(AuroraBaseModel):
duration: Optional[timedelta] = None
end_timestamp: Optional[datetime] = None
@property
def unix_timestamp(self) -> int:
return int(self.timestamp.timestamp())
def __str__(self):
return f"{self.type} {self.user_id} {self.reason}"
@ -114,6 +118,16 @@ class Change(AuroraBaseModel):
@classmethod
def from_dict(cls, bot: Red, data: dict) -> "Change":
if data["duration"] is not None:
hours, minutes, seconds = map(int, data["duration"].split(':'))
duration = timedelta(hours=hours, minutes=minutes, seconds=seconds)
else:
duration = None
data.update({
"timestamp": datetime.fromtimestamp(data["timestamp"]),
"end_timestamp": datetime.fromtimestamp(data["end_timestamp"]) if data["end_timestamp"] else None,
"duration": duration
})
return cls(bot=bot, **data)
class PartialUser(AuroraBaseModel):

View file

@ -2,17 +2,13 @@
from datetime import datetime, timedelta
from typing import Union
from discord import (Color, Embed, Guild, Interaction, InteractionMessage,
Member, Role, User)
from discord import Color, Embed, Guild, Interaction, InteractionMessage, Member, Role, User
from redbot.core import commands
from redbot.core.utils.chat_formatting import (bold, box, error,
humanize_timedelta, warning)
from redbot.core.utils.chat_formatting import bold, box, error, humanize_timedelta, warning
from aurora.models import Moderation
from aurora.utilities.config import config
from aurora.utilities.utils import (fetch_channel_dict, fetch_user_dict,
get_bool_emoji, get_next_case_number,
get_pagesize_str)
from aurora.utilities.utils import fetch_channel_dict, fetch_user_dict, get_bool_emoji, get_next_case_number, get_pagesize_str
async def message_factory(
@ -228,38 +224,32 @@ async def changes_factory(interaction: Interaction, moderation: Moderation) -> E
if moderation.changes:
for change in moderation.changes:
if change["user_id"] not in memory_dict:
memory_dict[str(change["user_id"])] = await fetch_user_dict(
interaction.client, change["user_id"]
)
if change.user_id not in memory_dict:
memory_dict[str(change.user_id)] = await change.get_user()
user = memory_dict[str(change["user_id"])]
name = (
user["name"]
if user["discriminator"] == "0"
else f"{user['name']}#{user['discriminator']}"
)
user = memory_dict[str(change.user_id)]
name = user["name"]
timestamp = f"<t:{change['timestamp']}> | <t:{change['timestamp']}:R>"
timestamp = f"<t:{change.unix_timestamp}> | <t:{change.unix_timestamp}:R>"
if change["type"] == "ORIGINAL":
if change.type == "ORIGINAL":
embed.add_field(
name="Original",
value=f"**User:** `{name}` ({user['id']})\n**Reason:** {change['reason']}\n**Timestamp:** {timestamp}",
value=f"**User:** `{name}` ({user['id']})\n**Reason:** {change.reason}\n**Timestamp:** {timestamp}",
inline=False,
)
elif change["type"] == "EDIT":
elif change.type == "EDIT":
embed.add_field(
name="Edit",
value=f"**User:** `{name}` ({user['id']})\n**Reason:** {change['reason']}\n**Timestamp:** {timestamp}",
value=f"**User:** `{name}` ({user['id']})\n**Reason:** {change.reason}\n**Timestamp:** {timestamp}",
inline=False,
)
elif change["type"] == "RESOLVE":
elif change.type == "RESOLVE":
embed.add_field(
name="Resolve",
value=f"**User:** `{name}` ({user['id']})\n**Reason:** {change['reason']}\n**Timestamp:** {timestamp}",
value=f"**User:** `{name}` ({user['id']})\n**Reason:** {change.reason}\n**Timestamp:** {timestamp}",
inline=False,
)