-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added embed, colours and file classes. Moved interaction reques…
…ts to goldy interaction method. #113
- Loading branch information
1 parent
939e6c1
commit 9685b41
Showing
13 changed files
with
413 additions
and
59 deletions.
There are no files selected for viewing
This file contains 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 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,42 @@ | ||
from __future__ import annotations | ||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from GoldyBot import File | ||
|
||
from enum import Enum | ||
from colorthief import ColorThief | ||
|
||
class Colours(Enum): | ||
"""Colours enum class for 🥞 pancake ported over from legacy api.""" | ||
AKI_PINK = 0xFF1493 | ||
AKI_ORANGE = 0xF4900C | ||
AKI_RED = 0xff0051 | ||
AKI_BLUE = 0X75E6DA | ||
BLUE = 0x3061f2 | ||
GREEN = 0x00FF00 | ||
LIME_GREEN = 0x8AFF65 | ||
YELLOW = 0xffff4d | ||
PURPLE = 0xFF00FF | ||
RED = 0xFF0000 | ||
BROWN = 0xFFBA6D | ||
GREY = 0x3B3B3B | ||
WHITE = 0xFFFFFF | ||
BLACK = 0x000000 | ||
|
||
INVISIBLE = 0x2B2D31 | ||
"""Makes the embed colour the same as the background essentially giving the embed colour a transparent look.""" | ||
|
||
def __init__(self, colour: int): | ||
... | ||
|
||
@classmethod | ||
def from_rgb(cls, r: int, g:int, b:int) -> int: | ||
"""Converts rgb values into colour.""" | ||
return (r << 16) + (g << 8) + b | ||
|
||
@classmethod | ||
def from_image(cls, file: File, accuracy: int = 5) -> int: | ||
"""Returns the dominant colour in that image.""" | ||
r, g, b = ColorThief(file.file_io).get_color(accuracy) | ||
return cls.from_rgb(r, g, b) |
This file contains 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 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 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,53 @@ | ||
from __future__ import annotations | ||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from typing import Optional, BinaryIO | ||
from typing_extensions import Self | ||
|
||
import os | ||
import io | ||
from requests import Response | ||
from .errors import GoldyBotError | ||
|
||
__all__ = ( | ||
"File", | ||
) | ||
|
||
class File(): | ||
""" | ||
Goldy bot's basic file object for 🥞 pancake. | ||
""" | ||
def __init__(self, file: BinaryIO, file_name: Optional[str] = None) -> None: | ||
self.file = file | ||
|
||
try: | ||
self.name = file_name or os.path.split(file.name)[1] | ||
except AttributeError as e: | ||
raise GoldyBotError( | ||
f"This file object does not have the .name attribute, 'file_name' must be specified! Error >> {e}" | ||
) | ||
|
||
self.attachment_url = f"attachment://{file_name}" | ||
"""Returns the attachment url string. Useful when attaching images to Embeds.""" | ||
|
||
@classmethod | ||
def from_response(cls, response: Response) -> Self: | ||
content_type = response.headers.get("Content-Type") | ||
|
||
if content_type is None: | ||
raise GoldyBotError("'response' does not have 'Content-Type' header!") | ||
|
||
return cls( | ||
file = io.BytesIO(response.content), | ||
file_name = f"image.{content_type.split('/')[1]}" | ||
) | ||
|
||
@property | ||
def contents(self) -> bytes: | ||
"""Returns the contents of this file. Useful for uploading.""" | ||
return self.file.read() | ||
|
||
def close(self) -> None: | ||
"""Closes the mf.""" | ||
self.file.close() |
This file contains 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 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 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 @@ | ||
from .embed import * |
Oops, something went wrong.