예제 #1
0
 def process(message):
     session = Session()
     try:
         if SendBlessingModule.checkTime():
             waitqq = redisConnection.lpop(REDIS_BLESSING_WAITING_QUEUE)
             if not waitqq:
                 return
             blessQuery = session.query(BlessingModal).order_by(func.rand()).limit(1).first()
             if blessQuery:
                 log(moduleName=SendBlessingModule.name,content=message.getContent())
                 renderblessing = renderBlessing.RenderBlessing(int(waitqq[1:]), blessQuery.fromqq, blessQuery.content)
                 url = renderblessing.render().get_url()
                 message = Message()
                 if waitqq[0]=="0":
                     message.setTargetQQ(SMALLWEI_QQ)
                 else:
                     message.setTargetQQ(SMALLWEI2016_QQ)
                 message.setSubType(1)
                 message.setPersonQQ(int(waitqq[1:]))
                 message.setContent(SendBlessingModule.BLESSING_REPLY.format(url,
                                                                             SendBlessingModule.BLESSING_TITLE,
                                                                             SendBlessingModule.BLESSING_CONTENT,
                                                                             SendBlessingModule.BLESSING_LOGO))
                 send(message,True)
             else:
                 return
         else:
             return
     except Exception as e:
         if isinstance(e,Block):
             raise Block()
         log(moduleName=SendBlessingModule.name,level="error",content=e.message)
         return
     finally:
         session.close()
예제 #2
0
 def process(message):
     message = message[:]
     session = Session()
     content = message.getContent()
     content = re.search(ur"[0-9]+", content).group(0)
     try:
         name, num = GroupAddRequest.validify_freshman(content)
         if message.getSubType() == 13:
             # 如果是有人申请加入小微管理的群的话。
             if len(content) == 9:
                 cardNo = int(content)
                 # 从数据库中查询验证信息中的一卡通号
                 student = session.query(StudentInfoModal).filter(
                     StudentInfoModal.cardNo == cardNo).first()
                 if not student:
                     set_group_add_request(message,
                                           message.getResponseFlag(),
                                           REQUEST_DENY)
                 else:
                     set_group_add_request(message,
                                           message.getResponseFlag(),
                                           REQUEST_ALLOW)
                     deptAbbr = DEPARTMENT_ABBR_MAP[student.dept]
                     set_group_card(
                         message, message.getGroupQQ(),
                         message.getPersonQQ(),
                         GroupAddRequest.GROUP_CARD_TEMPLATE.format(
                             student.grade, deptAbbr, student.name))
                     raise Block()
             elif name:
                 try:
                     province = NUM_PORVINCES_MAP[num[2:4]]
                     grade = int(num[0:2])
                     set_group_add_request(message,
                                           message.getResponseFlag(),
                                           REQUEST_ALLOW)
                     set_group_card(
                         message, message.getGroupQQ(),
                         message.getPersonQQ(),
                         GroupAddRequest.GROUP_CARD_TEMPLATE.format(
                             grade, province, name))
                     raise Block()
                 except KeyError:
                     set_group_add_request(message,
                                           message.getResponseFlag(),
                                           REQUEST_DENY)
             else:
                 set_group_add_request(message, message.getResponseFlag(),
                                       REQUEST_DENY)
     except Exception as e:
         if isinstance(e, Block):
             raise Block()
         log(moduleName=GroupAddRequest.name,
             level="error",
             content=e.message)
         return
예제 #3
0
 def validify_cardnum(cardNum):
     session = Session()
     try:
         student = session.query(StudentInfoModal).filter(
             StudentInfoModal.cardNo == cardNum).first()
         if not student:
             return False
         else:
             return True
     except Exception as e:
         log(moduleName=FriendAddRequest.name,
             level="error",
             content=e.message)
         return False
예제 #4
0
 def process(message):
     session = Session()
     try:
         if message.getSubType() == 1 or message.getSubType() == 2:
             content = message.getContent().strip()
             if content[0] == u"绑":
                 cardNo = int(content[1:].strip())
                 student = session.query(StudentInfoModal).filter(
                     StudentInfoModal.cardNo == cardNo).first()
                 print student is None
                 if not student:
                     message.setContent(u"请检查您的一卡通账号!")
                     if message.getSubType() == 2:
                         message.group_at()
                     send(message, True)
                     return
                 if student.QQ is not None:
                     # 该用户提供的一卡通号已经被注册。
                     if student.QQ == message.getPersonQQ():
                         # 该用户想要注册的一卡通号对应的qq就是该用户qq。
                         message.setContent(u"您已注册!")
                     else:
                         # 该用户想要注册的一卡通号对应的qq不是该用户qq。
                         message.setContent(u"请检查您的一卡通账号!")
                     if message.getSubType() == 2:
                         message.group_at()
                     send(message, True)
                     return
                 else:
                     student.QQ = message.getPersonQQ()
                     session.commit()
                     message.setContent(u"绑定成功!")
                     if message.getSubType() == 2:
                         message.group_at()
                     send(message, True)
                     return
     except Exception as e:
         if isinstance(e, Block):
             raise Block()
         log(moduleName=BindCardModule.name,
             level="error",
             content=e.message)
         return
예제 #5
0
 def process(message):
     session = Session()
     try:
         msg = message.getContent()
         if RegisterModule.isRegitser(msg):
             # 注册口令
             log(moduleName=RegisterModule.name,
                 content=str(message.getPersonQQ()) + " register")
             query = session.query(SignInUserModal).filter(
                 SignInUserModal.personQQ == message.getPersonQQ()).first()
             if query:
                 reply = SignInModule.getAt(
                     message) + u"你已经注册过了啦\n现在回复“签”试一下吧~"
                 message.setContent(reply)
                 send(message, True)
             personQQ = message.getPersonQQ()
             nickName = msg.split(' ')[1]
             totalSignIn = 0
             totalScore = 0
             ctnSignIn = 0
             last_Date = SignInModule.getYesterday()
             last_Time = SignInModule.getNowTime()
             record = SignInUserModal(personQQ=personQQ,
                                      nickName=nickName,
                                      totalSignIn=totalSignIn,
                                      totalScore=totalScore,
                                      ctnSignIn=ctnSignIn,
                                      last_Date=last_Date,
                                      last_Time=last_Time)
             session.add(record)
             session.commit()
             reply = SignInModule.getAt(message) + u"注册成功!\n现在回复“签”试一下吧~"
             message.setContent(reply)
             send(message, True)
         else:
             return
     except Exception as e:
         if isinstance(e, Block):
             raise Block()
         log(moduleName=SignInModule.name, level="error", content=e.message)
         return
     finally:
         session.close()
예제 #6
0
 def process(message):
     session = Session()
     try:
         session.add(Message.produceDBMessage(
             message))  # 根据Message对象生成MessageModel对象,并写入数据库中。
         log(moduleName=MessageStoreDBModule.name,
             content=message.getContent() + " " +
             str(message.getGroupQQ()) + " " + str(message.getPersonQQ()))
         session.commit()  # 数据库实际上发生变化是在这一行之后。相当于提交了插入操作。
         return
     except Exception as e:
         if isinstance(e, Block):
             raise Block()
         log(moduleName=MessageStoreDBModule.name,
             level="error",
             content=e.message)
         return
     finally:
         session.close()
예제 #7
0
 def process(message):
     session = Session()
     try:
         if message.getSubType() == 1 and ReceiveBlessingModule.isBless(message):
             log(moduleName=ReceiveBlessingModule.name,content=message.getContent())
             bless = message.getContent()
             if len(bless.encode("gbk")) < 8:
                 message.setContent(u"祝福太短了哦。")
                 send(message,True)
             elif len(bless.encode("gbk")) > 68:
                 message.setContent(u"祝福太长了哦,小微记不住了呢。。。")
                 send(message, True)
             else:
                 blessModule = BlessingModal(content=message.getContent()[1:],
                                             fromqq=message.getPersonQQ())
                 session.add(blessModule)
                 session.commit()
                 temp=0
                 if message.getTargetQQ()==SMALLWEI_QQ:
                     temp=0
                 else:
                     temp=1
                 redisConnection.rpush(REDIS_BLESSING_WAITING_QUEUE,str(temp)+str(message.getPersonQQ()))
                 if getinfo(str(message.getPersonQQ()))[0]==0:
                     message.setContent(u"已收录您的祝福,系统检测到您尚未注册,请回复“绑定+一卡通号”注册后享受完整功能哦!")
                 else:
                     message.setContent(
                         u"您的祝福已经收集!请等待不久后来自陌生人的祝福哦~")
                     send(message, True)
         else:
             return
     except Exception as e:
         if isinstance(e,Block):
             raise Block()
         log(moduleName=ReceiveBlessingModule.name,level="error",content=e.message)
         return
     finally:
         session.close()
예제 #8
0
    def process(message):
        session = Session()
        try:
            message = message[:]
            msg = message.getContent()

            if UnrecalledModule.isLastMessage(
                    msg) and UnrecalledModule.isUnrecalled(msg):
                if UnrecalledModule.isFromGroup(message):
                    """
                    群聊模块
                    """
                    getLast = session.query(MessageModal).filter_by(
                        groupQQ=message.getGroupQQ()).all()
                    getLast_content = u"发送的:\n" + getLast[-(int(msg[1:]) +
                                                            1)].content
                    getLast_personQQ = getLast[-(int(msg[1:]) + 1)].personQQ

                    message.setContent(getLast_content)
                    message.group_at(getLast_personQQ)
                    send(message, True)

                elif UnrecalledModule.isFromDiscussion(message):
                    """
                    讨论组模块
                    """
                    getLast = session.query(MessageModal).filter_by(
                        discussionQQ=message.getDiscussionQQ()).all()
                    getLast_content = u"发送的:\n" + getLast[-(int(msg[1:]) +
                                                            1)].content
                    getLast_personQQ = getLast[-(int(msg[1:]) + 1)].personQQ

                    message.setContent(getLast_content)
                    message.group_at(getLast_personQQ)
                    send(message, True)
            else:
                return
        except Exception as e:
            if isinstance(e, Block):
                raise Block()
            traceback.print_exc()
            return
        finally:
            session.close()
예제 #9
0
 def process(message):
     session = Session()
     scoreType = 0
     ctnSignIn = 0
     latter_totalScore = 0
     latter_totalSignIn = 0
     try:
         msg = message.getContent()
         if SignInModule.isSignIn(msg):
             # 签到口令
             log(moduleName=SignInModule.name,
                 content=str(message.getPersonQQ()) + " sign in")
             if SignInModule.inSuitableTime() == 0:
                 log(moduleName=SignInModule.name,
                     content=str(message.getPersonQQ()) +
                     " sign in time error")
                 reply = SignInModule.getAt(
                     message) + u"【签到失败】\n只能在6-9点之间签到哦。"
                 message.setContent(reply)
                 send(message, True)
             elif SignInModule.inSuitableTime() == 1:
                 scoreType = 1
             else:
                 scoreType = 2
             query = session.query(SignInUserModal).filter(
                 SignInUserModal.personQQ == message.getPersonQQ()).first()
             # 如果此人之前签过到,即数据库有此用户
             if query:
                 ctnSignIn = query.ctnSignIn
                 if query.last_Date == SignInModule.getToday():
                     reply = SignInModule.getAt(
                         message) + u"您今天已经签到过了,明天再来试试吧!"
                     message.setContent(reply)
                     send(message, True)
                 else:
                     addedScore = SignInModule.getSuitableScore(
                         query.ctnSignIn, scoreType=scoreType)
                     record = SignInRecordModal(
                         personQQ=message.getPersonQQ(),
                         date=datetime.datetime.fromtimestamp(
                             message.getSendTime()).date(),
                         time=datetime.datetime.fromtimestamp(
                             message.getSendTime()).time(),
                         addedScore=addedScore)
                     session.add(record)
                     session.commit()
                     # update
                     latter_totalSignIn = query.totalSignIn + 1
                     latter_totalScore = query.totalScore + addedScore
                 if query.last_Date == SignInModule.getYesterday():
                     ctnSignIn = ctnSignIn + 1
                 else:
                     ctnSignIn = 0
                 query.ctnSignIn = ctnSignIn
                 query.totalScore = latter_totalScore
                 query.totalSignIn = latter_totalSignIn
                 query.last_Date = datetime.datetime.fromtimestamp(
                     message.getSendTime()).date()
                 query.last_Time = datetime.datetime.fromtimestamp(
                     message.getSendTime()).time()
                 session.commit()
                 log(moduleName=SignInModule.name,
                     content=str(message.getPersonQQ()) +
                     " sign in success")
                 reply = SignInModule.SIGNIN_SUCCESS_REPLY.format(
                     SignInModule.URL, query.nickName,
                     SignInModule.SIGNIN_SUCCESS_CONTENT.format(
                         ctnSignIn, latter_totalSignIn, latter_totalScore),
                     SignInModule.USER_LOGO.format(message.getPersonQQ()))
                 # 返回内容
                 message.setContent(reply)
                 send(message, True)
             else:  # 如果此人之前未签过到,即数据库无此用户
                 log(moduleName=SignInModule.name,
                     content=str(message.getPersonQQ()) + " not registered")
                 reply = SignInModule.getAt(
                     message) + u"您尚未注册,输入[注册 昵称]即可注册,例: 注册 李云龙 "
                 message.setContent(reply)
                 send(message, True)
         elif SignInModule.isRank(msg):
             newContent = u"签到排行榜:"
             query = session.query(SignInUserModal).order_by(
                 desc(SignInUserModal.totalScore)).limit(6).all()
             for iq in range(0, len(query)):
                 newContent += u"\n{:<1}.{:<6}({:<10}):{:<4}分".format(
                     iq, query[iq].nickName, query[iq].personQQ,
                     query[iq].totalScore)
             message.setContent(SignInModule.getAt(message) + newContent)
             send(message, True)
         else:
             return
     except Exception as e:  #
         if isinstance(e, Block):
             raise Block()
         log(moduleName=SignInModule.name, level="error", content=e.message)
         return
     finally:
         session.close()
예제 #10
0
    def process(message):
        session = Session()
        try:
            if message.getSubType() == 1 or message.getSubType() == 2:
                message.remove_group_at()
                content = message.getContent()
                #管理功能,较高权限
                #绑定功能:绑定 + 一卡通号
                if content[0:2] == u"绑定":
                    cardNo = int(content[2:].strip())
                    student_qq = session.query(StudentInfoModal).filter(
                        StudentInfoModal.QQ == int(
                            message.getPersonQQ())).first()
                    if not student_qq:
                        student = session.query(StudentInfoModal).filter(
                            StudentInfoModal.cardNo == cardNo).first()
                        if not student:
                            message.setContent(u"没有找到此一卡通,请检查您的一卡通账号!")
                            if message.getSubType() == 2:
                                message.group_at()
                            send(message, True)
                            return
                        elif student.QQ is not None:
                            if student.QQ == message.getPersonQQ():
                                message.setContent(u"您已注册过!可以直接回复我“课表”查询课表哦~")
                            else:
                                message.setContent(u"该一卡通已经绑定过QQ了,请检查您的一卡通账号!")
                            if message.getSubType() == 2:
                                message.group_at()
                            send(message, True)
                            return
                        else:
                            student.QQ = message.getPersonQQ()
                            session.commit()
                            message.setContent(student.name +
                                               u"同学,您已经绑定成功!可以直接回复我“课表”查询课表哦~")
                            if message.getSubType() == 2:
                                message.group_at()
                            send(message, True)
                            return
                    else:
                        message.setContent(student_qq.name +
                                           u"同学,您已经绑定过啦!如有错误请发送您的一卡通到我邮箱哦~")
                        if message.getSubType() == 2:
                            message.group_at()
                        send(message, True)
                        return

                #管理员查信息功能:查信息 + 一卡通号 / QQ
                #只有开发群内有此权限
                elif content[0:3] == u"查信息" and message.getGroupQQ(
                ) == 588694674:
                    tempNo = content[3:].strip()
                    if int(tempNo) / 1000000 == 213:
                        student = session.query(StudentInfoModal).filter(
                            StudentInfoModal.cardNo == tempNo).first()
                    elif len(tempNo) == 8:
                        student = session.query(StudentInfoModal).filter(
                            StudentInfoModal.stuNo == tempNo).first()
                    else:
                        student = session.query(StudentInfoModal).filter(
                            StudentInfoModal.QQ == tempNo).first()
                    if not student:
                        message.setContent(u"尊敬的管理员:查询的目标不存在!")
                    else:
                        tempMsg = u"尊敬的管理员,你所查询的" + student.name + u"同学的信息如下:\n学号:" + str(
                            student.stuNo
                        ) + u"\n一卡通:" + str(student.cardNo) + u"\nQQ:" + str(
                            student.QQ
                        ) + u"\n院系:" + student.dept + u"\n专业:" + student.major
                        message.setContent(tempMsg)
                    if message.getSubType() == 2:
                        message.group_at()
                    send(message, True)
                    return

                #管理员解绑功能:解绑 + 一卡通号 / QQ
                #只有开发群内有此权限
                elif content[0:2] == u"解绑" and message.getGroupQQ(
                ) == 588694674:
                    tempNo = content[2:].strip()
                    #判断需要解除绑定的号码是否是一卡通号
                    if int(tempNo) / 1000000 == 213:
                        student = session.query(StudentInfoModal).filter(
                            StudentInfoModal.cardNo == tempNo).first()
                    elif len(tempNo) == 8:
                        student = session.query(StudentInfoModal).filter(
                            StudentInfoModal.stuNo == tempNo).first()
                    else:
                        student = session.query(StudentInfoModal).filter(
                            StudentInfoModal.QQ == tempNo).first()
                    if not student:
                        message.setContent(u"尊敬的管理员:查询的目标不存在!")
                    elif student.QQ is not None:
                        student.QQ = None
                        session.commit()
                        tempMsg = u"尊敬的管理员," + student.name + u"同学的QQ信息已删除"
                        message.setContent(tempMsg)
                    else:
                        tempMsg = u"该一卡通账号尚未绑定QQ,请核实!"
                        message.setContent(tempMsg)
                    if message.getSubType() == 2:
                        message.group_at()
                    send(message, True)
                    return

                #用户功能,绑定后即查
                if content[0:3].find(u"课表") != -1 or content[0:3].find(
                        u"跑操") != -1 or content[0].find(u"签") != -1:
                    student = session.query(StudentInfoModal).filter(
                        StudentInfoModal.QQ == message.getPersonQQ()).first()
                    if not student:
                        message.setContent(
                            u"您好,系统检测到您尚未绑定!请先回复“绑定+一卡通号”进行绑定!\n如:绑定213111111")
                        if message.getSubType() == 2:
                            message.group_at()
                        send(message, True)
                        return

                    else:
                        if content.find(u"课表") != -1:
                            tempMsg = StudentInfoModule.COURSE_TABLE_URL.format(
                                student.stuNo, student.name, student.QQ)
                            message.setContent(tempMsg)
                            #                            群聊转私发代码
                            #                            if message.getSubType() == 2:
                            #                                message.setSubType(1)
                            #                                message.setGroupQQ(0)
                            send(message, True)
                            return

                        elif content.find(u"跑操") != -1:
                            num = getpaocao(student.cardNo)
                            if num == '' or student.grade < 15:
                                tempMsg = StudentInfoModule.INFO_REPLY_PAOCAO_2.format(
                                    student.name, "N/A", student.QQ)
                            else:
                                tempMsg = StudentInfoModule.INFO_REPLY_PAOCAO.format(
                                    student.name, num, student.QQ)
                            message.setContent(tempMsg)
                            send(message, True)
                            return

                        elif content.find(u"签") != -1:
                            num = getpaocao(student.cardNo)
                            date = datetime.date.today()
                            time = str(datetime.datetime.now())[11:19]
                            if num == '' or student.grade < 15:
                                tempMsg = StudentInfoModule.INFO_REPLY_SIGNIN.format(
                                    student.name, "N/A", time, date,
                                    student.QQ, student.stuNo)
                            else:
                                tempMsg = StudentInfoModule.INFO_REPLY_SIGNIN.format(
                                    student.name, num, time, date, student.QQ,
                                    student.stuNo)
                            message.setContent(tempMsg)
                            if message.getSubType() == 2:
                                message.setSubType(1)
                                message.setGroupQQ(0)
                            send(message, True)
                            return

        except Exception as e:
            if isinstance(e, Block):
                raise Block()
            log(moduleName=StudentInfoModule.name,
                level="error",
                content=e.message)
            return
예제 #11
0
 def process(message):
     session = Session()
     try:
         context = redisConnection.hget(REDIS_CONTEXT_CACHE_HASH_NAME,
                                        message.get_context_str())
         message = message[:]
         message.remove_group_at()
         msg = message.getContent()
         """
         下面是接收模块
         和发送到运营群模块
         """
         if message.is_at() and TreeHoleModule.isTreeHole(msg):
             message.setContent(u"该功能涉及隐私,请私聊微微哟~")
             message.group_at(message.getPersonQQ())
             send(message, True)
         elif message.getSubType() == 1 and TreeHoleModule.isTreeHole(msg):
             redisConnection.hset(REDIS_CONTEXT_CACHE_HASH_NAME,
                                  message.get_context_str(),
                                  TreeHoleModule.CONTEXT)
             message.setContent(u"把你想说的发给微微哦~")
             message.group_at(message.getPersonQQ())
             send(message, True)
         elif message.getSubType(
         ) == 1 and context == TreeHoleModule.CONTEXT:
             message.setContent(TreeHoleModule.GET_SUCCESS_REPLY)
             redisConnection.hdel(REDIS_CONTEXT_CACHE_HASH_NAME,
                                  message.get_context_str())
             record = TreeHoleRecordModal(getContent=msg,
                                          getPersonQQ=message.getPersonQQ(),
                                          getTime=message.getSendTime(),
                                          subType=0)
             session.add(record)
             session.commit()
             send(message, False)
             getId = session.query(TreeHoleRecordModal).filter_by(
                 getContent=msg).all()
             message.setSubType(2)
             getId_str = str(getId[-1].id)
             message.setContent("ID:" + getId_str + "\n" + msg)
             message.setGroupQQ(YUNYINGQQ)
             message.setPersonQQ(0)
             send(message, True)
         elif message.is_at() and TreeHoleModule.issend(message):
             """
         下面是回复模块
         """
             getMessageList = message.getContent().split("#")
             ID = getMessageList[1]
             getSubType = session.query(TreeHoleRecordModal).filter_by(
                 id=ID).all()
             max = session.query(func.max(TreeHoleRecordModal.id)).first()
             try:
                 int(ID) / 1
             except Exception as e:
                 feedback = u"此次回复无效"
                 message.setContent(u"ERROR:\n" + "ID:" + str(ID) +
                                    u"输入违法\n" + feedback)
                 send(message, True)
             if int(ID) < 0 or int(ID) > int(str(max[0])):
                 feedback = u"此次回复无效"
                 message.setContent(u"ERROR:\n" + "ID:" + str(ID) +
                                    u"超出当前范围\n" + feedback)
                 send(message, True)
             elif str(getSubType[0].subType) == "1":
                 feedback = u"此次回复无效"
                 message.setContent(u"WARNING:\n" + "ID:" + str(ID) +
                                    u"事件已被回复\n" + feedback)
                 send(message, True)
             elif getMessageList[2] == u"pass":
                 sendContent = "pass"
                 feedback = u"Pass成功"
             else:
                 sendContent = getMessageList[2]
                 feedback = u"回复成功~"
             """
             session.query(TreeHoleRecordModal).filter(TreeHoleRecordModal.id==2).update({TreeHoleRecordModal.subType : 1},{TreeHoleRecordModal.sendContent : sendContent},{TreeHoleRecordModal.sendPersonQQ : message.getPersonQQ()},{TreeHoleRecordModal.sendTime:message.getSendTime()})
             """
             session.query(TreeHoleRecordModal).filter(
                 TreeHoleRecordModal.id == ID).update({"subType": 1})
             session.query(TreeHoleRecordModal).filter(
                 TreeHoleRecordModal.id == ID).update(
                     {"sendContent": sendContent})
             session.query(TreeHoleRecordModal).filter(
                 TreeHoleRecordModal.id == ID).update(
                     {"sendPersonQQ": message.getPersonQQ()})
             session.query(TreeHoleRecordModal).filter(
                 TreeHoleRecordModal.id == ID).update(
                     {"sendTime": message.getSendTime()})
             session.commit()
             message.setContent("ID:" + str(ID) + u"事件\n" + feedback)
             send(message, True)
         else:
             return
     except Exception as e:
         if isinstance(e, Block):
             raise Block()
         traceback.print_exc()
         return
     finally:
         session.close()
예제 #12
0
    def process(message):
        session = Session()
        try:
            context = redisConnection.hget(REDIS_CONTEXT_CACHE_HASH_NAME, message.get_context_str())
            message.remove_group_at()
            if (message.is_at()):
                message.setContent(u"该功能涉及隐私,请私聊微微哟~")
                # message.group_at()
                send(message, True)
            # 判断是否完成了上次的书写
            if (message.getSubType() == 1 and LostFinderModule.is_lost_find(message)):
                print "[" + LostFinderModule.name + "]"
                message.setContent(u"发送括号内命令,微微为你呈现:\
                    --[" + KEY_1 + "]--发布寻物启示\n\
                    --[" + KEY_2 + "]--发布失物招领\n\
                    --[" + KEY_3 + "]--浏览寻物启示\n\
                    --[" + KEY_4 + "]--浏览失物列表\n\
                    --[" + KEY_5 + "]--查阅我的发布\n\
                ")
                # message.group_at()
                send(message, True)
            elif (message.getSubType() == 1 and LostFinderModule.is_lost_find1(message)):
                redisConnection.hset(REDIS_CONTEXT_CACHE_HASH_NAME, message.get_context_str(),
                                     LostFinderModule.CONTEXT1)
                message.setContent(u"请将文字描述发给微微,回复[取消]可撤销此次发布。\n\
                    Tips:图片可在下一步添加,不要着急哦~\
                ")
                send(message, False)
            elif (message.getSubType() == 1 and LostFinderModule.is_lost_find2(message)):
                redisConnection.hset(REDIS_CONTEXT_CACHE_HASH_NAME, message.get_context_str(),
                                     LostFinderModule.CONTEXT2)
                message.setContent(u"请将文字描述发给微微,回复[取消]可撤销此次发布。。\n\
                    Tips:图片可在下一步添加,不要着急哦~:\
                ")
                send(message, False)
            elif (message.getSubType() == 1 and LostFinderModule.is_lost_find3(message)):
                redisConnection.hset(REDIS_CONTEXT_CACHE_HASH_NAME, message.get_context_str(),
                                     LostFinderModule.CONTEXT3)
                # 没被删除 是寻物启示 已经被发布 且pickPersonQQ为空--即还没有捡到的人
                result = session.query(LostRecordModal).filter(isDelete == False, isPublished == True, isLost == True,
                                                               pickPersonQQ == None).all()
                for row in result:
                    recordId = row.id
                    description = row.discription
                    imageName = row.imageFilename
                    image = LostFinderModule.PICTURE_NAME.format(str(recordId) + "_.jpg")
                    content = "丢失物编号:" + recordId + "\n丢失物描述:" + description + "\n附图:\n" + image
                    message.setContent(content)
                    send(message, True)

                content = "\n\n可用命令:\n--[归还 丢失物编号]--归还此失物\n--[举报 丢失物编号]--暂未开放的功能"
                message.setContent(content)
                send(message, True)
            elif (message.getSubType() == 1 and LostFinderModule.is_lost_find4(message)):
                redisConnection.hset(REDIS_CONTEXT_CACHE_HASH_NAME, message.get_context_str(),
                                     LostFinderModule.CONTEXT4)
                # 没被删除 是失物招领 已经被发布 且lostPersonQQ为空--即还没有认领的人
                result = session.query(LostRecordModal).filter(isDelete == False, isPublished == True, isLost == True,
                                                               pickPersonQQ == None).all()
                for row in result:
                    recordId = row.id
                    description = row.discription
                    imageName = row.imageFilename
                    image = LostFinderModule.PICTURE_NAME.format(str(recordId) + "_.jpg")
                    content = "拾取物编号:" + recordId + "\n拾取物描述:" + description + "\n附图:\n" + image
                    message.setContent(content)
                    send(message, True)

                content = "\n\n可用命令:\n--[认领 拾取物编号]--认领此物品\n--[举报 拾取物编号]--暂未开放的功能"
                message.setContent(content)
                send(message, True)
            elif (message.getSubType() == 1 and LostFinderModule.is_lost_find5(message)):
                redisConnection.hset(REDIS_CONTEXT_CACHE_HASH_NAME, message.get_context_str(),
                                     LostFinderModule.CONTEXT5)
                myqq = message.getPersonQQ()
                # 发布的寻物启示
                message.setContent(u"为您展示发布的寻物启示:")
                send(message, True)
                result = session.query(LostRecordModal).filter(isDelete == False, isPublished == True,
                                                               lostPersonQQ == myqq, isLost == True)
                for row in result:
                    recordId = row.id
                    description = row.discription
                    imageName = row.imageFilename
                    image = LostFinderModule.PICTURE_NAME.format(str(recordId) + "_.jpg")
                    if (row.pickPersonQQ() != None):
                        content = "丢失物编号:" + recordId + "\n拾取者qq:" + str(
                            row.pickPersonQQ) + "\n丢失物描述:" + description + "\n附图:\n" + image
                    else:
                        content = "丢失物编号:" + recordId + "\n[还没有被拾取!]" + "\n丢失物描述:" + description + "\n附图:\n" + image
                    message.setContent(content)
                    send(message, True)

                # 发布的失物招领
                message.setContent(u"为您展示发布的失物招领:")
                send(message, True)
                result = session.query(LostRecordModal).filter(isDelete == False, isPublished == True,
                                                               pickPersonQQ == myqq, isLost == False)
                for row in result:
                    recordId = row.id
                    description = row.discription
                    imageName = row.imageFilename
                    image = LostFinderModule.PICTURE_NAME.format(str(recordId + "_.jpg")
                    if (row.lostPersonQQ() != None):
                        content = "拾取物编号:" + recordId + "\n领取者qq:" + str(
                            row.pickPersonQQ) + "\n拾取物描述:" + description + "\n附图:\n" + image
                    else:
                        content = "拾取物编号:" + recordId + "\n[还没有被领取!]" + "\n拾取物描述:" + description + "\n附图:\n" + image
                    message.setContent(content)
                    send(message, True)

                    message.setContent(u"\n\n回复[抹除] 拾取物/丢失物编号] 可以抹除记录\n回复[修改 编号]可以修改内容\n回复[]")
                    send(message, True)

                    # 防止先发图片
                    elif message.getSubType() == 1 and context == LostFinderModule.CONTEXT1 and LostFinderModule.is_picture(
                        message):
                    message.setContent(u"请先发送文字描述")
                    send(message, True)

                    elif message.getSubType() == 1 and context == LostFinderModule.CONTEXT1 and (
                        not LostFinderModule.is_picture(message)):
                    redisConnection.hset(REDIS_CONTEXT_CACHE_HASH_NAME, message.get_context_str(),
                                         LostFinderModule.PIC_CONTEXT1)
                    lostPersonQQ = message.getPersonQQ()
                    description = message.getContent()
                    createDate = LostFinderModule.getToday()
                    isLost = True
                    record = LostRecordModal(
                        lostPersonQQ=lostPersonQQ,
                        description=description,
                        createDate=createDate,
                        isLost=isLost,
                    )
                    session.add(record)
                    session.commit()
                    message.setContent(u"已经收到文字描述,需要图片描述请继续发送图片,无图片回复[结束]直接发布。")
                    send(message, False)

                    elif message.getSubType() == 1 and context == LostFinderModule.PIC_CONTEXT1 and LostFinderModule.is_picture(
                        message):
                    name = re.search(LostRecordModal.PICTURE_PATTERN, msg.getContent()).group(1)
                    buffer = cStringIO.StringIO()
                    img = CQImgReader.CQImgReader(
                        LostFinderModule.COOLQ_IMAGE_PATH.format(
                            msg.getTargetQQ()) + name + ".cqimg").get_pil_img()

                    num = int(session.query(func.count(LostRecordModal.id))) + 1
                    filename = str(num)
                    img.save(LostFinderModule.lostFinderDirectory + "\\" + filename + ".jpg")
                    img.save(buffer, format="JPEG")

                    query = session.query(LostRecordModal)
                    result = query.filter(LostRecordModal.lostPersonQQ == str(message.getPersonQQ()),
                                          LostRecordModal.isPublished == False)
                    result.update({LostRecordModal.imageFilename: filename, LostRecordModal.isPublished: True})
                    session.commit()

                    msg.setContent(REPLY_1)
                    send(msg, True)

                    elif message.getSubType() == 1 and context == LostFinderModule.CONTEXT2:
                    redisConnection.hset(REDIS_CONTEXT_CACHE_HASH_NAME, message.get_context_str(),
                                         LostFinderModule.PIC_CONTEXT2)
                    pickPersonQQ = message.getPersonQQ()
                    description = message.getContent()
                    createDate = LostFinderModule.getToday()
                    isLost = False
                    record = LostRecordModal(
                        pickPersonQQ=pickPersonQQ,
                        description=description,
                        createDate=createDate,
                        isLost=isLost,
                    )
                    session.add(record)
                    session.commit()
                    message.setContent(u"已经收到文字描述,需要图片描述请继续发送图片,无图片回复[结束]直接发布。")
                    send(message, False)

                    elif message.getSubType() == 1 and context == LostFinderModule.PIC_CONTEXT2 and LostFinderModule.is_picture(
                        message):
                    name = re.search(LostRecordModal.PICTURE_PATTERN, msg.getContent()).group(1)
                    buffer = cStringIO.StringIO()
                    img = CQImgReader.CQImgReader(
                        LostFinderModule.COOLQ_IMAGE_PATH.format(
                            msg.getTargetQQ()) + name + ".cqimg").get_pil_img()

                    num = int(session.query(func.count(LostRecordModal.id))) + 1
                    filename = str(num)
                    img.save(LostFinderModule.lostFinderDirectory + "\\" + filename + ".jpg")
                    img.save(buffer, format="JPEG")

                    query = session.query(LostRecordModal)
                    result = query.filter(LostRecordModal.pickPersonQQ == str(message.getPersonQQ()),
                                          LostRecordModal.isPublished == False)
                    result.update({LostRecordModal.imageFilename: filename, LostRecordModal.isPublished: True})
                    session.commit()

                    msg.setContent(REPLY_1)
                    send(msg, True)

                    elif message.getSubType() == 1 and context == LostFinderModule.PIC_CONTEXT1 and (
                        not LostFinderModule.is_picture(message)):
                    redisConnection.hset(REDIS_CONTEXT_CACHE_HASH_NAME, message.get_context_str(), "")
                    query = session.query(LostRecordModal)
                    result = query.filter(LostRecordModal.lostPersonQQ == message.getPersonQQ(),
                                          LostRecordModal.isPublished == False)
                    result.update({LostRecordModal.isPublished: True})
                    session.commit()
                    message.setContent("监测到发送的不是图片,自动发布~若为误操作,可在查看自己的发布中修改~")

                    elif message.getSubType() == 1 and context == LostFinderModule.PIC_CONTEXT2 and (
                        not LostFinderModule.is_picture(message)):
                    redisConnection.hset(REDIS_CONTEXT_CACHE_HASH_NAME, message.get_context_str(), "")
                    query = session.query(LostRecordModal)
                    result = query.filter(LostRecordModal.pickPersonQQ == message.getPersonQQ(),
                                          LostRecordModal.isPublished == False)
                    result.update({LostRecordModal.isPublished: True})
                    session.commit()
                    message.setContent("监测到发送的不是图片,自动发布~若为误操作,可在查看自己的发布中修改~")

                    elif message.getSubType() == 1 and LostFinderModule.is_return(
                        message) and context == LostFinderModule.CONTEXT3):
                    recordID = LostFinderModule.RETURN_PATTERN.findall(message.getContent())
                    if (not recordID) | | (recordID[0]):
                        message.setContent(u"命令似乎有些问题呢,检查命令格式哦~")
                        send(message, True)
                    else:
                        recordId = recordID[0]
                        result = session.qeury(LostRecordModal).filter(id == recordId).first()
                        if not result:
                            message.setContent(u"命令似乎有些问题呢,检查命令格式哦~")
                            send(message, True)
                        else:
                            lostPersonQQ = result.lostPersonQQ
                            qqTemp = message.getPersonQQ()
                            session.update(LostRecordModal).where(id == recordId). \
                                values(
                                pickPersonQQ=int(message.getPersonQQ()),
                            )
                            session.commit()
                            message.setContent(u"归还申请已经接受,请您将物品归还给QQ:" + str(lostPersonQQ) + "~")
                            send(message, True)
                            message.setPersonQQ(int(lostPersonQQ))
                            message.setContent(u"有人认领您发布的寻物启示,他的qq为--" + str(qqTemp) + "--")
                            send(message, True)

                elif message.getSubType() == 1 and LostFinderModule.is_claim(
                    message) and context == LostFinderModule.CONTEXT4):
                recordID = LostFinderModule.CLAIM_PATTERN.findall(message.getContent())
                if (not recordID) | | (recordID[0]):
                    message.setContent(u"命令似乎有些问题呢,检查命令格式哦~")
                send(message, True)
                else: