added the fuzzy search to startgame

This commit is contained in:
Sakimori 2020-12-31 14:04:55 -05:00
parent 42524cb434
commit dfd5fd8940

View File

@ -119,13 +119,33 @@ class StartGameCommand(Command):
return return
try: try:
team1 = games.get_team(command.split("\n")[1]) team_name1 = command.split("\n")[1].strip()
team2 = games.get_team(command.split("\n")[2]) team1 = games.get_team(team_name1)
if team1 is None:
teams = games.search_team(team_name1.lower())
if len(teams) == 1:
team1 = teams[0]
team_name2 = command.split("\n")[2].strip()
team2 = games.get_team(team_name2)
if team2 is None:
teams = games.search_team(team_name2.lower())
if len(teams) == 1:
team2 = teams[0]
innings = int(command.split("\n")[3]) innings = int(command.split("\n")[3])
except IndexError: except IndexError:
try: try:
team1 = games.get_team(command.split("\n")[1]) team_name1 = command.split("\n")[1].strip()
team2 = games.get_team(command.split("\n")[2]) team1 = games.get_team(team_name1)
if team1 is None:
teams = games.search_team(team_name1.lower())
if len(teams) == 1:
team1 = teams[0]
team_name2 = command.split("\n")[2].strip()
team2 = games.get_team(team_name2)
if team2 is None:
teams = games.search_team(team_name2.lower())
if len(teams) == 1:
team2 = teams[0]
innings = None innings = None
except IndexError: except IndexError:
await msg.channel.send("We need at least three lines: startgame, away team, and home team are required. Optionally, the number of innings can go at the end, if you want a change of pace.") await msg.channel.send("We need at least three lines: startgame, away team, and home team are required. Optionally, the number of innings can go at the end, if you want a change of pace.")