mirror of
https://github.com/MelisaDev/melisa.git
synced 2024-11-14 12:27:28 +03:00
BREAKING CHANGE: add structure emoji and role
This commit is contained in:
parent
54d885294a
commit
c4ce2de1a4
3 changed files with 150 additions and 0 deletions
|
@ -5,3 +5,5 @@ from .guild import *
|
||||||
from .channel import *
|
from .channel import *
|
||||||
from .thread import *
|
from .thread import *
|
||||||
from .webhook import *
|
from .webhook import *
|
||||||
|
from .emoji import *
|
||||||
|
from .role import *
|
||||||
|
|
72
melisa/models/guild/emoji.py
Normal file
72
melisa/models/guild/emoji.py
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
# Copyright MelisaDev 2022 - Present
|
||||||
|
# Full MIT License can be found in `LICENSE.txt` at the project root.
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from dataclasses import dataclass
|
||||||
|
from typing import TYPE_CHECKING, Dict
|
||||||
|
|
||||||
|
from ...utils import Snowflake
|
||||||
|
from ...utils.api_model import APIModelBase
|
||||||
|
from ...utils.types import APINullable, UNDEFINED
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from ..user.user import User
|
||||||
|
from .role import Role
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(repr=False)
|
||||||
|
class Emoji(APIModelBase):
|
||||||
|
"""Emoji Structure
|
||||||
|
|
||||||
|
Attributes
|
||||||
|
----------
|
||||||
|
id: :class:`~melisa.utils.types.Snowflake`
|
||||||
|
Emoji id
|
||||||
|
name: :class:`str`
|
||||||
|
Emoji name
|
||||||
|
roles: :class:`Any`
|
||||||
|
Roles allowed to use this emoji
|
||||||
|
user: :class:`Any`
|
||||||
|
User that created this emoji
|
||||||
|
require_colons: :class:`bool`
|
||||||
|
Whether this emoji must be wrapped in colons
|
||||||
|
managed: :class:`bool`
|
||||||
|
Whether this emoji is managed
|
||||||
|
animated: :class:`bool`
|
||||||
|
Whether this emoji is animated
|
||||||
|
available: :class:`bool`
|
||||||
|
Whether this emoji can be used, may be false due to loss of Server Boosts
|
||||||
|
"""
|
||||||
|
|
||||||
|
id: APINullable[Snowflake] = UNDEFINED
|
||||||
|
name: APINullable[str] = UNDEFINED
|
||||||
|
roles: APINullable[Role] = UNDEFINED
|
||||||
|
user: APINullable[User] = UNDEFINED
|
||||||
|
require_colons: APINullable[bool] = UNDEFINED
|
||||||
|
managed: APINullable[bool] = UNDEFINED
|
||||||
|
animated: APINullable[bool] = UNDEFINED
|
||||||
|
available: APINullable[bool] = UNDEFINED
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_dict(cls, data: Dict[str, any]) -> Emoji:
|
||||||
|
"""Generate an emoji from the given data.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
data: :class:`dict`
|
||||||
|
The dictionary to convert into an emoji.
|
||||||
|
"""
|
||||||
|
|
||||||
|
self: Emoji = super().__new__(cls)
|
||||||
|
|
||||||
|
self.id = int(data["id"])
|
||||||
|
self.name = data.get("name")
|
||||||
|
self.roles = data.get("roles")
|
||||||
|
self.user = data.get("user", {})
|
||||||
|
self.require_colons = data.get("require_colons", False)
|
||||||
|
self.managed = data.get("managed", False)
|
||||||
|
self.animated = data.get("animated", False)
|
||||||
|
self.available = data.get("available", False)
|
||||||
|
|
||||||
|
return self
|
76
melisa/models/guild/role.py
Normal file
76
melisa/models/guild/role.py
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
# Copyright MelisaDev 2022 - Present
|
||||||
|
# Full MIT License can be found in `LICENSE.txt` at the project root.
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from dataclasses import dataclass
|
||||||
|
from typing import TYPE_CHECKING, Dict
|
||||||
|
|
||||||
|
from ...utils import Snowflake
|
||||||
|
from ...utils.api_model import APIModelBase
|
||||||
|
from ...utils.types import APINullable, UNDEFINED
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(repr=False)
|
||||||
|
class Role(APIModelBase):
|
||||||
|
"""Roles represent a set of permissions attached to a group of users.
|
||||||
|
|
||||||
|
Attributes
|
||||||
|
----------
|
||||||
|
id: :class:`~melisa.utils.types.Snowflake`
|
||||||
|
Role id
|
||||||
|
name: :class:`str`
|
||||||
|
Role name
|
||||||
|
color: :class:`int`
|
||||||
|
Integer representation of hexadecimal color code
|
||||||
|
hoist: :class:`bool`
|
||||||
|
If this role is pinned in the user listing
|
||||||
|
icon: :class:`str`
|
||||||
|
Role icon hash
|
||||||
|
unicode_emoji: :class:`str`
|
||||||
|
Role unicode emoji
|
||||||
|
position: :class:`str`
|
||||||
|
Position of this role
|
||||||
|
permission: :class:`str`
|
||||||
|
Permission bit set
|
||||||
|
managed: :class:`bool`
|
||||||
|
Whether this role is managed by an integration
|
||||||
|
mentionable: :class:`bool`
|
||||||
|
Whether this role is mentionable
|
||||||
|
"""
|
||||||
|
|
||||||
|
id: APINullable[Snowflake] = UNDEFINED
|
||||||
|
name: APINullable[str] = UNDEFINED
|
||||||
|
color: APINullable[int] = UNDEFINED
|
||||||
|
hoist: APINullable[bool] = UNDEFINED
|
||||||
|
icon: APINullable[str] = UNDEFINED
|
||||||
|
unicode_emoji: APINullable[str] = UNDEFINED
|
||||||
|
position: APINullable[int] = UNDEFINED
|
||||||
|
permission: APINullable[str] = UNDEFINED
|
||||||
|
managed: APINullable[bool] = UNDEFINED
|
||||||
|
mentionable: APINullable[bool] = UNDEFINED
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_dict(cls, data: Dict[str, any]) -> Role:
|
||||||
|
"""Generate a role from the given data.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
data: :class:`dict`
|
||||||
|
The dictionary to convert into a role.
|
||||||
|
"""
|
||||||
|
|
||||||
|
self: Role = super().__new__(cls)
|
||||||
|
|
||||||
|
self.id = int(data["id"])
|
||||||
|
self.name = data.get("name")
|
||||||
|
self.color = data.get("color")
|
||||||
|
self.hoist = data.get("hoist", False)
|
||||||
|
self.icon = data.get("icon")
|
||||||
|
self.unicode_emoji = data.get("unicode_emoji")
|
||||||
|
self.position = data.get("position")
|
||||||
|
self.permission = data.get("permission")
|
||||||
|
self.managed = data.get("managed", False)
|
||||||
|
self.mentionable = data.get("mentionable", False)
|
||||||
|
|
||||||
|
return self
|
Loading…
Reference in a new issue