Files
ai-chat-system/services/__pycache__/matrix_service.cpython-310.pyc

46 lines
4.8 KiB
Plaintext
Raw Normal View History

o
<00><><EFBFBD>ir<00>@s<>dZddlZddlZddlmZmZddlmZmZm Z m
Z
m Z ddl Z ddl mZmZmZmZmZmZddlmZe <0C>e<17>ZGdd<08>d<08>Ze<19>ZdS) u.
Matrix Bot 服务 - 处理Matrix消息收发
<EFBFBD>N)<02>Optional<61>Callable)<05> AsyncClient<6E>
MatrixRoom<EFBFBD>RoomMessageText<78> LoginResponse<73> SyncResponse)<06> SessionLocal<61>User<65> Conversation<6F>Message<67>MatrixRoomMapping<6E> SystemConfig)<01>ConversationServicec@sveZdZdd<02>Zdd<04>Zdd<06>Zddefd d
<EFBFBD>Zd ed e fd d<0E>Z
de de fdd<12>Z de de e fdd<16>Zdd<18>ZdS)<1A> MatrixBotcCs(d|_d|_d|_d|_d|_d|_dS)N<>F)<06>client<6E>
homeserver<EFBFBD>username<6D>password<72>
is_running<EFBFBD>on_message_callback<63><01>self<6C>r<00>M/home/xian/.openclaw/workspace-coder/works/ai-chat/services/matrix_service.py<70>__init__s 
zMatrixBot.__init__c<00>s<><00>t<00>}zCdd<02>|<01>t<02><01><03>D<00>}|<02>dd<04>|_|<02>dd<06>|_|<02>dd<06>|_|jr:|jrA|<00><08>IdHW|<01> <09>dSW|<01> <09>dSW|<01> <09>dS|<01> <09>w) u从数据库配置初始化cSsi|]}|j|j<01>qSr)<02>key<65>value)<02>.0<EFBFBD>crrr<00>
<dictcomp>sz.MatrixBot.init_from_config.<locals>.<dictcomp><3E>matrix_homeserverzhttps://matrix.tphai.com<6F>matrix_usernamer<00>matrix_passwordN)
r <00>queryr<00>all<6C>getrrr<00>connect<63>close)r<00>db<64>configsrrr<00>init_from_configs<02>  <02> <02>zMatrixBot.init_from_configc
<00>s<><00>|jr|jst<02>d<01>dSz1t|j|j<01>|_|j<05>|j<07>IdH}t|t <09>r5t<02>
d|j<01><00><02>d|_ WdSt<02> d|<01><00><02>WdSt yZ}zt<02> d|<02><00><02>WYd}~dSd}~ww)u连接到Matrix服务器u$Matrix配置不完整跳过连接FNuMatrix连接成功: TuMatrix登录失败: uMatrix连接错误: )rr<00>logger<65>warningrr<00>loginr<00>
isinstancer<00>infor<00>error<6F> Exception)r<00>response<73>errrr('s$<02> 

<08><02>zMatrixBot.connectN<74>message_handlerc<00>s:<00>|jsdS||_|j<00>|jt<04>|jjdd<03>IdHdS)u开始同步消息Ni0u)<01>timeout)rr<00>add_event_callback<63>_handle_room_messager<00> sync_forever)rr6rrr<00>
start_sync<s <02>zMatrixBot.start_sync<6E>room<6F>eventc <00>s$<00>|j|jkr dSt<02>}z<>t|<03>}|j}|j||j<05>|i<00><02>d|<05>d|d<04>}|<03>t<08><01> tj
|j
k<02><01> <0B>}|sZ|j |j d|j<0E><00>d<06>}t|j
|j |j d<07>}|<03>|<07>|<03><10>|<03>|<07>|j|jd|jd|j|j
d <09>d
<EFBFBD>|jr<>|j|jj|j|j|j
d <0B>IdHW|<03><19>dSW|<03><19>dS|<03><19>w) u处理收到的房间消息N<E681AF> display_name<6D>matrix)<04>user_idr><00> user_type<70>matrix_user_idzMatrix: )<01>title)<03>room_idr@<00>conversation_id<69>user)<02>event_idrD)rE<00>role<6C>content<6E>source<63>
extra_data)rE<00> user_messager@rD)<1A>senderrr r<00>get_or_create_user<65>usersr'r%r <00>filterrD<00>first<73>create_conversation<6F>idr><00>add<64>commit<69>refresh<73> add_messagerE<00>bodyrGr<00> conversationr@r)) rr<r=r*<00> conv_servicerBrF<00>mappingrYrrrr9IsZ<02> <06>

<02><02><06>

 <06> <0E> <02>zMatrixBot._handle_room_messagerD<00>messagec
<00>sh<00>|jsdSz|jj|dd|d<04>d<05>IdHWdSty3}zt<03>d|<03><00><02>WYd}~dSd}~ww) u发送消息到Matrix房间Fzm.room.messagezm.text)<02>msgtyperX)rD<00> message_typerINTu发送Matrix消息失败: )r<00> room_sendr3r-r2)rrDr\r5rrr<00> send_message<67>s"<02><04> <0C><08><02>zMatrixBot.send_message<67>user_matrix_id<69>returnc<00>sp<00>t<00>}z.|<02>t<02><01>tj|k<02><01><05>}|r,|<02>t<06><01>tj|jk<02><01><05>}|r,|j W|<02>
<EFBFBD>SW|<02>
<EFBFBD>dS|<02>
<EFBFBD>w)u 获取与用户的对话房间IDN) r r%r
rPrBrQr r@rSrDr))rrar*rFr[rrr<00>get_room_id_for_user<65>s<02>

<02><02>
<02>zMatrixBot.get_room_id_for_userc<00>s6<00>|jr|j<00><01>IdH|j<00><02>IdHd|_dSdS)u 断开连接NF)r<00>logoutr)rrrrr<00>
disconnect<EFBFBD>s <02>
<04>zMatrixBot.disconnect)N)<10>__name__<5F>
__module__<EFBFBD> __qualname__rr,r(rr;rrr9<00>strr`rrcrerrrrrs 8 r)<1B>__doc__<5F>asyncio<69>json<6F>typingrr<00>niorrrrr<00>logging<6E>modelsr r
r r r r<00>services.conversation_servicer<00> getLoggerrfr-r<00>
matrix_botrrrr<00><module>s