feat(aurora): make all models compatible with repr
This commit is contained in:
parent
794ce56040
commit
fa27d12de5
5 changed files with 55 additions and 0 deletions
|
@ -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}>"
|
||||||
|
|
|
@ -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)
|
||||||
|
|
||||||
|
|
|
@ -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!")
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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.
|
||||||
|
|
Loading…
Reference in a new issue