Exemple #1
0
def getEvent():
    data = request.json
    post_type = data.get('post_type')
    if (post_type == 'message'):
        message_type = data.get('message_type')
        #print(data)
        message = data.get('message')
        user_id = str(data.get('user_id'))
        if (message_type == 'private'
                and (dbconn.check_register(user_id) == 1 or '注册' in message)):
            #仅接收注册用户的消息和注册消息
            print(f"--------------------\n接收消息@{user_id}:{message[:20]}")
            readMsg(user_id, message)
    elif (post_type == 'request'):
        request_type = data.get('request_type')
        if (request_type == 'friend'):
            user_id = str(data.get('user_id'))
            comment = str(data.get('comment'))
            flag = str(data.get('flag'))
            print(f"--------------------\n接收加好友请求@{user_id}:{comment[:20]}")
            time.sleep(random.randint(5, 10))
            goapi.add_request(flag)
            time.sleep(random.randint(5, 10))
            goapi.sendMsg(
                user_id,
                "欢迎!\n请先注册,例如'注册@小明@智科20-2'\n 班级请严格按格式输入,否则可能统计不上哦,另外特别注意'-'是减号不是破折号,也不要加空格"
            )
    else:
        #暂不处理其他类型上报,为防止go-cq报错而设置
        pass

    return data
Exemple #2
0
def register_prompt(user_id, message):
    """用户注册逻辑"""
    if ('注册' in message):
        err_promot = '输入好像有点问题呢\n注册格式:"注册@姓名@班级"'
        try:
            user_name = message.split('@')[1]
            user_class = message.split('@')[2]
            #简单过滤用户输入
            if not (inputFilter.is_Chinese(user_name)
                    and inputFilter.check_length(user_name)):
                goapi.sendMsg(user_id, err_promot)
                return
            if not (inputFilter.is_valid(user_class)
                    and inputFilter.check_length(user_class)):
                goapi.sendMsg(user_id, err_promot)
                return

        except:
            goapi.sendMsg(user_id, err_promot)
        else:
            if (globalDB.check_register(user_id)):
                goapi.sendMsg(user_id, '您已注册过啦~')
                re_register_user(user_id, user_name, user_class)
            else:
                register_user(user_id, user_name, user_class)
    return
Exemple #3
0
def readMsg(user_id, message):
    #处理消息核心
    user_id = str(user_id)
    #管理员列表
    admin_list = show_admin()

    if ('image' in message):
        if (dbconn.check_register(user_id)):
            #用户已注册
            get_img(user_id, message)
        else:
            #用户未注册
            goapi.sendMsg(
                user_id,
                '您还没注册呢,请输入例如"注册@小明@智科20-2"\n 班级请严格按格式输入,否则可能统计不上哦,另外特别注意' -
                '是减号不是破折号,也不要加空格')
        return
    if ('注册' in message):
        try:
            user_name = message.split('@')[1]
            user_class = message.split('@')[2]
            #简单过滤用户输入
            if not (inputFilter.is_Chinese(user_name)
                    and inputFilter.check_length(user_name)):
                goapi.sendMsg(user_id, '输入好像有点问题呢')
                return
            if not (inputFilter.is_valid(user_class)
                    and inputFilter.check_length(user_class)):
                goapi.sendMsg(user_id, '输入好像有点问题呢')
                return

        except:
            goapi.sendMsg(user_id, '输入好像有点问题呢')
        else:
            if (dbconn.check_register(user_id)):
                goapi.sendMsg(user_id, '您已注册过啦~')
                re_register_user(user_id, user_name, user_class)
            else:
                register_user(user_id, user_name, user_class)
        return
    if ('/admin' in message):
        user_class = dbconn.get_user(user_id)['user_class']
        upload_date = time.strftime("%Y-%m-%d", time.localtime())
        print(user_id)
        if (user_id in admin_list.keys()):
            group_id = admin_list[user_id]
            if ('群提醒' in message):
                send_alert(group_id,
                           dbconn.get_user(user_id)['user_class'], 'group')
            elif ('提醒' in message):
                send_alert(user_id,
                           dbconn.get_user(user_id)['user_class'], 'private')
                upload_date = time.strftime("%Y-%m-%d", time.localtime())
                time.sleep(1)
                #ocr_err_upload(user_id,user_class,upload_date)
                ocr_err_upload(user_id, user_class, upload_date)
                time.sleep(2)
                send_images_info(user_id, user_class)
            elif ('打包' in message):
                cmp_ret = compress.zip_file(
                    upload_date,
                    dbconn.get_user(user_id)['user_class'])
                goapi.sendMsg(user_id,
                              f"---打包完毕---\n共处理:{cmp_ret['file_num']}张照片")
                goapi.sendMsg(
                    user_id,
                    '下载地址:' + urllib.parse.quote(cmp_ret['file_name']))
            elif ('成员' in message):
                list_class_menbers(user_id, user_class)
            elif ('核对' in message):
                goapi.sendMsg(user_id, 'get')
                err_imgid = message.split('@')[1]
                ocr_times = message.split('@')[2]
                ocr_scores = message.split('@')[3]
                if (dbconn.err_check):
                    err_code = dbconn.err_check(err_imgid)
                    if (err_code):
                        dbconn.manual_update(ocr_times, ocr_scores, err_imgid)
                        goapi.sendMsg(
                            user_id,
                            f"人工校对完成:{dbconn.get_user_by_migid(err_imgid)}\n参赛次数:{ocr_times}\n积分:{ocr_scores}"
                        )
                elif (err_code == 0):
                    goapi.sendMsg(user_id, '该图片无需校对,请重新检查输入的id')
                elif (err_code == -1):
                    goapi.sendMsg(
                        user_id,
                        f"已经人工校对过了,覆盖校对:\n{dbconn.get_user_by_migid(imgid)}\n参赛次数:{ocr_times}\n积分:{ocr_scores}"
                    )

            else:
                goapi.sendMsg(user_id, "目前支持以下管理指令呢:\n群提醒\n提醒\n打包\n成员\n")
        else:

            goapi.sendMsg(user_id, "无管理权限")

    if ('/sudo' in message
            and (user_id == '601179193' or user_id == "29242764"
                 or user_id == "1476821890" or user_id == "3439911708")):
        #try:

        if ('增加管理员' in message):
            admin_id = message.split('@')[1]
            group_id = message.split('@')[2]
            goapi.sendMsg(user_id, str(add_admin(admin_id, group_id)))
        elif ('删除管理员' in message):
            admin_id = message.split('@')[1]
            goapi.sendMsg(user_id, str(del_admin(admin_id)))
        elif ('展示管理员' in message):
            goapi.sendMsg(user_id, str(show_admin()))
        else:
            goapi.sendMsg(user_id, '增加管理员\n删除管理员\n展示管理员')
        #except:
        #goapi.sendMsg(user_id,'增加管理员\n删除管理员\n展示管理员')
        #else:
        #pass

    return
Exemple #4
0
def readMsg(user_id, message):
    #处理消息核心
    user_id = str(user_id)
    #管理员列表
    admin_list = show_admin()

    if ('image' in message):
        if (dbconn.check_register(user_id)):
            #用户已注册
            get_img(user_id, message)
        else:
            #用户未注册
            goapi.sendMsg(user_id,
                          '您还没注册呢,请输入例如"注册@张三@计科20-2"\n 班级请严格按格式输入,否则可能统计不上哦')
        return
    if ('注册' in message):
        try:
            user_name = message.split('@')[1]
            user_class = message.split('@')[2]
            #简单过滤用户输入
            if not (inputFilter.is_Chinese(user_name)
                    and inputFilter.check_length(user_name)):
                goapi.sendMsg(user_id, '输入好像有点问题呢')
                return
            if not (inputFilter.is_valid(user_class)
                    and inputFilter.check_length(user_class)):
                goapi.sendMsg(user_id, '输入好像有点问题呢')
                return

        except:
            goapi.sendMsg(user_id, '输入好像有点问题呢')
        else:
            if (dbconn.check_register(user_id)):
                goapi.sendMsg(user_id, '您已注册过啦~')
                re_register_user(user_id, user_name, user_class)
            else:
                register_user(user_id, user_name, user_class)
        return
    if ('/admin' in message):
        user_class = dbconn.get_user(user_id)['user_class']
        upload_date = time.strftime("%Y-%m-%d", time.localtime())
        print(user_id)
        if (user_id in admin_list.keys()):
            group_id = admin_list[user_id]
            if ('群提醒' in message):
                send_alert(group_id,
                           dbconn.get_user(user_id)['user_class'], 'group')
            elif ('提醒' in message):
                send_alert(user_id,
                           dbconn.get_user(user_id)['user_class'], 'private')
                upload_date = time.strftime("%Y-%m-%d", time.localtime())
                time.sleep(1)
                #ocr_err_upload(user_id,user_class,upload_date)
                ocr_err_upload(user_id, user_class, upload_date)
                time.sleep(2)
                send_images_info(user_id, user_class)
            elif ('打包' in message):
                cmp_ret = compress.zip_file(
                    upload_date,
                    dbconn.get_user(user_id)['user_class'])
                goapi.sendMsg(user_id,
                              f"---打包完毕---\n共处理:{cmp_ret['file_num']}张照片")
                goapi.sendMsg(
                    user_id, '下载地址:http://static.catop.top:8001/' +
                    urllib.parse.quote(cmp_ret['file_name']))
            elif ('成员' in message):
                list_class_menbers(user_id, user_class)
            else:
                goapi.sendMsg(user_id, "目前支持以下管理指令呢:\n群提醒\n提醒\n打包\n成员\n")
        else:

            goapi.sendMsg(user_id, "无管理权限")

    if ('/sudo' in message
            and (user_id == '601179193' or user_id == "29242764")):
        #try:

        if ('增加管理员' in message):
            admin_id = message.split('@')[1]
            group_id = message.split('@')[2]
            goapi.sendMsg(user_id, str(add_admin(admin_id, group_id)))
        elif ('删除管理员' in message):
            admin_id = message.split('@')[1]
            goapi.sendMsg(user_id, str(del_admin(admin_id)))
        elif ('展示管理员' in message):
            goapi.sendMsg(user_id, str(show_admin()))
        else:
            goapi.sendMsg(user_id, '增加管理员\n删除管理员\n展示管理员')
        #except:
        #goapi.sendMsg(user_id,'增加管理员\n删除管理员\n展示管理员')
        #else:
        #pass

    return