|
| 1 | +""" |
| 2 | +The MIT License (MIT) |
| 3 | +
|
| 4 | +Copyright (c) 2021-present Pycord Development |
| 5 | +
|
| 6 | +Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | +copy of this software and associated documentation files (the "Software"), |
| 8 | +to deal in the Software without restriction, including without limitation |
| 9 | +the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | +and/or sell copies of the Software, and to permit persons to whom the |
| 11 | +Software is furnished to do so, subject to the following conditions: |
| 12 | +
|
| 13 | +The above copyright notice and this permission notice shall be included in |
| 14 | +all copies or substantial portions of the Software. |
| 15 | +
|
| 16 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 17 | +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 21 | +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 22 | +DEALINGS IN THE SOFTWARE. |
| 23 | +""" |
| 24 | + |
| 25 | +from __future__ import annotations |
| 26 | + |
| 27 | +from typing import TYPE_CHECKING |
| 28 | + |
| 29 | +from .enums import ApplicationRoleConnectionMetadataType, try_enum |
| 30 | +from .utils import MISSING |
| 31 | + |
| 32 | +if TYPE_CHECKING: |
| 33 | + from .types.application_role_connection import ( |
| 34 | + ApplicationRoleConnectionMetadata as ApplicationRoleConnectionMetadataPayload, |
| 35 | + ) |
| 36 | + |
| 37 | +__all__ = ("ApplicationRoleConnectionMetadata",) |
| 38 | + |
| 39 | + |
| 40 | +class ApplicationRoleConnectionMetadata: |
| 41 | + r"""Represents role connection metadata for a Discord application. |
| 42 | +
|
| 43 | + .. versionadded:: 2.4 |
| 44 | +
|
| 45 | + Parameters |
| 46 | + ---------- |
| 47 | + type: :class:`ApplicationRoleConnectionMetadataType` |
| 48 | + The type of metadata value. |
| 49 | + key: :class:`str` |
| 50 | + The key for this metadata field. |
| 51 | + May only be the ``a-z``, ``0-9``, or ``_`` characters, with a maximum of 50 characters. |
| 52 | + name: :class:`str` |
| 53 | + The name for this metadata field. Maximum 100 characters. |
| 54 | + description: :class:`str` |
| 55 | + The description for this metadata field. Maximum 200 characters. |
| 56 | + name_localizations: Optional[Dict[:class:`str`, :class:`str`]] |
| 57 | + The name localizations for this metadata field. The values of this should be ``"locale": "name"``. |
| 58 | + See `here <https://discord.com/developers/docs/reference#locales>`_ for a list of valid locales. |
| 59 | + description_localizations: Optional[Dict[:class:`str`, :class:`str`]] |
| 60 | + The description localizations for this metadata field. The values of this should be ``"locale": "name"``. |
| 61 | + See `here <https://discord.com/developers/docs/reference#locales>`_ for a list of valid locales. |
| 62 | + """ |
| 63 | + |
| 64 | + __slots__ = ( |
| 65 | + "type", |
| 66 | + "key", |
| 67 | + "name", |
| 68 | + "description", |
| 69 | + "name_localizations", |
| 70 | + "description_localizations", |
| 71 | + ) |
| 72 | + |
| 73 | + def __init__( |
| 74 | + self, |
| 75 | + *, |
| 76 | + type: ApplicationRoleConnectionMetadataType, |
| 77 | + key: str, |
| 78 | + name: str, |
| 79 | + description: str, |
| 80 | + name_localizations: dict[str, str] = MISSING, |
| 81 | + description_localizations: dict[str, str] = MISSING, |
| 82 | + ): |
| 83 | + self.type: ApplicationRoleConnectionMetadataType = type |
| 84 | + self.key: str = key |
| 85 | + self.name: str = name |
| 86 | + self.name_localizations: dict[str, str] = name_localizations |
| 87 | + self.description: str = description |
| 88 | + self.description_localizations: dict[str, str] = description_localizations |
| 89 | + |
| 90 | + def __repr__(self): |
| 91 | + return ( |
| 92 | + f"<ApplicationRoleConnectionMetadata " |
| 93 | + f"type={self.type!r} " |
| 94 | + f"key={self.key!r} " |
| 95 | + f"name={self.name!r} " |
| 96 | + f"description={self.description!r} " |
| 97 | + f"name_localizations={self.name_localizations!r} " |
| 98 | + f"description_localizations={self.description_localizations!r}>" |
| 99 | + ) |
| 100 | + |
| 101 | + def __str__(self): |
| 102 | + return self.name |
| 103 | + |
| 104 | + @classmethod |
| 105 | + def from_dict( |
| 106 | + cls, data: ApplicationRoleConnectionMetadataPayload |
| 107 | + ) -> ApplicationRoleConnectionMetadata: |
| 108 | + return cls( |
| 109 | + type=try_enum(ApplicationRoleConnectionMetadataType, data["type"]), |
| 110 | + key=data["key"], |
| 111 | + name=data["name"], |
| 112 | + description=data["description"], |
| 113 | + name_localizations=data.get("name_localizations"), |
| 114 | + description_localizations=data.get("description_localizations"), |
| 115 | + ) |
| 116 | + |
| 117 | + def to_dict(self) -> ApplicationRoleConnectionMetadataPayload: |
| 118 | + data = { |
| 119 | + "type": self.type.value, |
| 120 | + "key": self.key, |
| 121 | + "name": self.name, |
| 122 | + "description": self.description, |
| 123 | + } |
| 124 | + if self.name_localizations is not MISSING: |
| 125 | + data["name_localizations"] = self.name_localizations |
| 126 | + if self.description_localizations is not MISSING: |
| 127 | + data["description_localizations"] = self.description_localizations |
| 128 | + return data |
0 commit comments