Feat/matrix bot configurable paths#4
Merged
Conversation
…fter initial sync Restructures the Matrix bot's main function to: 1. Define callback handlers as regular async functions. 2. Perform an initial `client.sync()` after successful login. 3. Register event callbacks using `client.add_event_callback()` only after the initial sync has completed. This ensures the `AsyncClient` object is fully initialized and ready before event handlers are attached, preventing the `AttributeError: 'AsyncClient' object has no attribute 'on'` that occurred when using decorators before the client was in a ready state.
merge back updates
This commit implements several changes to runtime behavior:
1. Refines sync and callback registration: Callbacks are now registered
immediately after login, followed by a single `sync_forever(full_state=True)`
call. This aims to improve the responsiveness of invite handling.
2. Prevents processing of old messages: The bot now records its startup
time and ignores any messages with a `server_timestamp` older than
this, preventing it from acting on historical messages when joining a room.
3. Modifies reply message format: The bot now replies with only the
substituted link, instead of including `(source: <original_link>)`.
Removes the erroneous `nonlocal bot_startup_time` declaration from the `main` function's scope that was causing a SyntaxError. `bot_startup_time` is now initialized at the start of `main` and its value is set before callbacks are registered. The `message_handler_callback` reads this value from its enclosing scope without needing a `nonlocal` declaration for reading.
- Makes URL detection regex in `find_links_in_text` case-insensitive. - Dynamically adds `x.com` as an alternative domain for `twitter.com` in the loaded service configuration, allowing the bot to recognize x.com links as Twitter links. - Updates README to mention these features.
- Modifies `mk_newlinks` to convert the input URL's netloc to lowercase before matching against `SERVICES` keys and `alt_domains`. - Ensures that `alt_domains` from `services.json` are also compared in lowercase. - Ensures that the `service` field from `alts.json` is compared in lowercase against the matched service key. - This complements the existing `re.IGNORECASE` in `find_links_in_text` to provide more robust case-insensitive link processing.
- Modifies `matrix_bot.py` to read the `LOG_LEVEL` environment variable (defaulting to INFO) and set the Python logging level accordingly. - Adds `LOG_LEVEL` to `.env.example`. - Updates `README.md` to document the new `LOG_LEVEL` configuration option.
Reverts the callback registration mechanism from decorators back to using `client.add_event_callback()`. Callbacks are defined as regular async functions and then registered explicitly after client login and before the main sync loop starts. This addresses the `AttributeError: 'AsyncClient' object has no attribute 'on'` that occurred when decorators were used within the main async function.
- Removes all automatic invitation handling logic. The bot will now only
operate in rooms it is already a member of (must be manually added).
- Implements session persistence using `matrix-nio`'s client store.
- Adds `MATRIX_BOT_STORE_PATH` env var to specify store location.
- Bot attempts to load session from store; uses password only for initial
login or if store is invalid.
- Updates Dockerfile to create a default store directory (`/app/store`).
- Updates docker-compose.yml to mount a host volume (`./matrix_bot_data/store`)
to `/app/store` for persisting the session data.
- Updates `.env.example` and `README.md` to reflect these significant changes
in configuration and operation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.