From 20685fe15c762ecff7f487ad184c6d63e6da30a4 Mon Sep 17 00:00:00 2001 From: Cyberes Date: Wed, 3 Apr 2024 23:07:42 -0600 Subject: [PATCH] logging and more info and service --- README.md | 9 ++++++--- main.py | 6 ++++-- matrix-room-exporter.service | 13 +++++++++++++ 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b01bcc0..d30db81 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ _Export a Matrix a room._ -This is a simple bot that can export a Matrix room and upload the compressed archive to a Cloudflare R2 bucket for the -room to download. +A quick-n-dirty bot that exports a Matrix room and uploads the archive to a Cloudflare R2 bucket for the room to +download. ### Install @@ -24,4 +24,7 @@ room to download. 1. Invite the new bot to the room you want to export. 2. Send the message `!export` to start the export process. -The bot will upload the exported room to your R2 bucket and share the link with the room. \ No newline at end of file +The bot will upload the exported room to your R2 bucket and share the link with the room. + +Remember, if your room is encrypted and new members can't see old history prior to their joining then the bot won't be +able to export anything earlier than when it joined. \ No newline at end of file diff --git a/main.py b/main.py index 22cf81b..fc1cb3b 100644 --- a/main.py +++ b/main.py @@ -27,7 +27,8 @@ async def main(args): config = DEFAULT_CONFIG | yaml_config - logger.setLevel(logging.DEBUG) + logger.setLevel(logging.DEBUG if args.debug else logging.INFO) + logger.debug('Debug logging enabled!') matrix_helper = MatrixClientHelper( user_id=config['auth']['username'], @@ -39,7 +40,7 @@ async def main(args): login_success, login_response = await matrix_helper.login() if not login_success: - print(login_response) + logger.critical(f'Failed to login: {login_response}') quit(1) logger.info(f'Logged in as {client.user_id}') @@ -54,5 +55,6 @@ async def main(args): if __name__ == '__main__': parser = argparse.ArgumentParser(description='Export a Matrix room.') parser.add_argument('--config', default=Path(SCRIPT_PATH) / 'config.yml') + parser.add_argument('--debug', '-d', action='store_true', help='Enable debug logging.') args = parser.parse_args() asyncio.run(main(args)) diff --git a/matrix-room-exporter.service b/matrix-room-exporter.service index e69de29..dfb3c71 100644 --- a/matrix-room-exporter.service +++ b/matrix-room-exporter.service @@ -0,0 +1,13 @@ +[Unit] +Description=Matrix Room Exporter Bot +After=network.target + +[Service] +Type=simple +User=matrix-bots +ExecStart=/srv/matrix-room-exporter/venv/bin/python /srv/matrix-room-exporter/main.py +Restart=on-failure +RestartSec=5s + +[Install] +WantedBy=multi-user.target \ No newline at end of file