Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
hifi authored May 9, 2024
2 parents 9e51a19 + 2ffd600 commit 66dd12f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
3 changes: 2 additions & 1 deletion heisenbridge/control_room.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,8 @@ async def cmd_status(self, args):

if self.serv.is_admin(self.user_id):
for room in self.serv.find_rooms():
users.add(room.user_id)
if room.user_id is not None: # ignore HiddenRoom
users.add(room.user_id)

users = list(users)
users.sort()
Expand Down
11 changes: 10 additions & 1 deletion heisenbridge/network_room.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ def init(self):
description="set SASL PLAIN credentials",
epilog=(
"If the network supports SASL authentication you can configure them with this command.\n"
"If your password contains special characters, use shell escaping.\n"
"Example: SASL \"pass;word\"\n"
"\n"
"Note: Bridge administrators can trivially see the stored password if they want to.\n"
),
Expand Down Expand Up @@ -252,9 +254,12 @@ def init(self):
epilog=(
"If the network you are connecting to does not support server password to identify you automatically"
" can set this to send a command before joining channels.\n"
"If your password contains special characters, use shell escaping rules to escape the entire NICKSERV"
" command, and its argument within (see example).\n"
"\n"
'Example (QuakeNet): AUTOCMD "UMODE +x; MSG -s [email protected] auth foo bar"\n'
"Example (OFTC): AUTOCMD NICKSERV -s identify foo bar\n"
"Example (special characters): AUTOCMD \"NICKSERV -s \\\"identify special;'chars\\\"\"\n"
),
)
cmd.add_argument("command", nargs="*", help="commands separated with ';'")
Expand Down Expand Up @@ -344,7 +349,11 @@ def init(self):
cmd = CommandParser(
prog="NICKSERV",
description="send a message to NickServ (if supported by network)",
epilog="Alias: NS",
epilog=(
"If your password contains special characters, use shell escaping.\n"
"Example: NICKSERV \"identify pass;word\"\n"
"Alias: NS"
),
)
cmd.add_argument("-s", "--sensitive", action="store_true", help="hide message content from network room")
cmd.add_argument("message", nargs="+", help="message")
Expand Down
22 changes: 20 additions & 2 deletions heisenbridge/private_room.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ class PrivateRoom(Room):
use_pastebin = False
use_reacts = False
force_forward = False
prefix_all = False

commands: CommandManager

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

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 @@ -422,6 +429,9 @@ def from_config(self, config: dict) -> None:
if "use_reacts" in config:
self.use_reacts = config["use_reacts"]

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 @@ -448,6 +458,7 @@ def to_config(self) -> dict:
"max_lines": self.max_lines,
"use_pastebin": self.use_pastebin,
"use_reacts": self.use_reacts,
"prefix_all": self.prefix_all,
}

@staticmethod
Expand Down Expand Up @@ -717,8 +728,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 @@ -907,6 +918,13 @@ async def cmd_reacts(self, args) -> None:

self.send_notice(f"Reacts are {'enabled' if self.use_reacts 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 66dd12f

Please sign in to comment.