Add base -> colour support, and optimization in errors.py.
This commit is contained in:
@@ -83,6 +83,24 @@ class Colour:
|
||||
raise TypeError(f'Expected int parameter, received {value.__class__.__name__} instead.')
|
||||
|
||||
self.value: int = value
|
||||
|
||||
@staticmethod
|
||||
def from_hex(self, value: str, base:int = None):
|
||||
"""
|
||||
Initiate self.value from different base(hexidecimal, binary)
|
||||
=======
|
||||
|
||||
value `str` :
|
||||
|
||||
value in different base, e.g. white in hexidecimal, 0xffffff
|
||||
|
||||
base `int` (optional) :
|
||||
|
||||
base of your value, if you don't supply this, you have to add a prefix to your number, e.g. 0x or 0b
|
||||
|
||||
"""
|
||||
|
||||
return Colour(value = int(value, base=base))
|
||||
|
||||
def _get_byte(self, byte: int) -> int:
|
||||
return (self.value >> (8 * byte)) & 0xff
|
||||
|
||||
@@ -110,7 +110,7 @@ class CommandError(DiscordException):
|
||||
from :class:`.Bot`\, :func:`.on_command_error`.
|
||||
"""
|
||||
def __init__(self, message: Optional[str] = None, *args: Any) -> None:
|
||||
if message is not None:
|
||||
if message: # replace 'if not none' with 'if message'
|
||||
# clean-up @everyone and @here mentions
|
||||
m = message.replace('@everyone', '@\u200beveryone').replace('@here', '@\u200bhere')
|
||||
super().__init__(m, *args)
|
||||
|
||||
Reference in New Issue
Block a user