def group_text(msg): global MsgContent # which group message in chatRoom_id = msg['User']['NickName'] # logger.debug(msg) # id of sender currentUserName = msg['ActualNickName'] friend = Friend(newInstance) member_alias = friend.addFriendFromMsg(robotId, msg) logger.debug(member_alias) # save message into database according to their types if msg['Type'] == TEXT: MsgContent = msg['Content'] # logger.debug(MsgContent) elif msg['Type'] == SHARING: MsgContent = msg['Text'] # logger.debug(MsgContent) # elif (msg['Type'] != SHARING or msg['Type'] != TEXT): # MsgContent = '1' connection = mysql_pool.connection() cur = connection.cursor() query = "INSERT INTO group_chat_content(group_id, user_nickname, content, member_id, content_type, time) VALUES(%s, %s, %s, %s, %s, UNIX_TIMESTAMP())" cur.execute(query, (chatRoom_id, currentUserName, MsgContent, member_alias, msg['Type']))
def text_reply(msg): jsonMsg = json.dumps(msg) logger.debug(jsonMsg) msgText = msg.text fromUser = msg.FromUserName msgType = msg.MsgType if len(msgText) < 6: logger.info("trying to authorize user") friend = Friend(newInstance) alias = friend.addFriendFromMsg(robotId, msg) auth = Authentication() attemptNum = auth.attemptNumbers(fromUser) if attemptNum > 10: msg.user.send("验证失败,尝试过多") else: try: loginCode = int(msgText) loginId = auth.login(loginCode, alias) if loginId: msg.user.send("验证成功, 登录 http://console.masterqun.com/client/directLogin/{}/{}/".format(loginCode, loginId)) logger.error("login ok code: {} text: {}".format(loginCode, msgText)) else: logger.error("failed code: {} text: {}".format(loginCode, msgText)) msg.user.send("验证失败") except Exception: pass robot.logMessage(fromUser, jsonMsg, msgType, 'login', robotId)
def text_reply(msg): jsonMsg = json.dumps(msg) logger.debug(jsonMsg) fromUser = msg.FromUserName msgType = msg.MsgType friend = Friend(newInstance) friend.addFriendFromMsg(robotId, msg) robot.logMessage(fromUser, jsonMsg, msgType, 'others', robotId)
def add_friend(msg): msg.user.verify() jsonMsg = json.dumps(msg) logger.debug(jsonMsg) fromUser = msg.FromUserName msgType = msg.MsgType friend = Friend(newInstance) friend.addFriendFromMsg(robotId, msg) robot.logMessage(fromUser, jsonMsg, msgType, 'friends', robotId)