示例#1
0
文件: stats.py 项目: NeStell/overbot
    async def statistics(self, ctx, platform: Platform, *, username):
        """Returns player both quick play and competitive statistics.

        `<platform>` - The platform of the player to get stats for.
        `<username>` - The username of the player to get stats for.

        Platforms
        - pc (bnet)
        - playstation (ps, psn, play)
        - xbox (xbl)
        - nintendo-switch (nsw, switch)

        Username formatting
        - pc: BattleTag (format: name#0000)
        - playstation: Online ID
        - xbox: Gamertag
        - nintendo-switch: Nintendo Switch ID (format: name-code)

        BattleTag example: Timmy#22340
        Nintendo Switch ID example: name-7alf327e36d5d1d8f507e765u5a2ech7
        """
        try:
            message = await ctx.send(embed=self.bot.loading_embed())
            data = await Request(platform=platform, username=username).get()
        except RequestError as e:
            await self.bot.cleanup(message)
            return await ctx.send(e)

        profile = Player(data, platform=platform, username=username)
        if profile.is_private:
            embed = profile.private()
        else:
            try:
                embed = profile.get_statistics(ctx)
            except PlayerException as e:
                await self.bot.cleanup(message)
                return await ctx.send(e)

        await self.bot.cleanup(message)
        await self.bot.paginator.Paginator(pages=embed).start(ctx)
示例#2
0
    async def statistics(self, ctx, index: Index = None, member: discord.Member = None):
        """Shows a member's Overwatch both quick play and competitive statistics.

        `[index]` - The profile's index you want to see the statistics for.
        `[member]` - The mention or the ID of a Discord member of the current server.

        If no index is given then the profile used will be the main one.
        If no member is given then the statistics returned will be yours.

        If you want to see a member's stats, you must enter both the index and the member.
        """
        async with ctx.typing():
            member = member or ctx.author

            try:
                _, platform, username = await self.get_profile(member, index=index)
            except MemberHasNoProfile as e:
                return await ctx.send(e)
            except IndexError:
                return await ctx.send(
                    f'Invalid index. Use "{ctx.prefix}help profile statistics" for more info.'
                )

            try:
                data = await Request(platform=platform, username=username).get()
            except RequestError as e:
                return await ctx.send(e)

            profile = Player(data, platform=platform, username=username)
            if profile.is_private:
                embed = profile.private()
            else:
                try:
                    embed = profile.get_statistics(ctx)
                except NoStatistics as e:
                    return await ctx.send(e)
                await self.bot.paginator.Paginator(pages=embed).start(ctx)