WIP: Refactor Aurora (3.0.0) #29

Draft
cswimr wants to merge 347 commits from aurora-pydantic into main
5 changed files with 55 additions and 0 deletions
Showing only changes of commit fa27d12de5 - Show all commits

View file

@ -25,3 +25,6 @@ class AuroraGuildModel(AuroraBaseModel):
def dump(self) -> dict:
return self.model_dump(exclude={"bot", "guild_id", "guild"})
def __repr__(self) -> str:
return f"<{self.__class__.__name__} guild_id={self.guild_id}>"

View file

@ -30,6 +30,18 @@ class Change(AuroraBaseModel):
def __str__(self):
return f"{self.type} {self.user_id} {self.reason}"
def __repr__(self) -> str:
attrs = [
('type', self.type),
('timestamp', self.timestamp),
('user_id', self.user_id),
('reason', self.reason),
('duration', self.duration),
('end_timestamp', self.end_timestamp),
]
joined = ' '.join('%s=%r' % t for t in attrs)
return f"<{self.__class__.__name__} {joined}>"
async def get_user(self) -> "PartialUser":
return await PartialUser.from_id(self.bot, self.user_id)

View file

@ -122,6 +122,29 @@ class Moderation(AuroraGuildModel):
def __int__(self) -> int:
return self.moderation_id
def __repr__(self) -> str:
attrs = [
('guild_id', self.guild_id),
('moderation_id', self.moderation_id),
('timestamp', self.timestamp),
('type', self.type),
('target_type', self.target_type),
('target_id', self.target_id),
('moderator_id', self.moderator_id),
('role_id', self.role_id),
('duration', self.duration),
('end_timestamp', self.end_timestamp),
('reason', self.reason),
('resolved', self.resolved),
('resolved_by', self.resolved_by),
('resolve_reason', self.resolve_reason),
('expired', self.expired),
('changes', self.changes),
('metadata', self.metadata),
]
joined = ' '.join('%s=%r' % t for t in attrs)
return f"<{self.__class__.__name__} {joined}>"
async def resolve(self, resolved_by: int, reason: str) -> Tuple[bool, str]:
if self.resolved:
raise ValueError("Case is already resolved!")

View file

@ -18,6 +18,9 @@ class PartialUser(AuroraBaseModel):
def __str__(self):
return self.name
def __repr__(self):
return f"<{self.__class__.__name__} id={self.id}>"
@classmethod
async def from_id(cls, bot: Red, user_id: int) -> "PartialUser":
user = bot.get_user(user_id)
@ -45,6 +48,9 @@ class PartialChannel(AuroraGuildModel):
def __str__(self):
return self.mention
def __repr__(self):
return f"<{self.__class__.__name__} id={self.id} guild_id={self.guild_id}>"
@classmethod
async def from_id(cls, bot: Red, channel_id: int, guild: Guild) -> "PartialChannel":
channel = bot.get_channel(channel_id)
@ -72,6 +78,9 @@ class PartialRole(AuroraGuildModel):
def __str__(self):
return self.mention
def __repr__(self) -> str:
return f"<{self.__class__.__name__} id={self.id} guild_id={self.guild_id}>"
@classmethod
async def from_id(cls, bot: Red, guild: Guild, role_id: int) -> "PartialRole":
role = guild.get_role(role_id)

View file

@ -43,6 +43,14 @@ class Type(metaclass=AutoRegister(type_registry)):
def __str__(self) -> str:
return self.string
def __repr__(self) -> str:
attrs = [
('key', self.key),
('channel', self.channel),
]
joined = ' '.join('%s=%r' % t for t in attrs)
return f"<{self.__class__.__name__} {joined}>"
@classmethod
async def handler(cls, ctx: commands.Context, target: Member | User | Messageable, silent: bool, **kwargs) -> 'Type': # pylint: disable=unused-argument
"""This method should be overridden by any child classes, but should retain the same starting keyword arguments.