clean up on error

This commit is contained in:
Cyberes 2024-04-03 23:28:27 -06:00
parent 265471864f
commit 72dff170ca
1 changed files with 8 additions and 0 deletions

View File

@ -1,6 +1,7 @@
import copy
import json
import logging
import os
import shutil
import tempfile
import time
@ -112,6 +113,9 @@ class MatrixBotCallbacks:
return
zipfile_name = f'{room.room_id.replace(":", "_").replace("!", "").replace(".", "")}-{int(time.time())}.zip'
zipfile_path = None
temp_dir = None
start_msg = await self.client.room_send(
room_id=room.room_id,
message_type="m.room.message",
@ -200,3 +204,7 @@ class MatrixBotCallbacks:
'm.room.message',
content
)
if zipfile_path:
os.remove(zipfile_path)
if temp_dir:
shutil.rmtree(temp_dir)