diff options
| author | 2021-09-12 08:39:47 -0400 | |
|---|---|---|
| committer | 2021-09-12 08:39:47 -0400 | |
| commit | 68c0de59f6f31fb1123c7ed3468c4faac202d9f6 (patch) | |
| tree | a9ba81f8396f1c284c19e5a57e6570e304c1b2af | |
| parent | Merge branch 'main' of https://github.com/python-discord/sir-lancebot into co... (diff) | |
Load json file once
| -rw-r--r-- | bot/exts/utilities/color.py | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/bot/exts/utilities/color.py b/bot/exts/utilities/color.py index 6452d292..dd470197 100644 --- a/bot/exts/utilities/color.py +++ b/bot/exts/utilities/color.py @@ -25,6 +25,8 @@ ERROR_MSG = """The color code {user_color} is not a possible color combination. """ COLOR_LIST = "bot/resources/utilities/ryanzec_colours.json" +with open(COLOR_LIST) as f: + COLOR_JSON = json.load(f) # define color command @@ -197,12 +199,9 @@ class Color(commands.Cog): @staticmethod def match_color(user_color: str) -> str: """Use fuzzy matching to return a hex color code based on the user's input.""" - with open(COLOR_LIST) as f: - color_list = json.load(f) - logger.debug(f"{type(color_list) = }") - match, certainty, _ = process.extractOne(query=user_color, choices=color_list.keys(), score_cutoff=50) + match, certainty, _ = process.extractOne(query=user_color, choices=COLOR_JSON.keys(), score_cutoff=50) logger.debug(f"{match = }, {certainty = }") - hex_match = color_list[match] + hex_match = COLOR_JSON[match] logger.debug(f"{hex_match = }") return match, hex_match |