Exemple #1
0
async def print_summary(hobchannel):
    topic = info.get_current_hobby_name()

    if topic == JSON_NO_HOBBY:
        await hobchannel.send(
            "No current hobby. Use !newhobby to pick a new hobby.")
        return

    try:
        await hobchannel.send("<" + wikipedia.page(topic).url + ">\n" +
                              wikipedia.summary(topic, 3))
    except wikipedia.exceptions.PageError:
        await hobchannel.send("Could not find or suggest wikipedia page for " +
                              topic)
Exemple #2
0
async def print_current_hobby(hobchannel):
    current = info.get_current_hobby_name()
    vetoes = info.get_current_vetoes()
    notes = info.get_current_notes()

    if current == JSON_NO_HOBBY:
        await hobchannel.send(
            "No current hobby. Use !newhobby to pick a new hobby.")
        return

    await hobchannel.send(f"Current hobby is {current} ({vetoes} vetoes).")

    if len(notes) > 0:
        await hobchannel.send(f"Notes: \n{notes}")
Exemple #3
0
async def add_note_to_current(note, authorname, hobchannel):
    note = helpers.unembed_links(note)

    jsondata = futils.get_json_from_file(PATH_CURRENT)

    current = info.get_current_hobby_name()
    notes = info.get_current_notes()
    notes += ("\n" if len(notes) > 0 else "") + note + f" ({authorname})"

    jsondata["notes"] = notes

    with open(PATH_CURRENT, "w") as currentfile:
        json.dump(jsondata, currentfile)

    await hobchannel.send(f"Added note to {current}. Full notes:\n{notes}")
Exemple #4
0
async def handle_veto(author, hobchannel):
    current = info.get_current_hobby_name()
    vetoes = info.get_current_vetoes()
    vetoers = info.get_current_vetoers()

    nick = author.nick
    if (nick == None):
        nick = author.name

    if (author.name in vetoers):
        await hobchannel.send(f"{nick} has already vetoed {current}!")
        return

    if (vetoes + 1) >= NUM_VETOES_TO_SKIP:
        #creating this now means we don't have to do anything
        #fancy to get an 'and' in the output string
        vetoersstr = ", ".join(vetoers)

        #add user to vetoers
        vetoers.append(author.name)

        jsondata = futils.get_json_from_file(PATH_CURRENT)

        jsondata["vetoers"] = vetoers

        with open(PATH_CURRENT, "w") as currentfile:
            json.dump(jsondata, currentfile)

        helpers.move_current_to_other_file(PATH_VETOED, hobchannel)
        await hobchannel.send(
            f"{current} has been vetoed by {vetoersstr}, and {author.name}!")
    else:
        vetoers.append(author.name)  #use username, not nickname

        jsondata = futils.get_json_from_file(PATH_CURRENT)

        jsondata["vetoers"] = vetoers

        with open(PATH_CURRENT, "w") as currentfile:
            json.dump(jsondata, currentfile)

        await hobchannel.send(f"{nick} has voted to veto {current}!")
Exemple #5
0
def move_current_to_other_file(path, hobchannel):
    current = info.get_current_hobby_name()
    vetoers = info.get_current_vetoers()
    notes = info.get_current_notes()

    #create new entry with info from current hobby
    newentry = {current: {"vetoers": vetoers, "notes": notes}}

    #get dict of completed hobbies
    with open(path) as f:
        filejson = json.load(f)

    #add now-completed hobby to list of completed hobbies
    filejson.update(newentry)

    #write back to file
    with open(path, "w") as f:
        json.dump(filejson, f)

    #reset current hobby
    clear_current_hobby(hobchannel)
Exemple #6
0
async def mark_current_as_complete(hobchannel):
    current = info.get_current_hobby_name()
    helpers.move_current_to_other_file_with_date(PATH_COMPLETE, hobchannel)

    await hobchannel.send(f"Completed {current}!")
Exemple #7
0
async def move_current_to_later(hobchannel):
    current = info.get_current_hobby_name()
    helpers.move_current_to_other_file(PATH_LATER, hobchannel)

    await hobchannel.send(f"We'll get back to {current} later.")