Fixed import bug with absolute paths

pull/1/head
TechieDamien 2021-11-22 18:03:48 +00:00
parent 2c0f2530a7
commit 127d3c1d59
1 changed files with 5 additions and 1 deletions

View File

@ -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)