WIP: Refactor Aurora (3.0.0) #29

Draft
cswimr wants to merge 347 commits from aurora-pydantic into main
2 changed files with 28 additions and 24 deletions
Showing only changes of commit 94f6d6c3b5 - Show all commits

View file

@ -106,6 +106,10 @@ class Change(AuroraBaseModel):
duration: Optional[timedelta] = None duration: Optional[timedelta] = None
end_timestamp: Optional[datetime] = None end_timestamp: Optional[datetime] = None
@property
def unix_timestamp(self) -> int:
return int(self.timestamp.timestamp())
def __str__(self): def __str__(self):
return f"{self.type} {self.user_id} {self.reason}" return f"{self.type} {self.user_id} {self.reason}"
@ -114,6 +118,16 @@ class Change(AuroraBaseModel):
@classmethod @classmethod
def from_dict(cls, bot: Red, data: dict) -> "Change": 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) return cls(bot=bot, **data)
class PartialUser(AuroraBaseModel): class PartialUser(AuroraBaseModel):

View file

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