From 4b85f54e77c12669f00983c4311a6ce56c8705bf Mon Sep 17 00:00:00 2001 From: Jeremiah K Date: Mon, 24 Apr 2023 11:33:19 -0500 Subject: [PATCH] Fixed shortened prefix formatting issue! --- .gitignore | 1 + main.py | 19 +++++++++---------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 5902cb1..4fb4462 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ .vscode config.yaml meshtastic.sqlite +__pycache__ \ No newline at end of file diff --git a/main.py b/main.py index 9c116a1..3df1e3d 100644 --- a/main.py +++ b/main.py @@ -280,12 +280,15 @@ async def on_room_message( if longname and meshnet_name: full_display_name = f"{longname}/{meshnet_name}" if meshnet_name != local_meshnet_name: + logger.info(f"Processing message from remote meshnet: {text}") short_longname = longname[:3] short_meshnet_name = meshnet_name[:4] prefix = f"{short_longname}/{short_meshnet_name}: " - logger.info(f"Processing message from remote meshnet: {text}") + text = re.sub(rf"^\[{full_display_name}\]: ", "", text) # Remove the original prefix from the text + text = truncate_message(text) + full_message = f"{prefix}{text}" else: - logger.info(f"Processing message from local meshnet: {text}") + logger.info(f"Ignoring message from local meshnet: {text}") return else: display_name_response = await matrix_client.get_displayname( @@ -294,12 +297,9 @@ async def on_room_message( full_display_name = display_name_response.displayname or event.sender short_display_name = full_display_name[:5] prefix = f"{short_display_name}[M]: " - logger.info( - f"Processing matrix message from [{full_display_name}]: {text}" - ) - - text = truncate_message(text) - full_message = f"{prefix}{text}" + logger.info(f"Processing matrix message from [{full_display_name}]: {text}") + text = truncate_message(text) + full_message = f"{prefix}{text}" room_config = None for config in matrix_rooms: @@ -314,8 +314,7 @@ async def on_room_message( logger.info( f"Sending radio message from {full_display_name} to radio broadcast" ) - meshtastic_interface.sendText( - text=full_message, channelIndex=meshtastic_channel + meshtastic_interface.sendText(text=full_message, channelIndex=meshtastic_channel ) else: logger.debug(