Extend room setup logic to invites also

Closes #4.
This commit is contained in:
Luke Murphy 2021-02-27 11:30:44 +01:00
parent 86c8495e88
commit d41e4b80bd
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC

View File

@ -129,28 +129,37 @@ logbot @uptime: To check how long @logbot has been around
@bots: To see who is around :)
"""
def _parse_room_name(self, room):
"""Parse room name from entire address string."""
return str(re.match(r".*@", room).group()).replace("@", "")
def _setup_room(self, room):
"""Create directories and database entries for a new room."""
room_name = self._parse_room_name(room)
room_path = os.path.join(self.output, room_name)
self.log.info(f"Processing setup logic for: {room_path}")
if room not in self.db.keys():
self.db[room] = {}
self.db[room]["messages"] = {}
self.db[room]["title"] = room
self.log.info(f"Added to the database: { room }")
if not os.path.exists(room_path):
os.mkdir(room_path)
shutil.copy("stylesheet.css", room_path)
self.log.info(f"Created a folder for: { room }")
self.log.info(f"Copied stylesheet.css to: { room }")
def setup(self):
self.log.info(f"Output folder is set to: { self.output }")
for room in self.rooms:
self._setup_room(room)
roomname = str(re.match(r".*@", room).group()).replace("@", "")
room_path = os.path.join(self.output, roomname)
self.log.info(f"Processing setup logic for: {room_path}")
# Check if the room is in the database already
if not room in self.db.keys():
self.db[room] = {}
self.db[room]["messages"] = {}
self.db[room]["title"] = room
self.log.info(f"Added to the database: { room }")
# Check if the room has an output folder already
if not os.path.exists(room_path):
os.mkdir(room_path)
shutil.copy("stylesheet.css", room_path)
self.log.info(f"Created a folder for: { room }")
self.log.info(f"Copied stylesheet.css to: { room }")
def group_invite(self, message):
"""Extend xbotlib invite response logic and do required room setup."""
super().group_invite(message)
self._setup_room(message.room)
def group(self, message):