33 lines
952 B
Python
33 lines
952 B
Python
|
|
import re
|
||
|
|
|
||
|
|
|
||
|
|
def normalize_irc_target(target: str) -> str:
|
||
|
|
target = target.strip()
|
||
|
|
target = re.sub(r"^irc:", "", target)
|
||
|
|
target = re.sub(r"^(channel|user):", "", target)
|
||
|
|
if not re.match(r"^[^\s:@!]+$", target) and not target.startswith(("#", "&")):
|
||
|
|
target = target.split("!")[0]
|
||
|
|
return target
|
||
|
|
|
||
|
|
|
||
|
|
def is_channel_target(target: str) -> bool:
|
||
|
|
return target.startswith("#") or target.startswith("&")
|
||
|
|
|
||
|
|
|
||
|
|
def build_irc_allowlist_candidates(
|
||
|
|
nick: str,
|
||
|
|
user: str | None,
|
||
|
|
host: str | None,
|
||
|
|
allow_name_matching: bool = False,
|
||
|
|
) -> list[str]:
|
||
|
|
candidates = []
|
||
|
|
nick_lower = nick.lower()
|
||
|
|
if user and host:
|
||
|
|
candidates.append(f"{nick_lower}!{user.lower()}@{host.lower()}")
|
||
|
|
if user:
|
||
|
|
candidates.append(f"{nick_lower}!{user.lower()}")
|
||
|
|
if host:
|
||
|
|
candidates.append(f"{nick_lower}@{host.lower()}")
|
||
|
|
if allow_name_matching:
|
||
|
|
candidates.append(nick_lower)
|
||
|
|
return candidates
|