Skip to content

Commit a87303b

Browse files
committed
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.
1 parent c602121 commit a87303b

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

zulip_botserver/tests/server_test_lib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def assert_bot_server_response(
2929
server.app.config["BOTS_LIB_MODULES"] = bots_lib_modules
3030
if bot_handlers is None:
3131
bot_handlers = server.load_bot_handlers(
32-
available_bots, bots_config, third_party_bot_conf
32+
available_bots, bots_lib_modules, bots_config, third_party_bot_conf
3333
)
3434
message_handlers = server.init_message_handlers(
3535
available_bots, bots_lib_modules, bot_handlers

zulip_botserver/zulip_botserver/server.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def load_module_from_file(file_path: str) -> ModuleType:
122122
return lib_module
123123

124124

125-
def load_lib_modules(available_bots: List[str]) -> Dict[str, Any]:
125+
def load_lib_modules(available_bots: List[str]) -> Dict[str, ModuleType]:
126126
bots_lib_module = {}
127127
for bot in available_bots:
128128
try:
@@ -147,6 +147,7 @@ def load_lib_modules(available_bots: List[str]) -> Dict[str, Any]:
147147

148148
def load_bot_handlers(
149149
available_bots: List[str],
150+
bot_lib_modules: Dict[str, ModuleType],
150151
bots_config: Dict[str, Dict[str, str]],
151152
third_party_bot_conf: Optional[configparser.ConfigParser] = None,
152153
) -> Dict[str, lib.ExternalBotHandler]:
@@ -157,7 +158,7 @@ def load_bot_handlers(
157158
api_key=bots_config[bot]["key"],
158159
site=bots_config[bot]["site"],
159160
)
160-
bot_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "bots", bot)
161+
bot_dir = os.path.join(os.path.dirname(os.path.abspath(bot_lib_modules[bot].__file__)))
161162
bot_handler = lib.ExternalBotHandler(
162163
client, bot_dir, bot_details={}, bot_config_parser=third_party_bot_conf
163164
)
@@ -253,7 +254,9 @@ def main() -> None:
253254
third_party_bot_conf = (
254255
parse_config_file(options.bot_config_file) if options.bot_config_file is not None else None
255256
)
256-
bot_handlers = load_bot_handlers(available_bots, bots_config, third_party_bot_conf)
257+
bot_handlers = load_bot_handlers(
258+
available_bots, bots_lib_modules, bots_config, third_party_bot_conf
259+
)
257260
message_handlers = init_message_handlers(available_bots, bots_lib_modules, bot_handlers)
258261
app.config["BOTS_LIB_MODULES"] = bots_lib_modules
259262
app.config["BOT_HANDLERS"] = bot_handlers

0 commit comments

Comments
 (0)