toy_uploader
if friend_type == "toy":
filename = get_xxtx(to_user, from_user, "xxtx")
RET["CODE"] = 0
RET["MSG"] = "上传成功"
RET["DATA"] = {
"code":0,
"filename": filename,
"friend_type": "toy"
}
redis_chat
def get_redis_toy(to_user, from_user):
to_user_json = RDB.get(to_user)
if to_user_json:
to_user_dict = json.loads(to_user_json)
count = to_user_dict.pop(from_user, 0)
if count == 0:
for k, v in to_user_dict.items():
if v:
from_user = k
count = v
to_user_dict[from_user] = 0
to_user_json = json.dumps(to_user_dict)
else:
to_user_json = json.dumps({from_user: 0})
count = 0
RDB.set(to_user, to_user_json)
return count,from_user
utils
def get_xxtx(to_user,from_user,tx_type=None):
friend_remark = "未知用户"
toy_info = MDB.Toys.find_one({"_id": ObjectId(to_user)})
toy_friend_list = toy_info.get("friend_list")
for friend in toy_friend_list:
if friend.get("friend_id") == from_user:
friend_remark = friend.get("friend_remark")
friend_type = friend.get("friend_type")
if tx_type == "xxtx":
wenjianming = text2audio(f"你有来自{friend_remark}的消息")
return wenjianming
else:
wenjianming = text2audio(f"以下是来自{friend_remark}的消息")
return wenjianming,friend_type