zulip_botserver: Fix path finding for external bots.
The previous implementation to locate the `bot_dir` is unfortunately wrong as it doesn't work with the external custom bots.
This commit is contained in:
parent
c602121171
commit
a87303beb1
|
@ -29,7 +29,7 @@ class BotServerTestCase(TestCase):
|
||||||
server.app.config["BOTS_LIB_MODULES"] = bots_lib_modules
|
server.app.config["BOTS_LIB_MODULES"] = bots_lib_modules
|
||||||
if bot_handlers is None:
|
if bot_handlers is None:
|
||||||
bot_handlers = server.load_bot_handlers(
|
bot_handlers = server.load_bot_handlers(
|
||||||
available_bots, bots_config, third_party_bot_conf
|
available_bots, bots_lib_modules, bots_config, third_party_bot_conf
|
||||||
)
|
)
|
||||||
message_handlers = server.init_message_handlers(
|
message_handlers = server.init_message_handlers(
|
||||||
available_bots, bots_lib_modules, bot_handlers
|
available_bots, bots_lib_modules, bot_handlers
|
||||||
|
|
|
@ -122,7 +122,7 @@ def load_module_from_file(file_path: str) -> ModuleType:
|
||||||
return lib_module
|
return lib_module
|
||||||
|
|
||||||
|
|
||||||
def load_lib_modules(available_bots: List[str]) -> Dict[str, Any]:
|
def load_lib_modules(available_bots: List[str]) -> Dict[str, ModuleType]:
|
||||||
bots_lib_module = {}
|
bots_lib_module = {}
|
||||||
for bot in available_bots:
|
for bot in available_bots:
|
||||||
try:
|
try:
|
||||||
|
@ -147,6 +147,7 @@ def load_lib_modules(available_bots: List[str]) -> Dict[str, Any]:
|
||||||
|
|
||||||
def load_bot_handlers(
|
def load_bot_handlers(
|
||||||
available_bots: List[str],
|
available_bots: List[str],
|
||||||
|
bot_lib_modules: Dict[str, ModuleType],
|
||||||
bots_config: Dict[str, Dict[str, str]],
|
bots_config: Dict[str, Dict[str, str]],
|
||||||
third_party_bot_conf: Optional[configparser.ConfigParser] = None,
|
third_party_bot_conf: Optional[configparser.ConfigParser] = None,
|
||||||
) -> Dict[str, lib.ExternalBotHandler]:
|
) -> Dict[str, lib.ExternalBotHandler]:
|
||||||
|
@ -157,7 +158,7 @@ def load_bot_handlers(
|
||||||
api_key=bots_config[bot]["key"],
|
api_key=bots_config[bot]["key"],
|
||||||
site=bots_config[bot]["site"],
|
site=bots_config[bot]["site"],
|
||||||
)
|
)
|
||||||
bot_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "bots", bot)
|
bot_dir = os.path.join(os.path.dirname(os.path.abspath(bot_lib_modules[bot].__file__)))
|
||||||
bot_handler = lib.ExternalBotHandler(
|
bot_handler = lib.ExternalBotHandler(
|
||||||
client, bot_dir, bot_details={}, bot_config_parser=third_party_bot_conf
|
client, bot_dir, bot_details={}, bot_config_parser=third_party_bot_conf
|
||||||
)
|
)
|
||||||
|
@ -253,7 +254,9 @@ def main() -> None:
|
||||||
third_party_bot_conf = (
|
third_party_bot_conf = (
|
||||||
parse_config_file(options.bot_config_file) if options.bot_config_file is not None else None
|
parse_config_file(options.bot_config_file) if options.bot_config_file is not None else None
|
||||||
)
|
)
|
||||||
bot_handlers = load_bot_handlers(available_bots, bots_config, third_party_bot_conf)
|
bot_handlers = load_bot_handlers(
|
||||||
|
available_bots, bots_lib_modules, bots_config, third_party_bot_conf
|
||||||
|
)
|
||||||
message_handlers = init_message_handlers(available_bots, bots_lib_modules, bot_handlers)
|
message_handlers = init_message_handlers(available_bots, bots_lib_modules, bot_handlers)
|
||||||
app.config["BOTS_LIB_MODULES"] = bots_lib_modules
|
app.config["BOTS_LIB_MODULES"] = bots_lib_modules
|
||||||
app.config["BOT_HANDLERS"] = bot_handlers
|
app.config["BOT_HANDLERS"] = bot_handlers
|
||||||
|
|
Loading…
Reference in a new issue