Skip to content

Commit

Permalink
Setting to insert prefix on all lines of a multi-line message
Browse files Browse the repository at this point in the history
This is helpful for some client scripts to unwrap the bridged messages
  • Loading branch information
russss authored and hifi committed May 9, 2024
1 parent 3fec8b5 commit b8febdb
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions heisenbridge/private_room.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ class PrivateRoom(Room):
max_lines = 0
use_pastebin = False
force_forward = False
prefix_all = False

commands: CommandManager

Expand Down Expand Up @@ -402,6 +403,12 @@ def init(self) -> None:
cmd.set_defaults(enabled=None)
self.commands.register(cmd, self.cmd_pastebin)

cmd = CommandParser(prog="PREFIXALL", description="prefix all bridged IRC lines with the user's nick, instead of just the first")
cmd.add_argument("--enable", dest="enabled", action="store_true", help="Prefix all lines")
cmd.add_argument("--disable", dest="enabled", action="store_false", help="Only prefix first line")
cmd.set_defaults(enabled=None)
self.commands.register(cmd, self.cmd_prefix_all)

self.mx_register("m.room.message", self.on_mx_message)
self.mx_register("m.room.redaction", self.on_mx_redaction)

Expand All @@ -412,6 +419,9 @@ def from_config(self, config: dict) -> None:
if "use_pastebin" in config:
self.use_pastebin = config["use_pastebin"]

if "prefix_all" in config:
self.prefix_all = config["prefix_all"]

if "name" not in config:
raise Exception("No name key in config for ChatRoom")

Expand All @@ -438,6 +448,7 @@ def to_config(self) -> dict:
"media": self.media[:5],
"max_lines": self.max_lines,
"use_pastebin": self.use_pastebin,
"prefix_all": self.prefix_all,
}

@staticmethod
Expand Down Expand Up @@ -706,8 +717,8 @@ async def _process_event_content(self, event, prefix, reply_to=None):
messages = []

for i, line in enumerate(lines):
# prefix first line if needed
if i == 0 and prefix and len(prefix) > 0:
# prefix line if needed
if (i == 0 or self.prefix_all) and prefix and len(prefix) > 0:
line = prefix + line

# filter control characters except ZWSP
Expand Down Expand Up @@ -886,6 +897,13 @@ async def cmd_pastebin(self, args) -> None:

self.send_notice(f"Pastebin is {'enabled' if self.use_pastebin else 'disabled'}")

async def cmd_prefix_all(self, args) -> None:
if args.enabled is not None:
self.prefix_all = args.enabled
await self.save()

self.send_notice(f"Prefix all is {'enabled' if self.prefix_all else 'disabled'}")

async def _attach_hidden_room_internal(self) -> None:
await self.az.intent.send_state_event(
self.id,
Expand Down

0 comments on commit b8febdb

Please sign in to comment.