matrix-eavesdrop: fix initial room path creation

The bot is supposed to create the filesystem director for the room
path when joining, but it may have done so with a relative path
instead of the full path that is actually used for logging.

Change-Id: I8c9c19a12eb2b85797ade75358859dc06b81b0b6
This commit is contained in:
James E. Blair 2021-08-02 16:54:14 -07:00
parent 81b3e0eb90
commit 42a875b0fe

View File

@ -94,6 +94,12 @@ class Bot:
data = json.load(f)
return data
def get_room_path(self, room):
room_path = room['path']
if not room_path.startswith('/'):
room_path = os.path.join(self.config['log_dir'], room_path)
return room_path
async def join_rooms(self):
new = set()
old = set()
@ -107,7 +113,7 @@ class Bot:
# Store the canonical room id, since the one in the config
# file may be an alias
self.room_map[resp.room_id] = room
os.makedirs(room['path'], exist_ok=True)
os.makedirs(self.get_room_path(room), exist_ok=True)
for room in old-new:
self.log.info("Leave room %s", room['id'])
await self.client.room_leave(room)
@ -120,9 +126,7 @@ class Bot:
ts = datetime.datetime.utcfromtimestamp(event.server_timestamp/1000.0)
event_date = str(ts.date())
event_time = str(ts.time())[:8]
room_path = config_room['path']
if not room_path.startswith('/'):
room_path = os.path.join(self.config['log_dir'], room_path)
room_path = self.get_room_path(config_room)
filename = f'{room_name}.{event_date}.log'
logpath = os.path.join(room_path, filename)
body = event.body