Added max_duration retrieval and usage

This commit is contained in:
Joan
2023-09-26 17:25:23 +02:00
parent 713dfc3bb0
commit ea529ef6de

View File

@@ -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}")