示例#1
0
文件: main.py 项目: monkeydg/pog-bot
    async def on_ready():
        # Initialise matches channels
        Match.init_channels(client, cfg.channels["matches"])

        modules.roles.init(client)
        # Init signal handler
        modules.signal.init()

        # fetch rule message, remove all reaction but the bot's
        channel = client.get_channel(cfg.channels["rules"])
        msg = await channel.fetch_message(channel.last_message_id)
        if msg.author.id == client.user.id:
            ctx = _interactions_handler.get_new_context(msg)
            await disp.RULES.edit(ctx)
        else:
            ctx = _interactions_handler.get_new_context(channel)
            await disp.RULES.send(ctx)

        # Update all players roles
        for p in Player.get_all_players_list():
            await modules.roles.role_update(p)
        _add_main_handlers(client)

        if not modules.lobby.get_all_names_in_lobby():
            try:
                last_lobby = modules.database.get_field(
                    "restart_data", 0, "last_lobby")
            except KeyError:
                pass
            else:
                for p_id in last_lobby:
                    try:
                        player = Player.get(int(p_id))
                        if player and not modules.lobby.is_lobby_stuck(
                        ) and player.is_registered:
                            modules.lobby.add_to_lobby(player)
                    except ValueError:
                        pass
                modules.database.set_field("restart_data", 0,
                                           {"last_lobby": list()})
            names = modules.lobby.get_all_names_in_lobby()
            if names:
                await disp.LB_QUEUE.send(
                    ContextWrapper.channel(cfg.channels["lobby"]),
                    names_in_lobby=modules.lobby.get_all_names_in_lobby())
        modules.loader.unlock_all(client)
        log.info('Client is ready!')
        await disp.RDY.send(ContextWrapper.channel(cfg.channels["spam"]),
                            cfg.VERSION)
示例#2
0
def get_all_stats():
    all_stats = list()
    for p in Player.get_all_players_list():
        loop = asyncio.get_event_loop()
        stat_player = loop.run_until_complete(
            PlayerStat.get_from_database(p.id, p.name))
        all_stats.append(stat_player)

    print("Highest Kills per match:")
    key = operator.attrgetter("kpm")
    sorted_stats = sorted(all_stats, key=key, reverse=True)
    for s in sorted_stats[:5]:
        print(
            f"id: [{s.id}], name: [{s.name}], nb_match: [{s.nb_matches_played}], value: [{s.kpm}]"
        )

    print("Highest Number of matches played, top 5:")
    key = operator.attrgetter("nb_matches_played")
    sorted_stats = sorted(all_stats, key=key, reverse=True)
    for s in sorted_stats[:5]:
        print(
            f"id: [{s.id}], name: [{s.name}], value: [{s.nb_matches_played}]")