Exemplo n.º 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)
Exemplo n.º 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)
def verify_annotation(fname):
    prefix = fname.split('.')[0]
    solved = get_solution(prefix)
    if solved != None:
        return "this problem is already solved"
    annotation = scan(fname)
    if len(annotation) == 0:
        return "denied, annotation not formatted correctly or does not exist"
    parsed = parse_annotation(annotation)
    if not parsed[0].lower().endswith(prefix.lower()):
        return "denied, annotation problem url does not match solution name"
    if len(parsed[1]) == 0 or len(parsed[1][0]) == 0:
        return "denied, at least one problem tag is required"
    if len(parsed[2]) < 5:
        return "denied, explanation was trivially short"
    if("TAGS:" not in annotation[1]):
        return "denied, no list of tags"
    if("EXPLANATION:" not in annotation[2]):
        return "denied, error reading explanation"
    return None
Exemplo n.º 4
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()