Skip to content

Commit

Permalink
fix: correct imports transformers.py
Browse files Browse the repository at this point in the history
  • Loading branch information
tylovejoy committed May 19, 2024
1 parent f153312 commit 1011674
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
5 changes: 4 additions & 1 deletion utilities/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,8 @@
"split_nth_conditional",
"errors",
"translations",
"URLTransformer"
"URLTransformer",
"fuzz_",
"fuzz_multiple",
"CODE_VERIFICATION",
]
25 changes: 12 additions & 13 deletions utilities/transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@

from discord import app_commands

import utilities.utils
import utils
from utils import utils
from utilities import errors
import utilities

if TYPE_CHECKING:
from core import DoomItx
Expand All @@ -20,8 +19,8 @@ def sanitize_map_code_input(value: str) -> str:
class MapCodeFormattingTransformer(app_commands.Transformer):
async def transform(self, itx: DoomItx, value: str) -> str:
value = sanitize_map_code_input(value)
if not re.match(utilities.utils.CODE_VERIFICATION, value):
raise utils.IncorrectCodeFormatError
if not re.match(utilities.CODE_VERIFICATION, value):
raise errors.IncorrectCodeFormatError
return value


Expand All @@ -31,7 +30,7 @@ async def transform(self, itx: DoomItx, value: str) -> str:
query = "SELECT EXISTS(SELECT 1 FROM maps WHERE maps.map_code=$1);"
exists = await itx.client.database.fetchval(query, transformed)
if not exists:
raise utils.InvalidMapCodeError
raise errors.InvalidMapCodeError
return value


Expand All @@ -54,7 +53,7 @@ async def transform(self, itx: DoomItx, value: str) -> int:
query = "SELECT user_id FROM users ORDER BY similarity(nickname, $1) LIMIT 1"
user_id = await itx.client.database.fetchval(query, value)
if not user_id:
raise utils.UserNotFoundError
raise errors.UserNotFoundError
return int(user_id)

async def autocomplete(self, itx: DoomItx, value: str) -> list[app_commands.Choice[str]] | None:
Expand Down Expand Up @@ -100,7 +99,7 @@ async def transform(self, itx: DoomItx, value: str) -> str:
level_name = await itx.client.database.fetchval(query, itx.namespace.map_code, value)
if not level_name:
level_names = await itx.client.database.fetch_level_names_of_map_code(itx.namespace.map_code)
return utilities.utils.fuzz_(value, level_names)
return utilities.fuzz_(value, level_names)
return level_name

async def autocomplete(self, itx: DoomItx, value: str) -> list[app_commands.Choice[str]] | None:
Expand All @@ -122,8 +121,8 @@ class MapNameTransformer(app_commands.Transformer):
async def transform(self, itx: DoomItx, value: str) -> str:
map_names = await itx.client.database.fetch_all_map_names()
if not map_names:
raise utils.InvalidMapNameError
return utilities.utils.fuzz_(value, map_names)
raise errors.InvalidMapNameError
return utilities.fuzz_(value, map_names)

async def autocomplete(self, itx: DoomItx, value: str) -> list[app_commands.Choice[str]] | None:
map_names = await itx.client.database.fetch_similar_map_names(value)
Expand All @@ -136,8 +135,8 @@ class MapTypeTransformer(app_commands.Transformer):
async def transform(self, itx: DoomItx, value: str) -> str:
map_types = await itx.client.database.fetch_all_map_types()
if not map_types:
raise utils.InvalidMapTypeError
return utilities.utils.fuzz_(value, map_types)
raise errors.InvalidMapTypeError
return utilities.fuzz_(value, map_types)

async def autocomplete(self, itx: DoomItx, value: str) -> list[app_commands.Choice[str]] | None:
map_types = await itx.client.database.fetch_similar_map_types(value)
Expand All @@ -153,5 +152,5 @@ async def transform(self, itx: DoomItx, value: str) -> str:
value = "https://" + value
async with itx.client.session.get(value) as resp:
if resp.status != 200:
raise utils.IncorrectURLFormatError
raise errors.IncorrectURLFormatError
return str(resp.url)

0 comments on commit 1011674

Please sign in to comment.