Load contact object, if it's not cached, create a new one and cache it. If you load it manually, you should call `ready()` to load the full info from puppet. Args: cls: the type of Contact contact_id: the union identifier of contact Example
(cls: Type[Contact], contact_id: str)
| 105 | |
| 106 | @classmethod |
| 107 | def load(cls: Type[Contact], contact_id: str) -> Contact: |
| 108 | """ |
| 109 | Load contact object, if it's not cached, create a new one and cache it. |
| 110 | |
| 111 | If you load it manually, you should call `ready()` to load the full info from puppet. |
| 112 | |
| 113 | Args: |
| 114 | cls: the type of Contact |
| 115 | contact_id: the union identifier of contact |
| 116 | |
| 117 | Examples: |
| 118 | >>> contact = bot.Contact.load(contact_id) |
| 119 | >>> await contact.ready() |
| 120 | >>> is_friend = contact.is_friend() |
| 121 | |
| 122 | Returns: |
| 123 | Contact: the contact object |
| 124 | """ |
| 125 | # 1. check if it's cached |
| 126 | if contact_id in cls._pool: |
| 127 | return cls._pool[contact_id] |
| 128 | |
| 129 | # 2. create new contact object |
| 130 | new_contact = cls(contact_id) |
| 131 | cls._pool[contact_id] = new_contact |
| 132 | return new_contact |
| 133 | |
| 134 | @classmethod |
| 135 | def _filter_contacts(cls, |