def recent_contest():
    headers = {
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.146 Safari/537.36'
    }
    url="http://algcontest.rainng.com"
    val=requests.get(url,headers=headers)
    res=json.loads(val.content)
    sum=""
    i = 0
    for it in res:
        i=i+1
        sum = sum  + '比赛名称: '
        sum = sum + it['name']
        sum = sum + '\n比赛时间: '
        sum = sum + it['startTime']
        sum = sum + '\n比赛连接: '
        sum = sum + it['link']
        sum = sum + '\n'
        if i == 5:
            break
    return sum

Rcontest = on_command("最近比赛", priority=2)
@Rcontest.handle()
async def Rcontest_(bot: Bot, event: Event, state: dict):
    if int(event.get_user_id()) != event.self_id:
        await bot.send(
            event=event,
            message = str(recent_contest())
        )

# Dream OJ 查询用户
DOJ_USER = on_command("DOJ", priority=2)
@DOJ_USER.handle()
async def DOJ_USER_(bot: Bot, event: Event, state: dict):
    if int(event.get_user_id()) != event.self_id:
        args = str(event.message).strip()  # 首次发送命令时跟随的参数,例:/天气 上海,则args为上海
        if args:
            state["name"] = args  # 如果用户发送了参数则直接赋值


@DOJ_USER.got("name", prompt="请输入你想查询的用户名...")
async def handle_DOJ_USER(bot: Bot, event: Event, state: dict):
    name = state["name"]
    url="http://acm.mangata.ltd/api/?"
    headers = {
            'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.146 Safari/537.36'
        }
    query="query {user(uname: \"" + name + "\") {uname,mail,loginat,regat,role,avatarUrl}}"
    url = url + query
    val=requests.get(url,headers=headers)
    res=json.loads(val.content)
    it=res['data']['user']
    ans=""
    if res['data']['user'] == None:
        ans = ans + "查无此人"
        await bot.send(
            event = event,
            message=ans
        )
    else:
        ans ="\n用户昵称: " + it['uname']
        ans = ans + "\n注册邮箱: " + it['mail']
        ans = ans + "\n上次登陆: " + it['loginat']
        ans = ans + "\n注册时间: " + it['regat']
        ans = ans + "\n用户身份: " + it['role']
        qq=str(it['mail'])
        ava = "https://q1.qlogo.cn/g?b=qq&nk="
        if qq.find("@qq.com") == -1:
            ava="http://acm.mangata.ltd/file/2/12.jpg"
        else:
            qq=qq.strip('@qq.com')
            ava=ava+qq+"&s=160"
        await bot.send(
            event = event,
            message=MessageSegment.image(ava) + ans
        )

#获取随机题目
def get_problem():
    url="http://acm.mangata.ltd/api/?"
    headers = {
            'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.146 Safari/537.36'
        }
    id=str(random.randint(1,1786))
    query="query{problem(id:" + id + "){pid,title,nSubmit,nAccept,difficulty,tag}}"
    url = url + query
    print(url)
    val=requests.get(url,headers=headers)

    res=json.loads(val.content)
    print(res)
    it=res["data"]["problem"]
    if it == None:
        return str("题目出错请联系Mangata!")
    else:
        link="http://acm.mangata.ltd/p/" + it['pid']
        tag = ""
        l = len(it['tag'])
        j = 1
        for i in it['tag']:
            if j < l:
                tag = tag + i + "、"
            else:
                tag = tag + i
            j=j+1
        ans = "题目名称: " + it['title']
        ans = ans + "\n题目连接: " + link
        ans = ans + "\n算法标签: " + tag
        ans = ans + "\n总提交数: " + str(it['nSubmit'])
        ans = ans + "\n总通过数: " + str(it['nAccept'])
        ans = ans + "\n预估难度: " + str(it['difficulty'])
        ans = ans + "\n骚年快来挑战吧!别忘了写题解噢!"
        return ans



# Dream OJ 查询用户
DOJ_PROBLEM = on_command("随机题目", priority=2)
@DOJ_PROBLEM.handle()
async def DOJ_PROBLEM_(bot: Bot, event: Event, state: dict):
    if int(event.get_user_id()) != event.self_id:
        ans = get_problem()
        await bot.send(
            event = event,
            message=ans
        )

0 comments

No comments so far...