Esempio n. 1
0
    def from_data(cls, data: ExtDict, client: Client) -> User:
        youtube = data.get(Index.USER_YOUTUBE, "")
        youtube = {
            "normal": youtube,
            "link": "https://www.youtube.com/channel/" + youtube
        }
        twitter = data.get(Index.USER_TWITTER, "")
        twitter = {"normal": twitter, "link": "https://twitter.com/" + twitter}
        twitch = data.get(Index.USER_TWITCH, "")
        twitch = {"normal": twitch, "link": "https://twitch.tv/" + twitch}

        return cls(
            name=data.get(Index.USER_NAME, "unknown"),
            id=data.getcast(Index.USER_PLAYER_ID, 0, int),
            stars=data.getcast(Index.USER_STARS, 0, int),
            demons=data.getcast(Index.USER_DEMONS, 0, int),
            secret_coins=data.getcast(Index.USER_SECRET_COINS, 0, int),
            coins=data.getcast(Index.USER_COINS, 0, int),
            cp=data.getcast(Index.USER_CREATOR_POINTS, 0, int),
            diamonds=data.getcast(Index.USER_DIAMONDS, 0, int),
            role=data.getcast(Index.USER_ROLE, 0, int),
            global_rank=data.getcast(Index.USER_GLOBAL_RANK, None, int),
            account_id=data.getcast(Index.USER_ACCOUNT_ID, 0, int),
            youtube=youtube,
            twitter=twitter,
            twitch=twitch,
            message_policy=MessagePolicyType.from_value(
                data.getcast(Index.USER_PRIVATE_MESSAGE_POLICY, 0, int), 0),
            friend_request_policy=FriendRequestPolicyType.from_value(
                data.getcast(Index.USER_FRIEND_REQUEST_POLICY, 0, int), 0),
            comment_policy=CommentPolicyType.from_value(
                data.getcast(Index.USER_COMMENT_HISTORY_POLICY, 0, int), 0),
            icon_setup=IconSet(
                main_icon=data.getcast(Index.USER_ICON, 1, int),
                color_1=colors[data.getcast(Index.USER_COLOR_1, 0, int)],
                color_2=colors[data.getcast(Index.USER_COLOR_2, 0, int)],
                main_icon_type=IconType.from_value(
                    data.getcast(Index.USER_ICON_TYPE, 0, int), 0),
                has_glow_outline=bool(
                    data.getcast(Index.USER_GLOW_OUTLINE_2, 0, int)),
                icon_cube=data.getcast(Index.USER_ICON_CUBE, 1, int),
                icon_ship=data.getcast(Index.USER_ICON_SHIP, 1, int),
                icon_ball=data.getcast(Index.USER_ICON_BALL, 1, int),
                icon_ufo=data.getcast(Index.USER_ICON_UFO, 1, int),
                icon_wave=data.getcast(Index.USER_ICON_WAVE, 1, int),
                icon_robot=data.getcast(Index.USER_ICON_ROBOT, 1, int),
                icon_spider=data.getcast(Index.USER_ICON_SPIDER, 1, int),
                icon_explosion=data.getcast(Index.USER_EXPLOSION, 1, int),
                client=client,
            ),
            client=client,
        )
Esempio n. 2
0
    async def generate(
        self,
        type: Optional[Union[int, str, IconType]] = None,
        as_image: bool = False,
    ) -> Union[bytes, ImageType]:
        """|coro|

        Generate an image of an icon.

        Parameters
        ----------
        type: Optional[Union[:class:`int`, :class:`str`, :class:`.IconType`]]
            Type of an icon to generate. If not given or ``"main"``, picks current main icon.

        as_image: :class:`bool`
            Whether to return an image or bytes of an image.

        Returns
        -------
        Union[:class:`bytes`, :class:`PIL.Image.Image`]
            Bytes or an image, based on ``as_image``.
        """
        if type is None or type == "main":
            type = self.main_type

        type = IconType.from_value(type)

        result = await run_blocking_io(
            factory.generate,
            icon_type=type,
            icon_id=self.get_id_by_type(type),
            color_1=self.color_1,
            color_2=self.color_2,
            glow_outline=self.has_glow_outline(),
        )

        if as_image:
            return result

        return await run_blocking_io(to_bytes, result)
Esempio n. 3
0
    async def generate(
        self,
        type: Optional[Union[int, str, IconType]] = None,
        as_image: bool = False,
    ) -> Union[bytes, ImageType]:
        if type is None or type == "main":
            type = self.main_type

        type = IconType.from_value(type)

        result = await run_blocking_io(
            factory.generate,
            icon_type=type,
            icon_id=self.get_id_by_type(type),
            color_1=self.color_1,
            color_2=self.color_2,
            glow_outline=self.has_glow_outline(),
        )

        if as_image:
            return result

        return await run_blocking_io(to_bytes, result)
Esempio n. 4
0
 def __attrs_post_init__(self) -> None:
     self.type = IconType.from_value(self.type)
Esempio n. 5
0
 def main_type(self) -> IconType:
     """:class:`.IconType`: A type of the main icon of the iconset."""
     return IconType.from_value(self.options.get("main_icon_type", 0))