From dfd5fd8940f05cc27d5126756e553ddf83ce0efd Mon Sep 17 00:00:00 2001 From: Sakimori Date: Thu, 31 Dec 2020 14:04:55 -0500 Subject: [PATCH] added the fuzzy search to startgame --- the_prestige.py | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/the_prestige.py b/the_prestige.py index b0df472..dbc08c9 100644 --- a/the_prestige.py +++ b/the_prestige.py @@ -119,14 +119,34 @@ class StartGameCommand(Command): return try: - team1 = games.get_team(command.split("\n")[1]) - team2 = games.get_team(command.split("\n")[2]) + team_name1 = command.split("\n")[1].strip() + 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]) except IndexError: try: - team1 = games.get_team(command.split("\n")[1]) - team2 = games.get_team(command.split("\n")[2]) - innings = None + team_name1 = command.split("\n")[1].strip() + 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 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.") return