From a98b6fa3b40c659099f6e2d05321e5c35d97070c Mon Sep 17 00:00:00 2001 From: Sayad Uddin Tahsin <89304780+Sayad-Uddin-Tahsin@users.noreply.github.com> Date: Tue, 11 Apr 2023 20:08:08 +0600 Subject: [PATCH] Add files via upload Signed-off-by: Sayad Uddin Tahsin <89304780+Sayad-Uddin-Tahsin@users.noreply.github.com> --- setup.py | 2 +- sra/__init__.py | 2 +- sra/canvas.py | 132 +++++++++++++++++++----------------------------- sra/welcome.py | 26 +++++++--- 4 files changed, 72 insertions(+), 90 deletions(-) diff --git a/setup.py b/setup.py index f0e92e1..60ce6c5 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setup( name='sra-pylib', - version='1.4.0', + version='1.4.1', author='Sayad Uddin Tahsin', author_email='mr.pluto012@gmail.com', description='A Wrapper of some-random-api for Python', diff --git a/sra/__init__.py b/sra/__init__.py index 8919be1..25a3ee4 100644 --- a/sra/__init__.py +++ b/sra/__init__.py @@ -10,7 +10,7 @@ from sra import exceptions import datetime -__version__ = "1.4.0" +__version__ = "1.4.1" __copyright__ = f"© Copyright 2023 {('- ' + str(datetime.datetime.today().year) + ' ') if int(datetime.datetime.today().year) != 2023 else ''}Sayad Uddin Tahsin." __author__ = "Sayad Uddin Tahsin" __author_email__ = "mr.pluto012@gmail.com" diff --git a/sra/canvas.py b/sra/canvas.py index 566ab81..03ab118 100644 --- a/sra/canvas.py +++ b/sra/canvas.py @@ -8,16 +8,24 @@ def is_valid_url(url): pattern = re.compile( r'^https?://' - r'(?:[a-z0-9]+(?:\.[a-z0-9]+)*/)*' - r'[a-z0-9]+\.[a-z]+/?$' + r'([a-z0-9]+\.)*[a-z0-9]+\.[a-z]+/?' + r'([^\s/]+/?)+$' ) return bool(pattern.match(url)) -def get_exact_avatar_url(url): - if "?" in str(url): - url = (str(url).split("?"))[0] - return url +def isValidAvatarURL(url): + try: + response = requests.get(url, stream=True) + content_type = response.headers.get('content-type') + if 'image' in content_type: + if 'png' in content_type: + return True + elif 'jpg' in content_type: + return True + except requests.exceptions.RequestException: + return False + return False class Filter: @@ -46,8 +54,7 @@ def Blue(self, avatar_url: str, name: str = "image.png"): if not is_valid_url(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Seems the Avatar URL is Invalid. Please recheck it and make sure it startswith http or https") - avatar_url = get_exact_avatar_url(avatar_url) - if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png"): + if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png") and not isValidAvatarURL(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Avatar Format must be '.jpg' or '.png'" ) @@ -94,8 +101,7 @@ def Blurple(self, avatar_url: str, name: str = "image.png"): if not is_valid_url(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Seems the Avatar URL is Invalid. Please recheck it and make sure it startswith http or https") - avatar_url = get_exact_avatar_url(avatar_url) - if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png"): + if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png") and not isValidAvatarURL(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Avatar Format must be '.jpg' or '.png'" ) @@ -142,8 +148,7 @@ def Blurple2(self, avatar_url: str, name: str = "image.png"): if not is_valid_url(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Seems the Avatar URL is Invalid. Please recheck it and make sure it startswith http or https") - avatar_url = get_exact_avatar_url(avatar_url) - if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png"): + if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png") and not isValidAvatarURL(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Avatar Format must be '.jpg' or '.png'" ) @@ -192,8 +197,7 @@ def Brightness(self, avatar_url: str, brightness: int = 30, name: str = "image.p if not is_valid_url(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Seems the Avatar URL is Invalid. Please recheck it and make sure it startswith http or https") - avatar_url = get_exact_avatar_url(avatar_url) - if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png"): + if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png") and not isValidAvatarURL(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Avatar Format must be '.jpg' or '.png'" ) @@ -245,11 +249,11 @@ def Color(self, avatar_url: str, color: str, name: str = "image.png"): if not is_valid_url(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Seems the Avatar URL is Invalid. Please recheck it and make sure it startswith http or https") - avatar_url = get_exact_avatar_url(avatar_url) - if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png"): + if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png") and not isValidAvatarURL(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Avatar Format must be '.jpg' or '.png'" ) + if color.startswith("#"): color = color.replace("#", "", 1) if len(color) not in [6, 8]: @@ -300,8 +304,7 @@ def Tint(self, avatar_url: str, color: str, name: str = "image.png"): if not is_valid_url(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Seems the Avatar URL is Invalid. Please recheck it and make sure it startswith http or https") - avatar_url = get_exact_avatar_url(avatar_url) - if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png"): + if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png") and not isValidAvatarURL(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Avatar Format must be '.jpg' or '.png'" ) @@ -353,8 +356,7 @@ def Green(self, avatar_url: str, name: str = "image.png"): if not is_valid_url(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Seems the Avatar URL is Invalid. Please recheck it and make sure it startswith http or https") - avatar_url = get_exact_avatar_url(avatar_url) - if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png"): + if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png") and not isValidAvatarURL(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Avatar Format must be '.jpg' or '.png'" ) @@ -401,8 +403,7 @@ def Greyscale(self, avatar_url: str, name: str = "image.png"): if not is_valid_url(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Seems the Avatar URL is Invalid. Please recheck it and make sure it startswith http or https") - avatar_url = get_exact_avatar_url(avatar_url) - if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png"): + if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png") and not isValidAvatarURL(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Avatar Format must be '.jpg' or '.png'" ) @@ -449,8 +450,7 @@ def InvertGrayscale(self, avatar_url: str, name: str = "image.png"): if not is_valid_url(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Seems the Avatar URL is Invalid. Please recheck it and make sure it startswith http or https") - avatar_url = get_exact_avatar_url(avatar_url) - if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png"): + if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png") and not isValidAvatarURL(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Avatar Format must be '.jpg' or '.png'" ) @@ -497,8 +497,7 @@ def Red(self, avatar_url: str, name: str = "image.png"): if not is_valid_url(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Seems the Avatar URL is Invalid. Please recheck it and make sure it startswith http or https") - avatar_url = get_exact_avatar_url(avatar_url) - if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png"): + if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png") and not isValidAvatarURL(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Avatar Format must be '.jpg' or '.png'" ) @@ -544,8 +543,7 @@ def Sepia(self, avatar_url: str, name: str = "image.png"): if not is_valid_url(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Seems the Avatar URL is Invalid. Please recheck it and make sure it startswith http or https") - avatar_url = get_exact_avatar_url(avatar_url) - if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png"): + if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png") and not isValidAvatarURL(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Avatar Format must be '.jpg' or '.png'" ) @@ -594,8 +592,7 @@ def Threshold(self, avatar_url: str, threshold: int = 100, name: str = "image.pn if not is_valid_url(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Seems the Avatar URL is Invalid. Please recheck it and make sure it startswith http or https") - avatar_url = get_exact_avatar_url(avatar_url) - if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png"): + if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png") and not isValidAvatarURL(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Avatar Format must be '.jpg' or '.png'" ) @@ -653,8 +650,7 @@ def BisexualBorder(self, avatar_url: str, name: str = "image.png"): if not is_valid_url(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Seems the Avatar URL is Invalid. Please recheck it and make sure it startswith http or https") - avatar_url = get_exact_avatar_url(avatar_url) - if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png"): + if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png") and not isValidAvatarURL(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Avatar Format must be '.jpg' or '.png'" ) @@ -701,8 +697,7 @@ def Blur(self, avatar_url: str, name: str = "image.png"): if not is_valid_url(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Seems the Avatar URL is Invalid. Please recheck it and make sure it startswith http or https") - avatar_url = get_exact_avatar_url(avatar_url) - if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png"): + if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png") and not isValidAvatarURL(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Avatar Format must be '.jpg' or '.png'" ) @@ -836,8 +831,7 @@ def HeartCrop(self, avatar_url: str, name: str = "image.png"): if not is_valid_url(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Seems the Avatar URL is Invalid. Please recheck it and make sure it startswith http or https") - avatar_url = get_exact_avatar_url(avatar_url) - if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png"): + if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png") and not isValidAvatarURL(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Avatar Format must be '.jpg' or '.png'" ) @@ -913,8 +907,7 @@ def Horny(self, avatar_url: str, name: str = "image.png"): if not is_valid_url(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Seems the Avatar URL is Invalid. Please recheck it and make sure it startswith http or https") - avatar_url = get_exact_avatar_url(avatar_url) - if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png"): + if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png") and not isValidAvatarURL(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Avatar Format must be '.jpg' or '.png'" ) @@ -960,8 +953,7 @@ def ItsSoStupid(self, avatar_url: str, name: str = "image.png"): if not is_valid_url(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Seems the Avatar URL is Invalid. Please recheck it and make sure it startswith http or https") - avatar_url = get_exact_avatar_url(avatar_url) - if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png"): + if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png") and not isValidAvatarURL(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Avatar Format must be '.jpg' or '.png'" ) @@ -1008,8 +1000,7 @@ def Jpg(self, avatar_url: str, name: str = "image.png"): if not is_valid_url(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Seems the Avatar URL is Invalid. Please recheck it and make sure it startswith http or https") - avatar_url = get_exact_avatar_url(avatar_url) - if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png"): + if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png") and not isValidAvatarURL(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Avatar Format must be '.jpg' or '.png'" ) @@ -1055,8 +1046,7 @@ def LesbianBorder(self, avatar_url: str, name: str = "image.png"): if not is_valid_url(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Seems the Avatar URL is Invalid. Please recheck it and make sure it startswith http or https") - avatar_url = get_exact_avatar_url(avatar_url) - if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png"): + if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png") and not isValidAvatarURL(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Avatar Format must be '.jpg' or '.png'" ) @@ -1103,8 +1093,7 @@ def LGBTBorder(self, avatar_url: str, name: str = "image.png"): if not is_valid_url(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Seems the Avatar URL is Invalid. Please recheck it and make sure it startswith http or https") - avatar_url = get_exact_avatar_url(avatar_url) - if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png"): + if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png") and not isValidAvatarURL(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Avatar Format must be '.jpg' or '.png'" ) @@ -1150,8 +1139,7 @@ def Lolice(self, avatar_url: str, name: str = "image.png"): if not is_valid_url(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Seems the Avatar URL is Invalid. Please recheck it and make sure it startswith http or https") - avatar_url = get_exact_avatar_url(avatar_url) - if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png"): + if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png") and not isValidAvatarURL(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Avatar Format must be '.jpg' or '.png'" ) @@ -1202,8 +1190,7 @@ def GenshinNamecard(self, avatar_url: str, username: str, birthday: str, descrip if not is_valid_url(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Seems the Avatar URL is Invalid. Please recheck it and make sure it startswith http or https") - avatar_url = get_exact_avatar_url(avatar_url) - if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png"): + if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png") and not isValidAvatarURL(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Avatar Format must be '.jpg' or '.png'" ) @@ -1292,8 +1279,7 @@ def NonbinaryBorder(self, avatar_url: str, name: str = "image.png"): if not is_valid_url(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Seems the Avatar URL is Invalid. Please recheck it and make sure it startswith http or https") - avatar_url = get_exact_avatar_url(avatar_url) - if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png"): + if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png") and not isValidAvatarURL(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Avatar Format must be '.jpg' or '.png'" ) @@ -1419,8 +1405,7 @@ def PansexualBorder(self, avatar_url: str, name: str = "image.png"): if not is_valid_url(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Seems the Avatar URL is Invalid. Please recheck it and make sure it startswith http or https") - avatar_url = get_exact_avatar_url(avatar_url) - if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png"): + if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png") and not isValidAvatarURL(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Avatar Format must be '.jpg' or '.png'" ) @@ -1467,8 +1452,7 @@ def Pixelate(self, avatar_url: str, name: str = "image.png"): if not is_valid_url(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Seems the Avatar URL is Invalid. Please recheck it and make sure it startswith http or https") - avatar_url = get_exact_avatar_url(avatar_url) - if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png"): + if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png") and not isValidAvatarURL(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Avatar Format must be '.jpg' or '.png'" ) @@ -1549,8 +1533,7 @@ def SimpCard(self, avatar_url: str, name: str = "image.png"): if not is_valid_url(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Seems the Avatar URL is Invalid. Please recheck it and make sure it startswith http or https") - avatar_url = get_exact_avatar_url(avatar_url) - if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png"): + if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png") and not isValidAvatarURL(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Avatar Format must be '.jpg' or '.png'" ) @@ -1597,8 +1580,7 @@ def Tonikawa(self, avatar_url: str, name: str = "image.png"): if not is_valid_url(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Seems the Avatar URL is Invalid. Please recheck it and make sure it startswith http or https") - avatar_url = get_exact_avatar_url(avatar_url) - if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png"): + if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png") and not isValidAvatarURL(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Avatar Format must be '.jpg' or '.png'" ) @@ -1645,8 +1627,7 @@ def TransgenderBorder(self, avatar_url: str, name: str = "image.png"): if not is_valid_url(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Seems the Avatar URL is Invalid. Please recheck it and make sure it startswith http or https") - avatar_url = get_exact_avatar_url(avatar_url) - if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png"): + if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png") and not isValidAvatarURL(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Avatar Format must be '.jpg' or '.png'" ) @@ -1716,8 +1697,7 @@ def Tweet(self, display_name: str, username: str, avatar_url: str, comment: str, if not is_valid_url(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Seems the Avatar URL is Invalid. Please recheck it and make sure it startswith http or https") - avatar_url = get_exact_avatar_url(avatar_url) - if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png"): + if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png") and not isValidAvatarURL(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Avatar Format must be '.jpg' or '.png'" ) @@ -1773,8 +1753,7 @@ def YoutubeComment(self, username: str, avatar_url: str, comment: str, name: str if not is_valid_url(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Seems the Avatar URL is Invalid. Please recheck it and make sure it startswith http or https") - avatar_url = get_exact_avatar_url(avatar_url) - if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png"): + if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png") and not isValidAvatarURL(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Avatar Format must be '.jpg' or '.png'" ) @@ -1832,8 +1811,7 @@ def Comrade(self, avatar_url: str, name: str = "image.png"): if not is_valid_url(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Seems the Avatar URL is Invalid. Please recheck it and make sure it startswith http or https") - avatar_url = get_exact_avatar_url(avatar_url) - if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png"): + if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png") and not isValidAvatarURL(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Avatar Format must be '.jpg' or '.png'" ) @@ -1879,8 +1857,7 @@ def Gay(self, avatar_url: str, name: str = "image.png"): if not is_valid_url(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Seems the Avatar URL is Invalid. Please recheck it and make sure it startswith http or https") - avatar_url = get_exact_avatar_url(avatar_url) - if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png"): + if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png") and not isValidAvatarURL(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Avatar Format must be '.jpg' or '.png'" ) @@ -1926,8 +1903,7 @@ def Glass(self, avatar_url: str, name: str = "image.png"): if not is_valid_url(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Seems the Avatar URL is Invalid. Please recheck it and make sure it startswith http or https") - avatar_url = get_exact_avatar_url(avatar_url) - if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png"): + if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png") and not isValidAvatarURL(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Avatar Format must be '.jpg' or '.png'" ) @@ -1973,8 +1949,7 @@ def Jail(self, avatar_url: str, name: str = "image.png"): if not is_valid_url(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Seems the Avatar URL is Invalid. Please recheck it and make sure it startswith http or https") - avatar_url = get_exact_avatar_url(avatar_url) - if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png"): + if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png") and not isValidAvatarURL(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Avatar Format must be '.jpg' or '.png'" ) @@ -2020,8 +1995,7 @@ def Passed(self, avatar_url: str, name: str = "image.png"): if not is_valid_url(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Seems the Avatar URL is Invalid. Please recheck it and make sure it startswith http or https") - avatar_url = get_exact_avatar_url(avatar_url) - if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png"): + if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png") and not isValidAvatarURL(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Avatar Format must be '.jpg' or '.png'" ) @@ -2067,8 +2041,7 @@ def Triggered(self, avatar_url: str, name: str = "image.gif"): if not is_valid_url(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Seems the Avatar URL is Invalid. Please recheck it and make sure it startswith http or https") - avatar_url = get_exact_avatar_url(avatar_url) - if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png"): + if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png") and not isValidAvatarURL(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Avatar Format must be '.jpg' or '.png'" ) @@ -2114,8 +2087,7 @@ def Wasted(self, avatar_url: str, name: str = "image.png"): if not is_valid_url(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Seems the Avatar URL is Invalid. Please recheck it and make sure it startswith http or https") - avatar_url = get_exact_avatar_url(avatar_url) - if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png"): + if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png") and not isValidAvatarURL(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Avatar Format must be '.jpg' or '.png'" ) diff --git a/sra/welcome.py b/sra/welcome.py index 23363c6..bfa748c 100644 --- a/sra/welcome.py +++ b/sra/welcome.py @@ -8,15 +8,25 @@ def is_valid_url(url): pattern = re.compile( r'^https?://' - r'(?:[a-z0-9]+(?:\.[a-z0-9]+)*/)*' - r'[a-z0-9]+\.[a-z]+/?$' + r'([a-z0-9]+\.)*[a-z0-9]+\.[a-z]+/?' + r'([^\s/]+/?)+$' ) return bool(pattern.match(url)) -def get_exact_avatar_url(url): - if "?" in str(url): - url = (str(url).split("?"))[0] - return url + +def isValidAvatarURL(url): + try: + response = requests.get(url, stream=True) + content_type = response.headers.get('content-type') + if 'image' in content_type: + if 'png' in content_type: + return True + elif 'jpg' in content_type: + return True + except requests.exceptions.RequestException: + return False + return False + class WelcomeLeaveFree: """ @@ -45,8 +55,8 @@ def __get(self, template, background, type, username, avatar_url, discriminator, if not is_valid_url(avatar_url): raise sra.exceptions.InvalidAvatarURL( "Seems the Avatar URL is Invalid. Please recheck it and make sure it startswith http or https") - avatar_url = get_exact_avatar_url(avatar_url) - if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png"): + if not str(avatar_url).endswith(".jpg") and not str(avatar_url).endswith(".png") and not isValidAvatarURL( + avatar_url): raise sra.exceptions.InvalidAvatarURL( "Avatar Format must be '.jpg' or '.png'" )