Esempio n. 1
0
async def team(ctx):
    if not config['game_ongoing']: return
    member = ctx.message.author
    try:
        p = models.Player()
        p.custom_load("discord_id = ?", (member.id, ))
        if p.last_active_day != helpers.get_game_day():
            p.last_active_day = helpers.get_game_day()
            p.update()
            models.save()
    except Exception:
        await ctx.send("I don't think you're playing, {}\n\
            (If you think this is a mistake, please talk to a Lord or the King)"
                       .format(member.mention))
        return
    t = models.Team()
    t.load(p.team_id)
    l = models.Location()
    l.load(t.current_location_id)
    funding_table = paymentreducer.get_funding_table(p.team_id,
                                                     helpers.get_game_day())
    await ctx.send(
        "Your team is in **{}**, with at least **{}km** to go!\nHere is how today's funding is going:\n{}"
        .format(
            l.name,
            graphanalyzer.dijkstra(graphanalyzer.graph, t.current_location_id,
                                   0), "```" + funding_table + "```"))
Esempio n. 2
0
async def end_game():
    logging.info("Time to end the game!")
    ch = get(client.get_all_channels(),
             id=config["channels"]["progress-announcements"])
    config['game_ongoing'] = 0
    with open(Path(__file__).parent / 'config.json', 'w') as f:
        json.dump(config, f, indent=4)
    scheduledjobs.config = config
    helpers.config = config
    # Invalidate All Oustanding Logs
    logs = models.Log_list()
    logs.custom_load("sent = ?", (0, ))
    if len(logs.items) > 0:
        try:
            for log in logs.items:
                log.sent = 1
                log.update()
        except Exception as e:
            logging.error("Failed to invalidate old logs - {}".format(e))
        models.save()
    # Load winners
    winners = []
    teams = models.Team_list()
    teams.custom_load("team_id > ?", (0, ))
    for t in teams.items:
        start_loc = t.current_location_id
        if start_loc == 1:
            start_loc = 0
        winners.append(
            (t.name, graphanalyzer.dijkstra(graphanalyzer.graph, start_loc,
                                            0)))
    winners.sort(key=lambda x: x[1], reverse=True)
    # Make a big deal of everything, really.
    try:
        await ch.send(
            "All right, adventurers! The game has ended! Drumroll please!!!")
        await (asyncio.sleep(5))
        await ch.send("In third place, with {}km remaining, the {}!".format(
            winners[0][1], winners[0][0]))
        await (asyncio.sleep(3))
        await ch.send("In second place, with {}km remaining, the {}!!".format(
            winners[1][1], winners[1][0]))
        await (asyncio.sleep(3))
        await ch.send(
            "Finally, in first place, the {}!!!!!!!!! Congratulations!".format(
                winners[2][0]))
        await (asyncio.sleep(3))
        await ch.send(
            "Thank you all for playing! I hope you had fun! Now, I'm going to take a nap. Maybe we can do this again some time :sweat_smile:"
        )
    except AttributeError:
        logging.info("Can't see the channel. We'll get 'em next time.")
        return
Esempio n. 3
0
def next_location_table(team_id):
    t = graphanalyzer.get_next_location_list(team_id)
    tab = []
    tab.append("```\n")
    for k, v in t.items():
        l = models.Location()
        l.custom_load("name = ?", (k, ))
        tab.append("{}: {} coins, at least {}km from the goal\n".format(
            k, v, graphanalyzer.dijkstra(graphanalyzer.graph, l.location_id,
                                         0)))
    tab.append("```")
    return ''.join(tab)