Repository navigation
Expand file tree
/
Copy pathprocessor.py
More file actions
45 lines (34 loc) · 1.68 KB
/
Copy pathprocessor.py
File metadata and controls
45 lines (34 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
class MessageProcessor:
def __init__(self, wechat_manager):
"""
Initialize the processor with a WeChatManager instance.
Args:
wechat_manager: Instance of WeChatManager to send replies.
"""
self.wx = wechat_manager
def handle_message(self, msg, chat_session=None):
"""
Callback function to handle incoming messages.
Args:
msg: The message object received from wxautox4.
chat_session: The chat session object (optional, depends on lib version).
"""
try:
# Extract basic info
# Note: The structure of 'msg' depends on wxautox4_wechatbot.
# Assuming msg has .content, .type, and we can get sender from chat_session or msg.
# If chat_session is passed, use it to get the sender
sender = chat_session.who if chat_session else "Unknown"
content = getattr(msg, 'content', str(msg))
msg_type = getattr(msg, 'type', 'unknown')
print(f"[{sender}] Received {msg_type}: {content}")
# --- Logic Separation Area ---
# Here you can implement your new logic without touching the original project.
# Example: Simple keyword response
if content == "ping":
self.wx.send_text(sender, "pong from 1052")
# Example: Echo for testing
# self.wx.send_text(sender, f"Echo: {content}")
# -----------------------------
except Exception as e:
print(f"Error processing message: {e}")