-
-
Notifications
You must be signed in to change notification settings - Fork 494
feat: Add the shared client theme object on message sent and in message object #3209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
UnBonWhisky
wants to merge
27
commits into
Pycord-Development:master
Choose a base branch
from
UnBonWhisky:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
236e8ec
feat: Add SharedClientTheme support for customizable message appearance
UnBonWhisky 9116f68
fix: Remove redundant validation checks for shared_client_theme
UnBonWhisky 7c2ae1e
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 03e795b
fix: Update versionadded for SharedClientTheme to 2.9 across multiple…
UnBonWhisky 2ac124b
fix: Add SharedClientTheme in changelog
UnBonWhisky e940162
fix: Update the SharedClientTheme constructor to mark the required ar…
UnBonWhisky d41f8f6
Update discord/shared_client_theme.py
UnBonWhisky d4c1a55
Update CHANGELOG.md
UnBonWhisky 73c3ce1
Update discord/abc.py
UnBonWhisky 6234b77
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] d96ea81
fix: applied the comments and used colour as the main and color as an…
2ad9447
docs: moved SharedClientTheme from data_class to models
b8a1994
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 9e84f08
Merge branch 'master' into master
Paillat-dev 4401b08
fix: refactor SharedClientTheme initialization and color handling
c99567d
fix: update from_dict method to use Self type hint
23bd2cf
fix: add parentheses to SharedClientTheme autoclass declaration
7d4d65d
fix: refactor SharedClientTheme to use dataclass and update type hints
5a1f0c1
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] aa00312
fix: update SharedClientTheme to use field for colours with default f…
12adfcb
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] b827ed1
fix: update SharedClientTheme to use field for colours and adjust dat…
a53d601
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 4e8926c
fix: remove __repr__ method from SharedClientTheme class
28c746f
Update discord/message.py
UnBonWhisky cfdcb80
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 383b28e
Update CHANGELOG.md
UnBonWhisky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| """ | ||
| The MIT License (MIT) | ||
|
|
||
| Copyright (c) 2021-present Pycord Development | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a | ||
| copy of this software and associated documentation files (the "Software"), | ||
| to deal in the Software without restriction, including without limitation | ||
| the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
| and/or sell copies of the Software, and to permit persons to whom the | ||
| Software is furnished to do so, subject to the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be included in | ||
| all copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
| OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
| FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
| DEALINGS IN THE SOFTWARE. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from dataclasses import dataclass | ||
| from typing import TYPE_CHECKING, Sequence | ||
|
|
||
| from typing_extensions import Self | ||
|
|
||
| from .colour import Colour | ||
| from .enums import SharedClientThemeBaseType, try_enum | ||
| from .utils import MISSING | ||
|
|
||
| __all__ = ("SharedClientTheme",) | ||
|
|
||
|
|
||
| if TYPE_CHECKING: | ||
| from .types.shared_client_theme import SharedClientTheme as SharedClientThemePayload | ||
|
|
||
|
|
||
| @dataclass(init=False) | ||
| class SharedClientTheme: | ||
| """Represents a shared client theme that can be sent in a message. | ||
|
|
||
| A shared client theme lets users transmit a customized Discord client | ||
| appearance (colors, gradient, and base mode) through a message. | ||
|
|
||
| .. versionadded:: 2.9 | ||
|
|
||
| Attributes | ||
| ---------- | ||
| colours: List[:class:`Colour`] | ||
| The colours of the theme. A maximum of 5 colours. | ||
| colors: List[:class:`Colour`] | ||
| Alias for :attr:`colours`. | ||
| gradient_angle: :class:`int` | ||
| The direction of the theme's colors, in degrees. Must be between ``0`` and ``360``. | ||
| base_mix: :class:`int` | ||
| The intensity of the theme's colors. Must be between ``0`` and ``100``. | ||
| base_theme: Optional[:class:`SharedClientThemeBaseType`] | ||
| The mode of the theme. Defaults to :attr:`SharedClientThemeBaseType.unset`, | ||
| which Discord treats as :attr:`SharedClientThemeBaseType.dark`. | ||
| """ | ||
|
|
||
| gradient_angle: int = 0 | ||
| base_mix: int = 0 | ||
| colours: list[Colour] | ||
| base_theme: SharedClientThemeBaseType | None = SharedClientThemeBaseType.unset | ||
|
|
||
| def __init__( | ||
| self, | ||
| gradient_angle: int = 0, | ||
| base_mix: int = 0, | ||
| colors: Sequence[Colour] = MISSING, | ||
| colours: Sequence[Colour] = MISSING, | ||
| *, | ||
| base_theme: SharedClientThemeBaseType = SharedClientThemeBaseType.unset, | ||
| ) -> None: | ||
| colours = colours if colours is not MISSING else colors | ||
|
|
||
| if len(colours or []) > 5: | ||
| raise ValueError("colors or colours must contain at most 5 colours") | ||
| if colours is MISSING: | ||
| raise TypeError("colors or colours must be provided") | ||
|
|
||
| if not 0 <= gradient_angle <= 360: | ||
| raise ValueError("gradient_angle must be between 0 and 360") | ||
|
|
||
| if not 0 <= base_mix <= 100: | ||
| raise ValueError("base_mix must be between 0 and 100") | ||
|
|
||
| if base_theme is not None and not isinstance( | ||
| base_theme, SharedClientThemeBaseType | ||
| ): | ||
| raise TypeError("base_theme must be a SharedClientThemeBaseType or None") | ||
|
|
||
| self.gradient_angle = gradient_angle | ||
| self.base_mix = base_mix | ||
| self.colours = list(colours) | ||
| self.base_theme = base_theme | ||
|
|
||
| @property | ||
| def colors(self) -> list[Colour]: | ||
| return self.colours | ||
|
|
||
| def to_dict(self) -> SharedClientThemePayload: | ||
| payload: SharedClientThemePayload = { | ||
| "colors": [f"{c.value:0>6x}" for c in self.colours], | ||
| "gradient_angle": self.gradient_angle, | ||
| "base_mix": self.base_mix, | ||
| } | ||
| if self.base_theme is not None: | ||
| payload["base_theme"] = self.base_theme.value | ||
| return payload | ||
|
|
||
| @classmethod | ||
| def from_dict(cls, data: SharedClientThemePayload) -> Self: | ||
| base_theme_value = data.get("base_theme") | ||
| colours = [Colour(int(c, 16)) for c in data.get("colors", [])] | ||
| return cls( | ||
| colours=colours, | ||
| gradient_angle=data["gradient_angle"], | ||
| base_mix=data["base_mix"], | ||
| base_theme=( | ||
| try_enum(SharedClientThemeBaseType, base_theme_value) | ||
| if base_theme_value is not None | ||
| else None | ||
| ), | ||
| ) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be documented in the property method not here since it's not an attribute technically.