01
事件钩子注册方法
通过 xchat.hook_print 和 xchat.hook_server,你可以监听几乎所有的网络输入、输出以及 UI 渲染事件,精准捕获需要处理的数据流。
import xchat
def on_channel_message(word, word_eol, userdata):
print(f"收到消息: {word[1]}")
return xchat.EAT_NONE
xchat.hook_print("Channel Message", on_channel_message)
def on_channel_message(word, word_eol, userdata):
print(f"收到消息: {word[1]}")
return xchat.EAT_NONE
xchat.hook_print("Channel Message", on_channel_message)
02
消息拦截与修改示例
利用拦截器机制,不仅可以读取消息,还能动态修改进出频道的文本内容。在回调函数中返回 xchat.EAT_ALL 即可阻断原消息显示,实现自定义过滤逻辑。
03
控制台指令绑定
使用 xchat.hook_command 将复杂的 Python 执行逻辑封装为简单的客户端斜杠指令(如 /mybot start),大幅提升日常操作的便捷度与安全性。