2026-05-12 00:50:10 +08:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def format_privmsg_line(target: str, text: str) -> str:
|
|
|
|
|
return f"PRIVMSG {target} :{text}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def format_action_line(target: str, text: str) -> str:
|
|
|
|
|
return f"PRIVMSG {target} :\x01ACTION {text}\x01"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def format_pong(token: str) -> str:
|
|
|
|
|
return f"PONG :{token}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def format_cap_req(capabilities: list[str]) -> str:
|
|
|
|
|
return f"CAP REQ :{' '.join(capabilities)}"
|
2026-05-12 14:51:53 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def find_utf8_cut(encoded: bytes, byte_limit: int) -> int:
|
|
|
|
|
cut = byte_limit
|
|
|
|
|
while cut > 0 and (encoded[cut - 1] & 0xC0) == 0x80:
|
|
|
|
|
cut -= 1
|
|
|
|
|
while cut > 0 and (encoded[cut - 1] & 0xC0) == 0xC0:
|
|
|
|
|
cut -= 1
|
|
|
|
|
if cut == 0:
|
|
|
|
|
cut = max(1, byte_limit)
|
|
|
|
|
return cut
|