コード例 #1
0
    async def update_global_board(self):
        query = """SELECT player_tag, donations
                   FROM players 
                   WHERE season_id=$1
                   ORDER BY donations DESC NULLS LAST
                   LIMIT 100;
                """
        fetch_top_players = await self.bot.pool.fetch(
            query, await self.bot.seasonconfig.get_season_id())

        players = await self.bot.coc.get_players(
            (n[0] for n in fetch_top_players)).flatten()

        top_players = {
            n.tag: n
            for n in players
            if n.tag in set(x['player_tag'] for x in fetch_top_players)
        }

        messages = await self.get_board_messages(663683345108172830,
                                                 number_of_msg=5)
        if not messages:
            return

        for i, v in enumerate(messages):
            player_data = fetch_top_players[i * 20:(i + 1) * 20]
            table = CLYTable()

            for x, y in enumerate(player_data):
                index = i * 20 + x
                table.add_row(
                    [index, y[1],
                     top_players.get(y['player_tag'], mock).name])

            fmt = table.donationboard_2()

            e = discord.Embed(colour=self.bot.colour,
                              description=fmt,
                              timestamp=datetime.utcnow())
            e.set_author(name="Global Donationboard",
                         icon_url=self.bot.user.avatar_url)
            e.set_footer(text='Last Updated')
            await v.edit(embed=e, content=None)
コード例 #2
0
ファイル: info.py プロジェクト: bonomali/donationbot
    async def info_donationboard(self, ctx):
        """Gives you info about guild's donationboard.
        """
        table = CLYTable()
        if ctx.config.render == 2:
            table.add_rows([[0, 6532, 'Member (Awesome Clan)'], [1, 4453, 'Nearly #1 (Bad Clan)'],
                            [2, 5589, 'Another Member (Awesome Clan)'], [3, 0, 'Winner (Bad Clan)']
                            ])
            table.title = ctx.config.title or 'DonationBoard'
            render = table.donationboard_2()
        else:
            table.add_rows([[0, 9913, 12354, 'Member Name'], [1, 524, 123, 'Another Member'],
                            [2, 321, 444, 'Yet Another'], [3, 0, 2, 'The Worst Donator']
                            ])
            table.title = ctx.config.title or 'DonationBoard'
            render = table.donationboard_1()

        fmt = f'**DonationBoard Example Format:**\n\n{render}\n**Icon:** ' \
            f'Please see the icon displayed above.\n'

        channel = ctx.config.channel
        data = []

        if channel is None:
            data.append('**Channel:** #deleted-channel')
        else:
            data.append(f'**Channel:** {channel.mention}')

        query = "SELECT clan_name, clan_tag FROM clans WHERE guild_id = $1;"
        fetch = await ctx.db.fetch(query, ctx.guild.id)

        data.append(f"**Clans:** {', '.join(f'{n[0]} ({n[1]})' for n in fetch)}")

        fmt += '\n'.join(data)

        e = discord.Embed(colour=self.bot.colour,
                          description=fmt if len(fmt) < 2048 else f'{fmt[:2040]}...')

        e.set_author(name='DonationBoard Info',
                     icon_url=ctx.config.icon_url or 'https://cdn.discordapp.com/emojis/592028799768592405.png?v=1')

        await ctx.send(embed=e)