55from loguru import logger
66
77from WechatAPI import WechatAPIClient
8+ from WechatAPI .Client .protect import protector
89from utils .event_manager import EventManager
910
1011
@@ -19,10 +20,13 @@ def __init__(self, bot_client: WechatAPIClient):
1920 with open ("main_config.toml" , "rb" ) as f :
2021 main_config = tomllib .load (f )
2122
23+ self .ignore_protection = main_config .get ("XYBot" , {}).get ("ignore-protection" , False )
24+
2225 self .ignore_mode = main_config .get ("XYBot" , {}).get ("ignore-mode" , "" )
2326 self .whitelist = main_config .get ("XYBot" , {}).get ("whitelist" , [])
2427 self .blacklist = main_config .get ("XYBot" , {}).get ("blacklist" , [])
2528
29+
2630 def update_profile (self , wxid : str , nickname : str , alias : str , phone : str ):
2731 """更新机器人信息"""
2832 self .wxid = wxid
@@ -66,7 +70,10 @@ async def process_message(self, message: Dict[str, Any]):
6670 await self .process_system_message (message )
6771
6872 elif msg_type == 37 : # 好友请求
69- await EventManager .emit ("friend_request" , self .bot , message )
73+ if self .ignore_protection or not protector .check (14400 ):
74+ await EventManager .emit ("friend_request" , self .bot , message )
75+ else :
76+ logger .warning ("风控保护: 新设备登录后4小时内请挂机" )
7077
7178 elif msg_type == 51 :
7279 pass
@@ -119,7 +126,10 @@ async def process_text_message(self, message: Dict[str, Any]):
119126 message ["Content" ])
120127
121128 if self .ignore_check (message ["FromWxid" ], message ["SenderWxid" ]):
122- await EventManager .emit ("at_message" , self .bot , message )
129+ if self .ignore_protection or not protector .check (14400 ):
130+ await EventManager .emit ("at_message" , self .bot , message )
131+ else :
132+ logger .warning ("风控保护: 新设备登录后4小时内请挂机" )
123133 return
124134
125135 logger .info ("收到文本消息: 消息ID:{} 来自:{} 发送人:{} @:{} 内容:{}" ,
@@ -130,7 +140,10 @@ async def process_text_message(self, message: Dict[str, Any]):
130140 message ["Content" ])
131141
132142 if self .ignore_check (message ["FromWxid" ], message ["SenderWxid" ]):
133- await EventManager .emit ("text_message" , self .bot , message )
143+ if self .ignore_protection or not protector .check (14400 ):
144+ await EventManager .emit ("text_message" , self .bot , message )
145+ else :
146+ logger .warning ("风控保护: 新设备登录后4小时内请挂机" )
134147
135148 async def process_image_message (self , message : Dict [str , Any ]):
136149 """处理图片消息"""
@@ -175,7 +188,10 @@ async def process_image_message(self, message: Dict[str, Any]):
175188 message ["Content" ] = await self .bot .download_image (aeskey , cdnmidimgurl )
176189
177190 if self .ignore_check (message ["FromWxid" ], message ["SenderWxid" ]):
178- await EventManager .emit ("image_message" , self .bot , message )
191+ if self .ignore_protection or not protector .check (14400 ):
192+ await EventManager .emit ("image_message" , self .bot , message )
193+ else :
194+ logger .warning ("风控保护: 新设备登录后4小时内请挂机" )
179195
180196 async def process_voice_message (self , message : Dict [str , Any ]):
181197 """处理语音消息"""
@@ -225,7 +241,10 @@ async def process_voice_message(self, message: Dict[str, Any]):
225241 message ["Content" ] = await self .bot .silk_base64_to_wav_byte (silk_base64 )
226242
227243 if self .ignore_check (message ["FromWxid" ], message ["SenderWxid" ]):
228- await EventManager .emit ("voice_message" , self .bot , message )
244+ if self .ignore_protection or not protector .check (14400 ):
245+ await EventManager .emit ("voice_message" , self .bot , message )
246+ else :
247+ logger .warning ("风控保护: 新设备登录后4小时内请挂机" )
229248
230249 async def process_xml_message (self , message : Dict [str , Any ]):
231250 """处理xml消息"""
@@ -364,7 +383,10 @@ async def process_quote_message(self, message: Dict[str, Any]):
364383 message ["Quote" ])
365384
366385 if self .ignore_check (message ["FromWxid" ], message ["SenderWxid" ]):
367- await EventManager .emit ("quote_message" , self .bot , message )
386+ if self .ignore_protection or not protector .check (14400 ):
387+ await EventManager .emit ("quote_message" , self .bot , message )
388+ else :
389+ logger .warning ("风控保护: 新设备登录后4小时内请挂机" )
368390
369391 async def process_video_message (self , message ):
370392 # 预处理消息
@@ -394,7 +416,10 @@ async def process_video_message(self, message):
394416 message ["Video" ] = await self .bot .download_video (message ["MsgId" ])
395417
396418 if self .ignore_check (message ["FromWxid" ], message ["SenderWxid" ]):
397- await EventManager .emit ("video_message" , self .bot , message )
419+ if self .ignore_protection or not protector .check (14400 ):
420+ await EventManager .emit ("video_message" , self .bot , message )
421+ else :
422+ logger .warning ("风控保护: 新设备登录后4小时内请挂机" )
398423
399424 async def process_file_message (self , message : Dict [str , Any ]):
400425 """处理文件消息"""
@@ -419,7 +444,10 @@ async def process_file_message(self, message: Dict[str, Any]):
419444 message ["File" ] = await self .bot .download_attach (attach_id )
420445
421446 if self .ignore_check (message ["FromWxid" ], message ["SenderWxid" ]):
422- await EventManager .emit ("file_message" , self .bot , message )
447+ if self .ignore_protection or not protector .check (14400 ):
448+ await EventManager .emit ("file_message" , self .bot , message )
449+ else :
450+ logger .warning ("风控保护: 新设备登录后4小时内请挂机" )
423451
424452 async def process_system_message (self , message : Dict [str , Any ]):
425453 """处理系统消息"""
@@ -480,7 +508,10 @@ async def process_pat_message(self, message: Dict[str, Any]):
480508 message ["PatSuffix" ])
481509
482510 if self .ignore_check (message ["FromWxid" ], message ["SenderWxid" ]):
483- await EventManager .emit ("pat_message" , self .bot , message )
511+ if self .ignore_protection or not protector .check (14400 ):
512+ await EventManager .emit ("pat_message" , self .bot , message )
513+ else :
514+ logger .warning ("风控保护: 新设备登录后4小时内请挂机" )
484515
485516 def ignore_check (self , FromWxid : str , SenderWxid : str ):
486517 if self .ignore_mode == "Whitelist" :
0 commit comments