Skip to content

Commit

Permalink
1.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Bertik23 committed May 18, 2021
1 parent 1f9b3ee commit f31916a
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 83 deletions.
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"python.pythonPath": "d:\\Python\\BDBF\\venv\\Scripts\\python.exe"
"python.pythonPath": "d:\\Python\\BDBF\\venv\\Scripts\\python.exe",
"python.linting.enabled": true,
"python.formatting.provider": "autopep8",
"python.linting.pycodestyleEnabled": true
}
2 changes: 1 addition & 1 deletion bdbf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
__author__ = 'Bertik23'
__license__ = 'MIT'
__copyright__ = 'Copyright 2020-2021 Bertik23'
__version__ = '1.1.1'
__version__ = '1.1.2'
83 changes: 53 additions & 30 deletions bdbf/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

last10messages: dict = {}

def IntToRgb(RGBint: int):# -> typing.Tuple[int,int,int]:

def IntToRgb(RGBint: int): # -> typing.Tuple[int,int,int]:
"""Converts a integer color value to a RGB tuple
:param RGBint: :class:`int`
Expand All @@ -16,12 +17,13 @@ def IntToRgb(RGBint: int):# -> typing.Tuple[int,int,int]:
:returns: :class:`tuple[int,int,int]`
RGB tuple
"""
blue = RGBint & 255
blue = RGBint & 255
green = (RGBint >> 8) & 255
red = (RGBint >> 16) & 255
red = (RGBint >> 16) & 255
return red, green, blue

def RgbToInt(rgb: typing.Tuple[int,int,int]):# -> int:

def RgbToInt(rgb: typing.Tuple[int, int, int]): # -> int:
"""Converts a RGB tuple to a integer color value
:param rgb: :class:`tuple[int,int,int]`
Expand All @@ -35,29 +37,44 @@ def RgbToInt(rgb: typing.Tuple[int,int,int]):# -> int:
red = rgb[0]
green = rgb[1]
blue = rgb[2]
RGBint = (red<<16) + (green<<8) + blue
RGBint = (red << 16) + (green << 8) + blue
return RGBint

def hasLink(text: str):# -> bool:

def hasLink(text: str): # -> bool:
"""Returns if a string contains a link.
:param text: :class:`str`
String to check
:returns: :class:`bool`
If the string has a link.
"""
regex = re.compile(
"(([\w]+:)?//)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,63}(:[\d]+)?(/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?"
r"(([\w]+:)?//)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})"
r"+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,63}(:[\d]+)?(/([-+_~.\d"
r"\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?"
r"(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?"
)
if regex.match(text):
return True
else:
return False

def embed(title, url = None, description = None, fields = None, image = None, thumbnail = None, author = None, footer=None, color: typing.Union[typing.Tuple[int,int,int], int] = 0):# -> discord.Embed:

def embed(
title,
url=discord.embeds.EmptyEmbed,
description=discord.embeds.EmptyEmbed,
fields=None,
image=None,
thumbnail=None,
author=None,
footer=None,
color: typing.Union[typing.Tuple[int, int, int], int] = 0
): # -> discord.Embed:
"""Returns discord embed from given parameters
:param title: :class:`str`
Title of the embed
:param url: :class:`Optional[str]`
Expand All @@ -66,7 +83,8 @@ def embed(title, url = None, description = None, fields = None, image = None, th
Description of the embed
:param fields: :class:`Optional[List[Tuple[str,str,Optional[bool]]]]`
Fields of the embed.
A tuple with item 1 being the name of the field, item 2 the value and item 3 weather is inline or not, item 3 is optional
A tuple with item 1 being the name of the field, item 2 the value and
item 3 weather is inline or not, item 3 is optional
:param image: :class:`Optional[str]`
Url of the embed image
:param thumbnail: :class:`Optional[str]`
Expand All @@ -77,35 +95,40 @@ def embed(title, url = None, description = None, fields = None, image = None, th
Footer of the embed
:param color: :class:`Optional[Union[Tuple[int,int,int],int]]`
Color of the embed, eighter RGB tuple or int
:returns: discord.Embed"""
if type(color) == tuple:
color = RgbToInt(color)

if fields == None:
if fields is None:
fields = []

fieldKeys = []
for i,f in enumerate(fields):
for i, f in enumerate(fields):
if len(f) == 2:
fieldKeys.append(("name","value"))
fieldKeys.append(("name", "value"))
elif len(f) == 3:
fieldKeys.append(("name","value","inline"))
fieldKeys.append(("name", "value", "inline"))

#print(fieldKeys, fields, [list(i) for i in [zip(j,fields[k]) for k,j in enumerate(fieldKeys)]])
fields = [dict(l) for l in [list(i) for i in [zip(j,fields[k]) for k,j in enumerate(fieldKeys)]]]
#print(fields)
fields = [
dict(a) for a in [
list(i) for i in [
zip(j, fields[k]) for k, j in enumerate(fieldKeys)
]
]
]
# print(fields)

e = discord.Embed.from_dict({
"title": title,
"color": color,
"description": description,
"image": image,
"thumbnail": thumbnail,
"author": author,
"fields": fields,
"url": url,
"footer": footer
}
)
"title": title,
"color": color,
"description": description,
"image": image,
"thumbnail": thumbnail,
"author": author,
"fields": fields,
"url": url,
"footer": footer
}
)
return e
Loading

0 comments on commit f31916a

Please sign in to comment.