Example #1
0
async def delf(session: CommandSession):
    admin = read('admin', 'admin')
    if str(session.ctx['user_id']) == admin:
        delList = []
        delDir = read('server', 'http_path')
        delList = os.listdir(delDir)
        for f in delList:
            filePath = os.path.join(delDir, f)
            if os.path.isfile(filePath):
                os.remove(filePath)
            elif os.path.isdir(filePath):
                shutil.rmtree(filePath, True)
        shutil.copyfile('404.html', delDir + '404.html')
        await session.send('文件已清除')
    else:
        await session.send('您没有权限进行此操作')
Example #2
0
def login(accent, password, session: CommandSession):
    global count, header
    APP_ID = read('baidu_API', 'APP_ID')
    APP_KEY = read('baidu_API', 'APP_KEY')
    SECRET_KEY = read('baidu_API', 'SECRET_KEY')
    client = AipOcr(APP_ID, APP_KEY, SECRET_KEY)
    r = requests.get('http://aao-eas.nuaa.edu.cn/eams/login.action',
                     headers=header)
    session = r.cookies
    passsha = re.findall(r"CryptoJS.SHA1\('(.+?)'", r.text)[0]
    passsha = hashlib.sha1((passsha + password).encode('utf-8')).hexdigest()
    r = requests.get('http://aao-eas.nuaa.edu.cn/eams/captcha/image.action',
                     headers=header,
                     cookies=session)
    options = {'language_type': 'ENG'}
    if count < 499:
        yzm = client.basicAccurate(r.content, options)["words_result"]
        count = count + 1
    else:
        session.send('服务器负载过大,将使用低精度验证码识别,敬请谅解')
        yzm = client.basicGeneral(r.content, options)["words_result"]
    with open('wb.png', 'wb') as code:
        code.write(r.content)
    code.close()
    yzm = re.findall(r"words': '(.+?)'", str(yzm))[0]
    yzm = yzm.replace(' ', "")
    print(yzm)

    data = {
        'username': accent,
        'password': str(passsha),
        'captcha_response': yzm
    }
    time.sleep(1)
    r = requests.post('http://aao-eas.nuaa.edu.cn/eams/login.action',
                      data=data,
                      cookies=session,
                      headers=header)
    if r.text.find('验证码不正确', 0, len(r.text)) != -1:
        return 1
    elif r.text.find('密码错误', 0, len(r.text)) != -1:
        return 0
    elif r.text.find('不存在', 0, len(r.text)) != -1:
        return 2
    else:
        return session
Example #3
0
async def report(session: CommandSession):
    text = session.get('text', prompt='请输入要反馈的内容')
    bot = nonebot.get_bot()
    admin = read('admin', 'admin')
    await bot.send_private_msg(user_id=admin,
                               message=str(session.ctx['user_id']) +
                               '反馈问题:\n' + text)
    await session.send('反馈成功')
Example #4
0
async def add_chmod(session: CommandSession):
    admin = read('admin', 'admin')
    if str(session.ctx['user_id']) == admin:
        accnet = session.get('accent', prompt='请输入账号')
        file = open('dict.txt', 'a+')
        file.write(accnet + ' ?\n')
        file.close()
        await session.send('添加成功')
    else:
        await session.send('您没有权限进行此操作')
Example #5
0
async def _():
    delList = []
    delDir = read('server', 'http_path')
    delList = os.listdir(delDir)
    for f in delList:
        filePath = os.path.join(delDir, f)
        if os.path.isfile(filePath):
            os.remove(filePath)
        elif os.path.isdir(filePath):
            shutil.rmtree(filePath, True)
    shutil.copyfile('404.html', delDir + '404.html')
Example #6
0
async def course_cal(session: CommandSession):
    exam_state = get_exam_state(str(session.ctx['user_id']))
    if exam_state != 0:
        accentlist = chmod.read_chmod()
        http_path = read('server', 'http_path')
        address = read('server', 'address')
        if str(session.ctx['user_id']) in accentlist:
            if accentlist[str(session.ctx['user_id'])] != '?':
                accent = accentlist[str(session.ctx['user_id'])]
                password = session.get('password', prompt='请输入密 码')
                await session.send('请稍后,正在尝试连接教务系统')
                cookie = login(accent, password, session)
                if cookie == 1:
                    await session.send('验证码识别错误,请重试')
                elif cookie == 0:
                    await session.send('密码错误,请重试')
                elif cookie == 2:
                    await session.send('账号不存在,请尝试重新绑定账号')
                else:
                    time.sleep(1)
                    table = get_course(cookie, '')
                    lessons = parseCourseTable(table)
                    semester_start_date = datetime(
                        2019, 9, 2, 0, 0, 0, tzinfo=timezone('Asia/Shanghai'))
                    cal = create_ics(lessons, semester_start_date)
                    export_ics(cal, str(session.ctx['user_id']))
                    filename = 'NUAAiCal-Data/' + str(
                        session.ctx['user_id']) + '.ics'
                    shutil.copyfile(
                        os.path.abspath(filename),
                        http_path + str(session.ctx['user_id']) + '.ics')
                    await session.send('点击网址下载日历文件 http://' + address + '/' +
                                       str(session.ctx['user_id']) + '.ics')
                    await session.send(
                        '本日历模块来自miaotony的github开源项目,感谢他对开源社区做出的贡献')
            else:
                await session.send('清先绑定账号')
        else:
            await session.send('您的账号权限不足')
Example #7
0
async def spread(session: CommandSession):
    admin = read('admin', 'admin')
    if str(session.ctx['user_id']) == admin:
        text = session.get('text', prompt='请输入内容')
        file = open('dict.txt', 'r')
        for line in file.readlines():
            line = line.strip()
            k = int(line.split(' ')[0])
            bot = nonebot.get_bot()
            if k != '11111':
                await bot.send_private_msg(user_id=k, message=text)
        await session.send('发送成功')
    else:
        await session.send('您没有权限进行此操作')
Example #8
0
async def course(session: CommandSession):
    exam_state = get_exam_state(str(session.ctx['user_id']))
    if exam_state != 0:
        accentlist = chmod.read_chmod()
        http_path = read('server', 'http_path')
        address = read('server', 'address')
        if str(session.ctx['user_id']) in accentlist:
            if accentlist[str(session.ctx['user_id'])] != '?':
                accent = accentlist[str(session.ctx['user_id'])]
                password = session.get('password', prompt='请输入密 码')
                await session.send('请稍后,正在尝试连接教务系统')
                cookie = login(accent, password, session)
                if cookie == 1:
                    await session.send('验证码识别错误,请重试')
                elif cookie == 0:
                    await session.send('密码错误,请重试')
                elif cookie == 2:
                    await session.send('账号不存在,请尝试重新绑定账号')
                else:
                    time.sleep(1)
                    week = get_week(cookie)
                    table = get_course(cookie, week)
                    table = table.replace('/eams',
                                          'http://aao-eas.nuaa.edu.cn/eams')
                    with open(http_path + str(session.ctx['user_id']) +
                              '.html',
                              'w',
                              encoding='utf-8') as f:
                        f.write(table)
                        f.close()
                    await session.send('点击网址查看课程表 http://' + address + '/' +
                                       str(session.ctx['user_id']) + '.html')
            else:
                await session.send('清先绑定账号')
        else:
            await session.send('您的账号权限不足')