diff --git a/telemovris/telemovris.py b/telemovris/telemovris.py index b325c49..87e59ae 100644 --- a/telemovris/telemovris.py +++ b/telemovris/telemovris.py @@ -62,7 +62,7 @@ def generate_audio(message_text): return audio_name, get_audio_duration(audio_name) -async def main(user, message_text, audio): +async def main(user, message_text, audio, max_duration): async with client: audio_name, audio_duration = generate_audio(message_text) @@ -90,7 +90,7 @@ async def main(user, message_text, audio): t2 = time.perf_counter() await asyncio.sleep(1) try: - if call.ctrl.call_duration > audio_duration or call_has_ended or (call.state == CallState.WAITING and int(t2-t1) > min(30, RING_WAIT_TIME)) or call.ctrl.call_duration > MAX_CALL_DURATION: + if call.ctrl.call_duration > audio_duration or call_has_ended or (call.state == CallState.WAITING and int(t2-t1) > min(30, RING_WAIT_TIME)) or call.ctrl.call_duration > MAX_CALL_DURATION or call.ctrl.call_duration > max_duration: logging.info("Finishing call because of duration") await call.discard_call() break @@ -110,8 +110,9 @@ while True: user = response_json["user"] message = response_json["message"] audio = response_json["audio"] + max_duration = response_json["max_duration"] logging.info(f"Calling {user}") - loop.run_until_complete(main(f"@{user}", message, audio)) + loop.run_until_complete(main(f"@{user}", message, audio, max_duration)) logging.info("Call finished") except Exception as e: logging.info(f"Error: {e}")