本次提交对Twitch适配器进行了全面升级与优化: 1. 修复UTF8截断逻辑,避免越界访问 2. 重构群聊策略配置,标准化mention相关规则 3. 新增消息缓存管理器,支持通过消息ID查询已发送消息 4. 更新配置schema,新增prefer_helix_send开关和deprecated策略自动转换 5. 新增CLEARMSG和ROOMSTATE IRC消息解析,补充事件订阅支持 6. 优化令牌刷新逻辑,增加重试机制与退避策略 7. 新增Helix API聊天消息发送、删除和公告功能 8. 扩展事件订阅类型,新增直播状态、频道更新等系统事件 9. 新增reply、delete_message、announcement等动作支持,完善操作能力 10. 重构流式发送逻辑,新增进度指示器和配置项 11. 优化重连策略,增加指数退避与计数重置
30 lines
753 B
Python
30 lines
753 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:
|
|
byte_limit = min(byte_limit, len(encoded))
|
|
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
|