From d8c93fbc4961484d6b0887c249414141b1ab91e8 Mon Sep 17 00:00:00 2001 From: Davide Depau Date: Sun, 11 Aug 2024 22:15:17 +0200 Subject: [PATCH] Allow multiple chat IDs --- bot.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/bot.py b/bot.py index 95dffa2..4d4ed26 100644 --- a/bot.py +++ b/bot.py @@ -27,7 +27,7 @@ class Bot: self.camera_ip = os.environ["CAMERA_IP"] self.camera_user = os.environ["CAMERA_USER"] self.camera_password = os.environ["CAMERA_PASSWORD"] - self.chat_id = int(os.environ["CHAT_ID"]) + self.chat_ids = list(map(int, os.environ["CHAT_ID"].split(","))) self.profile_name = os.environ.get("CAMERA_PROFILE_NAME", "board") self.openhab_url = os.environ["OPENHAB_URL"] self.openhab_token = os.environ["OPENHAB_TOKEN"] @@ -353,7 +353,11 @@ class Bot: try: return await asyncio.get_event_loop().run_in_executor( - self.executor, self._take_photo_blocking, adjust_perspective, timeout, chat_action_fn + self.executor, + self._take_photo_blocking, + adjust_perspective, + timeout, + chat_action_fn, ) finally: if item_state == "OFF": @@ -374,7 +378,7 @@ class Bot: try: upd = cast(Update, await queue.get()) print(upd) - if not upd.message or upd.message.chat_id != self.chat_id: + if not upd.message or upd.message.chat_id not in self.chat_ids: print("Ignoring message") continue # noinspection PyBroadException @@ -384,7 +388,7 @@ class Bot: traceback.print_exc() exc = traceback.format_exc() await self.bot.send_message( - chat_id=self.chat_id, + chat_id=upd.message.chat_id, text=f"Error: {exc}", ) except Exception: