Files
abot/message_report/process_message.py
2025-02-05 13:34:19 +08:00

21 lines
634 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import redis
from datetime import datetime
import re
from wcferry import WxMsg
# 连接到Redis
r = redis.Redis(host='192.168.2.32', port=6379, db=0)
def process_message(message:WxMsg):
# 示例message字符串
current_date = datetime.now().strftime('%Y-%m-%d')
# 生成Redis key
key = f"{message.roomid}:{message.sender}:{current_date}:count"
# 使用Redis哈希或字符串增加发言次数
r.hincrby(key, 'count', 1) # 这里使用哈希但也可以考虑用字符串的INCR操作
# 或者使用字符串r.incr(key) # 如果只存储一个整数值,字符串类型可能更简单