Keep sending chat action
This commit is contained in:
parent
f49141ccf2
commit
d60dad1c87
1 changed files with 19 additions and 5 deletions
22
bot.py
22
bot.py
|
@ -68,6 +68,7 @@ class Bot:
|
|||
self,
|
||||
adjust_perspective=True,
|
||||
timeout: float = 10.0,
|
||||
chat_action_fn=None,
|
||||
) -> List[cv2.typing.MatLike]:
|
||||
privacy_mode = self.tapo.getPrivacyMode()
|
||||
|
||||
|
@ -99,9 +100,11 @@ class Bot:
|
|||
aruco_params = aruco.DetectorParameters()
|
||||
|
||||
t0 = time.time()
|
||||
last_chat_action = 0
|
||||
print("Taking image with ArUco markers...")
|
||||
while len(aruco_corners) < 4:
|
||||
if time.time() - t0 > timeout:
|
||||
delta = time.time() - t0
|
||||
if delta > timeout:
|
||||
a = self.last_aruco_corners.copy()
|
||||
a.update(aruco_corners)
|
||||
aruco_corners = a
|
||||
|
@ -117,6 +120,11 @@ class Bot:
|
|||
self.tapo.setDayNightMode("auto")
|
||||
return [pretty_image]
|
||||
|
||||
if delta - last_chat_action > 3:
|
||||
last_chat_action = delta
|
||||
if chat_action_fn:
|
||||
chat_action_fn()
|
||||
|
||||
ret, annotated_image = vcap.read()
|
||||
if not ret:
|
||||
continue
|
||||
|
@ -189,9 +197,15 @@ class Bot:
|
|||
return [warped, annotated_image]
|
||||
|
||||
async def _photo_command(self, chat_id: int, adjust_perspective: bool = True):
|
||||
async def chat_action_fn():
|
||||
await self.bot.send_chat_action(chat_id=chat_id, action="upload_photo")
|
||||
|
||||
photos = await self.take_photo(adjust_perspective=adjust_perspective)
|
||||
await chat_action_fn()
|
||||
|
||||
photos = await self.take_photo(
|
||||
adjust_perspective=adjust_perspective,
|
||||
chat_action_fn=lambda: asyncio.run(chat_action_fn())
|
||||
)
|
||||
jpegs = [cv2.imencode(".jpg", photo)[1].tobytes() for photo in photos]
|
||||
|
||||
media = [
|
||||
|
@ -319,7 +333,7 @@ class Bot:
|
|||
)
|
||||
|
||||
async def take_photo(
|
||||
self, adjust_perspective=True, timeout=10.0
|
||||
self, adjust_perspective=True, timeout=10.0, chat_action_fn=None
|
||||
) -> List[cv2.typing.MatLike]:
|
||||
item_state = await self._get_item_state()
|
||||
if item_state == "OFF":
|
||||
|
@ -328,7 +342,7 @@ class Bot:
|
|||
|
||||
try:
|
||||
return await asyncio.get_event_loop().run_in_executor(
|
||||
self.executor, self._take_photo_blocking, adjust_perspective, timeout
|
||||
self.executor, self._take_photo_blocking, adjust_perspective, timeout, chat_action_fn
|
||||
)
|
||||
finally:
|
||||
if item_state == "OFF":
|
||||
|
|
Loading…
Reference in a new issue