From 0ef6f01685faedaaf4ab439f8b68f3136a03ad81 Mon Sep 17 00:00:00 2001 From: missytake Date: Mon, 10 Nov 2025 13:06:17 +0100 Subject: [PATCH] api(jsonrpc): add run_until parameter for bots --- .../src/deltachat_rpc_client/_utils.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/deltachat-rpc-client/src/deltachat_rpc_client/_utils.py b/deltachat-rpc-client/src/deltachat_rpc_client/_utils.py index 47d9b878cd..d9b1484182 100644 --- a/deltachat-rpc-client/src/deltachat_rpc_client/_utils.py +++ b/deltachat-rpc-client/src/deltachat_rpc_client/_utils.py @@ -27,6 +27,10 @@ def _to_attrdict(obj): return obj +def _forever(): + return False + + class AttrDict(dict): """Dictionary that allows accessing values using the "dot notation" as attributes.""" @@ -46,6 +50,7 @@ def __setattr__(self, attr, val): def run_client_cli( hooks: Optional[Iterable[Tuple[Callable, Union[type, "EventFilter"]]]] = None, + until: func = _forever, argv: Optional[list] = None, **kwargs, ) -> None: @@ -55,10 +60,11 @@ def run_client_cli( """ from .client import Client - _run_cli(Client, hooks, argv, **kwargs) + _run_cli(Client, until, hooks, argv, **kwargs) def run_bot_cli( + until: func = _forever, hooks: Optional[Iterable[Tuple[Callable, Union[type, "EventFilter"]]]] = None, argv: Optional[list] = None, **kwargs, @@ -69,11 +75,12 @@ def run_bot_cli( """ from .client import Bot - _run_cli(Bot, hooks, argv, **kwargs) + _run_cli(Bot, until, hooks, argv, **kwargs) def _run_cli( client_type: Type["Client"], + until: func = _forever, hooks: Optional[Iterable[Tuple[Callable, Union[type, "EventFilter"]]]] = None, argv: Optional[list] = None, **kwargs, @@ -111,7 +118,7 @@ def _run_cli( kwargs={"email": args.email, "password": args.password}, ) configure_thread.start() - client.run_forever() + client.run_until(until) def extract_addr(text: str) -> str: