[docs]classSnowflake:""" A class to represent a Discord Snowflake """def__init__(self,*,id:int):ifnotisinstance(id,int):raiseTypeError("id must be an integer")self.id:int=iddef__repr__(self)->str:returnf"<Snowflake id={self.id}>"def__str__(self)->str:returnstr(self.id)def__int__(self)->int:returnself.iddef__eq__(self,other)->bool:matchother:casexifisinstance(x,Snowflake):returnself.id==other.idcasexifisinstance(x,int):returnself.id==othercase_:returnFalsedef__gt__(self,other)->bool:matchother:casexifisinstance(x,Snowflake):returnself.id>other.idcasexifisinstance(x,int):returnself.id>othercase_:raiseTypeError(f"Cannot compare 'Snowflake' to '{type(other).__name__}'")def__lt__(self,other)->bool:matchother:casexifisinstance(x,Snowflake):returnself.id<other.idcasexifisinstance(x,int):returnself.id<othercase_:raiseTypeError(f"Cannot compare 'Snowflake' to '{type(other).__name__}'")def__ge__(self,other)->bool:matchother:casexifisinstance(x,Snowflake):returnself.id>=other.idcasexifisinstance(x,int):returnself.id>=othercase_:raiseTypeError(f"Cannot compare 'Snowflake' to '{type(other).__name__}'")def__le__(self,other)->bool:matchother:casexifisinstance(x,Snowflake):returnself.id<=other.idcasexifisinstance(x,int):returnself.id<=othercase_:raiseTypeError(f"Cannot compare 'Snowflake' to '{type(other).__name__}'")@propertydefcreated_at(self)->datetime:""" `datetime`: The datetime of the snowflake """returnutils.snowflake_time(self.id)
[docs]classPartialBase(Snowflake):""" A base class for partial objects. This class is based on the Snowflae class standard, but with a few extra attributes. """def__init__(self,*,id:int):super().__init__(id=int(id))def__repr__(self)->str:returnf"<PartialBase id={self.id}>"
[docs]defis_partial(self)->bool:""" `bool`: Returns True if the object is partial This depends on the class name starting with Partial or not. """returnself.__class__.__name__.startswith("Partial")