コード例 #1
0
async def handle_message_solution(message, client):
    tag = message.content[9:].strip()
    if "-h" in message.content:
        await send_message(
            message.channel,
            "usage: !solution <tag>, use this to see the code for any solution in the knowledge base"
        )
        return
    prob = get_kattis_problem(tag)
    if prob == None:
        await send_message(message.channel, "that problem does not exist")
        return None
    sol = get_solution(tag)
    if sol == None:
        await send_message(message.channel, tag + " is unsolved")
        return None
    file = discord.File(sol[3])
    await message.channel.send(file=file)
コード例 #2
0
async def handle_message_status(message, client):
    if "-h" in message.content:
        await send_message(
            message.channel,
            "usage: !status <tag>, use this to determine if any Kattis Problem has been solved yet"
        )
        return

    tag = message.content[7:].lower().strip()

    prob = get_kattis_problem(tag)
    if prob == None:
        await send_message(message.channel, "that problem does not exist")
        return
    sol = get_solution(tag)
    if sol == None:
        res = tag + " is unsolved"
    else:
        res = tag + " has been solved"
    await send_message(message.channel, res)
コード例 #3
0
async def handle_message_writeup(message, client):
    if "-h" in message.content:
        await send_message(
            message.channel,
            "usage: !writeup [contest_name], use this to generate a writeup of a contest using the solutions available in the knowledge base"
        )
        return

    progress = make_progress(1, 2)
    response = await send_message(message.channel,
                                  "finding contest\n" + progress)

    cname = message.content[8:].strip()

    problem_list = await get_problem_list(cname, response)

    file = open(cname + ".txt", "w")

    done = []

    x = 0
    for tag in problem_list:
        if tag in done:
            continue
        done.append(tag)
        file.write(str(chr(65 + x)) + ": " + tag + "\n\n")
        x += 1
        prob = get_kattis_problem(tag)
        sol = get_solution(tag)
        if sol == None:
            file.write(tag + " is not currently in the knowledge base\n\n")
        else:
            prob = open(sol[4], "r")
            file.write(prob.read() + "\n\n")
    file.close()
    sendfile = discord.File(cname + ".txt")
    os.remove(cname + ".txt")
    await message.channel.send(file=sendfile)
    await response.delete()
コード例 #4
0
def on_accepted(file, fname, user):
    prefix = fname.split('.')[0]
    annotation = scan(fname)
    parsed = parse_annotation(annotation)
    directory = "kb/"+prefix
    if not os.path.exists(directory):
        os.makedirs(directory)
    sol_path ="kb/"+prefix+"/"+fname
    copyfile(fname, sol_path)
    with open(prefix+".txt", 'w') as f:
        for ss in annotation:
            f.write(ss)
            if ss.startswith("TAGS:"):
                tags = ss[5:]
    write_up_path = "kb/"+prefix+"/"+prefix+".txt"
    copyfile(prefix+".txt", write_up_path)
    os.remove(prefix+".txt")
    kattis_prob = get_kattis_problem(prefix)
    kattis_id = kattis_prob[0]
    prob_id = kattis_prob[1]
    #we already have user

    insert_solution(kattis_id, prob_id, user, sol_path, write_up_path, parsed)
    return "Accepted! Adding your solution to the knowledge base."