set_embed_color, embed_color and get_message added

This commit is contained in:
NightSlasher35 2021-08-29 00:56:09 +01:00 committed by GitHub
parent 6bcc717e63
commit c079983c57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -241,6 +241,58 @@ class Client:
# internals
def get_message(self, id):
"""Get a message from cache if the message is still in cache.
.. versionadded:: 1.6.0.7
Parameters
-----------
id: :class:`int`
The message ID to look for.
Returns
--------
Optional[:class:`.Message`]
The message asked for."""
return utils.get(self.cached_messages, id=id)
@property
def embed_color(self):
"""Optional[:class:`.Colour`]: The default embed colour that is
being used for all embed if no colour is passed."""
col = os.getenv("DEFAULT_EMBED_COLOR")
if not col:
return None
return Colour(int(col, 16))
def set_embed_color(self, color):
"""Set a new default embed color.
This will raise a TypeError if an improper format was passed.
.. versionadded:: 1.5.0.1
Parameters
-----------
color: Union[:class:`.Colour`, :class:`int`]
The new color you want to set as default embed color.
Pass either an instance of discord.Color or a valid
0x****** HEX value.
Returns
--------
:class:`.Colour`
The new color that has been set as default embed color.
"""
if isinstance(color, (Color, Colour)):
os.environ['DEFAULT_EMBED_COLOR'] = str(hex(color))
return color
else:
try:
HEX = re.compile(r'^(#)[A-Fa-f0-9]{6}$')
col = Color(color)
if HEX.match(str(col)):
os.environ['DEFAULT_EMBED_COLOR'] = str(hex(col))
return col
else:
raise TypeError('The hex value passed could not be converted to a color')
except:
raise TypeError('embed_color must be an instance of discord.Colour or a valid 0x****** hex value.')
def _get_websocket(self, guild_id: Optional[int] = None, *, shard_id: Optional[int] = None) -> DiscordWebSocket:
return self.ws