コード例 #1
0
 async def pushboard_info(self, ctx):
     """Provides info on guild's pushboard"""
     guild_config = await self.bot.get_guild_config(ctx.guild.id)
     table = CLYTable()
     table.title = guild_config.pushboard_title or "PushBoard"
     if guild_config.pushboard_render == 2:
         table.add_rows([[0, 4721, 56, "Rowcoy"],
                         [1, 4709, 42, "Stitch"],
                         [2, 4658, 37, "t3pps"]])
         render = table.render_option_2()
     else:
         table.add_rows([[0, 4721, "Rowcoy (Awesome Clan)"],
                         [1, 4709, "Stitch (Lilo's Clan)"],
                         [2, 4658, "t3pps (Other Clan)"]])
         render = table.render_option_1()
     fmt = f"**PushBoard Example Format:**\n\n{render}\n" \
           f"**Icon:** Please see the icon displayed above.\n"
     channel = guild_config.pushboard
     data = []
     if channel is None:
         data.append("**Channel:** #deleted-channel")
     else:
         data.append(f"**Channel:** {channel.mention}")
     sql = "SELECT clan_name, clan_tag FROM clans WHERE guild_id = $1"
     fetch = await ctx.db.fetch(sql, ctx.guild.id)
     data.append(f"**Clans:** {', '.join(f'{n[0]} ({n[1]})' for n in fetch)}")
     fmt += "\n".join(data)
     embed = discord.Embed(color=self.bot.color,
                           description=fmt)
     embed.set_author(name="PushBoard Info",
                      icon_url=guild_config.icon_url or "https://cdn.discordapp.com/emojis/"
                                                        "592028799768592405.png?v=1")
     await ctx.send(embed=embed)
コード例 #2
0
 async def update_pushboard(self, guild_id):
     guild_config = await self.get_guild_config(guild_id)
     if not guild_config.updates_toggle:
         return
     if not guild_config.pushboard:
         return
     sql = "SELECT DISTINCT clan_tag FROM clans WHERE guild_id = $1"
     fetch = await self.bot.pool.fetch(sql, guild_id)
     clans = await self.bot.coc.get_clans((n[0] for n in fetch)).flatten()
     players = []
     for n in clans:
         players.extend(p for p in n.itermembers)
     sql = ("SELECT player_tag, current_trophies, current_attack_wins - starting_attack_wins AS attacks "
            "FROM players "
            "WHERE player_tag = ANY($1::TEXT[]) "
            "ORDER BY current_trophies "
            "LIMIT 100")
     fetch = await self.bot.pool.fetch(sql, [n.tag for n in players])
     db_players = [DatabasePlayer(bot=self.bot, record=n) for n in fetch]
     players = {n.tag: n for n in players if n.tag in set(x.player_tag for x in db_players)}
     message_count = math.ceil(len(db_players) / 20)
     messages = await self.get_updates_messages(guild_id, number_of_msg=message_count)
     if not messages:
         return
     for i, v in enumerate(messages):
         player_data = db_players[i * 20: (i + 1) * 20]
         table = CLYTable()
         for x, y in enumerate(player_data):
             index = i * 20 + x
             if guild_config.pushboard_render == 2:
                 table.add_row([index,
                                y.current_trophies,
                                players.get(y.player_tag, MockPlayer()).name])
             else:
                 table.add_row([index,
                                y.current_trophies,
                                y.attacks,
                                players.get(y.player_tag, MockPlayer()).name])
         fmt = table.render_option_2() if \
             guild_config.pushboard_render == 2 else table.render_option_1()
         e = discord.Embed(color=self.bot.color,
                           description=fmt,
                           timestamp=datetime.utcnow())
         e.set_author(name=guild_config.pushboard_title or "Trophy Push Leaderboard",
                      icon_url=guild_config.icon_url or "https://cdn.discordapp.com/emojis/"
                                                        "592028799768592405.png?v=1")
         e.set_footer(text="Last Updated")
         await v.edit(embed=e, content=None)