feat(aurora): make all models compatible with repr
Some checks failed
Actions / Build Documentation (MkDocs) (pull_request) Successful in 29s
Actions / Lint Code (Ruff & Pylint) (pull_request) Failing after 51s

This commit is contained in:
Seaswimmer 2024-08-22 15:33:36 -04:00
parent 794ce56040
commit fa27d12de5
Signed by: cswimr
GPG key ID: 3813315477F26F82
5 changed files with 55 additions and 0 deletions

View file

@ -25,3 +25,6 @@ class AuroraGuildModel(AuroraBaseModel):
def dump(self) -> dict: def dump(self) -> dict:
return self.model_dump(exclude={"bot", "guild_id", "guild"}) 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): def __str__(self):
return f"{self.type} {self.user_id} {self.reason}" 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": async def get_user(self) -> "PartialUser":
return await PartialUser.from_id(self.bot, self.user_id) return await PartialUser.from_id(self.bot, self.user_id)

View file

@ -122,6 +122,29 @@ class Moderation(AuroraGuildModel):
def __int__(self) -> int: def __int__(self) -> int:
return self.moderation_id 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]: async def resolve(self, resolved_by: int, reason: str) -> Tuple[bool, str]:
if self.resolved: if self.resolved:
raise ValueError("Case is already resolved!") raise ValueError("Case is already resolved!")

View file

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

View file

@ -43,6 +43,14 @@ class Type(metaclass=AutoRegister(type_registry)):
def __str__(self) -> str: def __str__(self) -> str:
return self.string 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 @classmethod
async def handler(cls, ctx: commands.Context, target: Member | User | Messageable, silent: bool, **kwargs) -> 'Type': # pylint: disable=unused-argument 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. """This method should be overridden by any child classes, but should retain the same starting keyword arguments.