Skip to content

Commit

Permalink
Refactor code to use keyword arguments in generate_code_snippet funct…
Browse files Browse the repository at this point in the history
…ion and add validators module
  • Loading branch information
Zingzy committed Feb 8, 2024
1 parent a0b77b7 commit 18effa7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion cogs/getcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async def get_code(self, interaction: discord.Interaction, language:app_commands

await interaction.response.defer()

code, lang = generate_code_snippet(language.value, url, alias, max_clicks, password)
code, lang = generate_code_snippet(language=language.value, long_url=url, alias=alias, max_clicks=max_clicks, password=password)

soft_errors = []

Expand Down
1 change: 1 addition & 0 deletions constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import random
import datetime
import random
import validators

load_dotenv()

Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ discord.py
python-dotenv
requests
py_spoo_url
flask
flask
validators
26 changes: 15 additions & 11 deletions utils_code.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
from typing import Literal
import re
import validators

available_languages = [
"Python-Requests",
Expand Down Expand Up @@ -472,7 +473,7 @@ async def main():
"kotlin",
)

elif language == "Node.js-Request":
elif language == "Node.js-Requests":
form_params = f"url: '{long_url}'"

if alias is not None:
Expand Down Expand Up @@ -755,18 +756,21 @@ def validate_password(password):
return True


def validate_url(url):
pattern = re.compile(
r"^(https?:\/\/)?(www\.)?[a-zA-Z0-9]+([\-\.]{1}[a-zA-Z0-9]+)*\.[a-zA-Z]{2,6}(\:[0-9]{1,5})?(\/.*)?$"
)
# def validate_url(url):
# pattern = re.compile(
# r"^(https?:\/\/)?(www\.)?[a-zA-Z0-9]+([\-\.]{1}[a-zA-Z0-9]+)*\.[a-zA-Z]{2,6}(\:[0-9]{1,5})?(\/.*)?$"
# )

if "spoo.me" in url:
return False
# if "spoo.me" in url:
# return False

if re.fullmatch(pattern, url):
return True
else:
return False
# if re.fullmatch(pattern, url):
# return True
# else:
# return False

def validate_url(url):
return validators.url(url, skip_ipv4_addr=True, skip_ipv6_addr=True) and not "spoo.me" in url


def validate_string(string):
Expand Down

0 comments on commit 18effa7

Please sign in to comment.