这是一个批量整理提交,包含以下主要改动: 1. 删除多处冗余的空行和未使用的导入 2. 修复文件末尾缺少换行符的问题 3. 调整部分模块的导入顺序与代码排版 4. 修复部分配置默认值与策略逻辑 5. 新增多个功能模块与辅助工具 6. 完善异常处理与日志记录 7. 修复速率限制、消息缓存、权限校验等逻辑bug 8. 废弃部分旧有API与配置项并添加警告提示
29 lines
706 B
Python
29 lines
706 B
Python
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)}"
|
|
|
|
|
|
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
|