From 127d3c1d596d4156ec415d3a3ef1c6cbc27922ad Mon Sep 17 00:00:00 2001 From: TechieDamien Date: Mon, 22 Nov 2021 18:03:48 +0000 Subject: [PATCH] Fixed import bug with absolute paths --- __init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/__init__.py b/__init__.py index b608aae..b060da5 100644 --- a/__init__.py +++ b/__init__.py @@ -80,6 +80,10 @@ class Respond(Skill): entities = self._get_entities(message) chosen_response = self._substitute_entities(chosen_response, entities) if self.callback_file != None and self.callback_name != None: - callback_module = importlib.import_module(self.callback_file) + # The following three lines allow us to import the module using an absolute path dynamically + spec = importlib.util.spec_from_file_location("callback", self.callback_file) + callback_module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(callback_module) + # Now we can get the response from the callback. chosen_response = eval("callback_module." + self.callback_name + "(message, entities)") await message.respond(chosen_response)