Allow multiple chat IDs

This commit is contained in:
Davide Depau 2024-08-11 22:15:17 +02:00
parent 9165cb9551
commit d8c93fbc49

12
bot.py
View file

@ -27,7 +27,7 @@ class Bot:
self.camera_ip = os.environ["CAMERA_IP"] self.camera_ip = os.environ["CAMERA_IP"]
self.camera_user = os.environ["CAMERA_USER"] self.camera_user = os.environ["CAMERA_USER"]
self.camera_password = os.environ["CAMERA_PASSWORD"] 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.profile_name = os.environ.get("CAMERA_PROFILE_NAME", "board")
self.openhab_url = os.environ["OPENHAB_URL"] self.openhab_url = os.environ["OPENHAB_URL"]
self.openhab_token = os.environ["OPENHAB_TOKEN"] self.openhab_token = os.environ["OPENHAB_TOKEN"]
@ -353,7 +353,11 @@ class Bot:
try: try:
return await asyncio.get_event_loop().run_in_executor( 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: finally:
if item_state == "OFF": if item_state == "OFF":
@ -374,7 +378,7 @@ class Bot:
try: try:
upd = cast(Update, await queue.get()) upd = cast(Update, await queue.get())
print(upd) 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") print("Ignoring message")
continue continue
# noinspection PyBroadException # noinspection PyBroadException
@ -384,7 +388,7 @@ class Bot:
traceback.print_exc() traceback.print_exc()
exc = traceback.format_exc() exc = traceback.format_exc()
await self.bot.send_message( await self.bot.send_message(
chat_id=self.chat_id, chat_id=upd.message.chat_id,
text=f"Error: {exc}", text=f"Error: {exc}",
) )
except Exception: except Exception: