Add base -> colour support, and optimization in errors.py.
This commit is contained in:
@@ -84,6 +84,24 @@ class Colour:
|
|||||||
|
|
||||||
self.value: int = value
|
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:
|
def _get_byte(self, byte: int) -> int:
|
||||||
return (self.value >> (8 * byte)) & 0xff
|
return (self.value >> (8 * byte)) & 0xff
|
||||||
|
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ class CommandError(DiscordException):
|
|||||||
from :class:`.Bot`\, :func:`.on_command_error`.
|
from :class:`.Bot`\, :func:`.on_command_error`.
|
||||||
"""
|
"""
|
||||||
def __init__(self, message: Optional[str] = None, *args: Any) -> None:
|
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
|
# clean-up @everyone and @here mentions
|
||||||
m = message.replace('@everyone', '@\u200beveryone').replace('@here', '@\u200bhere')
|
m = message.replace('@everyone', '@\u200beveryone').replace('@here', '@\u200bhere')
|
||||||
super().__init__(m, *args)
|
super().__init__(m, *args)
|
||||||
|
|||||||
Reference in New Issue
Block a user