Skip to content

Commit

Permalink
Fix alias and some smaller bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
TLNBS2405 committed Dec 20, 2023
1 parent 79926cc commit d0dad7d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/module/embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

MOVE_NOT_FOUND_TITLE = 'Move not found'
SUCCESS_COLOR = discord.Colour.from_rgb(50,168,82)
ERROR_COLOR = discord.Colour.from_rgb(220,20,60)

def _upper_first_letter(input :str) -> str:
if input:
Expand All @@ -22,13 +23,13 @@ def move_list_embed(character, moves, move_type):
desc_string += move + '\n'

embed = discord.Embed(title=character.name + ' ' + move_type.lower() + ':',
colour=0x00EAFF,
colour=SUCCESS_COLOR,
description=desc_string)
return embed

def error_embed(err):
embed = discord.Embed(title='Error',
colour=0xFF4500,
colour=ERROR_COLOR,
description=err)
return embed

Expand Down
13 changes: 12 additions & 1 deletion src/module/json_movelist_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,25 @@ def _simplify_input(input: str) -> str:
input = input.lower().replace('wr', 'fff')
return input

def _is_command_in_alias(command: str, item: dict) -> bool:
if 'alias' in item:
aliases = item['alias']
for alias in aliases:
if _simplify_input(command) == _simplify_input(alias):
return True
return False

def get_move(input: str, character_movelist: dict):
result = [entry for entry in character_movelist if _simplify_input(entry["input"]) == _simplify_input(input)]

if result:
result[0]['input'] = result[0]['input'].replace("\\", "")
return result[0]
else:
result = list(filter(lambda x: (_is_command_in_alias(input, x)), character_movelist))
if result:
result[0]['input'] = result[0]['input'].replace("\\", "")
print(result[0])
return result[0]
return {}

def _correct_move_type(move_type :str) -> str:
Expand Down
17 changes: 15 additions & 2 deletions src/module/test/test_json_movelist_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def test_get_move(self):

azu_move_list = json_movelist_reader.get_movelist("azucena")
move = json_movelist_reader.get_move("d/f+1",azu_move_list)

self.assertEqual(move["id"],"Azucena-df+1")

move = json_movelist_reader.get_move("df141",azu_move_list)
self.assertEqual(move["id"],"Azucena-df+1,4,1")
move = json_movelist_reader.get_move("fc df3",azu_move_list)
Expand Down Expand Up @@ -67,4 +67,17 @@ def test_get_move(self):
self.assertEqual(move["id"],"Azucena-H.LIB.2,F")

move = json_movelist_reader.get_move("ws41",azu_move_list)
self.assertEqual(move["id"],"Azucena-ws4,1")
self.assertEqual(move["id"],"Azucena-ws4,1")

move = json_movelist_reader.get_move("LIB d+1+3",azu_move_list)
self.assertEqual(move["id"],"Azucena-LIB.d+1+3_d+2+4")

move = json_movelist_reader.get_move("LIB d2+4",azu_move_list)
self.assertEqual(move["id"],"Azucena-LIB.d+1+3_d+2+4")

jun_move_list = json_movelist_reader.get_movelist("jun")
move = json_movelist_reader.get_move("12u",jun_move_list)
self.assertEqual(move["id"],"Jun-1,2,u_d")

move = json_movelist_reader.get_move("12d",jun_move_list)
self.assertEqual(move["id"],"Jun-1,2,u_d")
2 changes: 1 addition & 1 deletion src/resources/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
'claudio': ['cld', 'cla'],
'devil_jin': ['dj', 'deviljin', 'dvj'],
'dragunov': ['drag', 'sergei', 'dragu'],
'eliza': ['elz'],
'jun': [],
'feng': ['fen'],
'hwoarang': ['hwo'],
'jack8': ['j8', 'jack-8', 'jack'],
Expand Down

0 comments on commit d0dad7d

Please sign in to comment.