コード例 #1
0
 def test_get_unknown_player(self):
     with self.assertRaises(Exception):
         name = "Gorbys"
         responses.add(responses.GET,
                       '{}/{}'.format(player_url, name),
                       body=file_get_contents(
                             './test/fixtures/unknown-player.html'),
                       status=200)
         PhoenixParser(name)
コード例 #2
0
 def test_player_pretty_rr(self):
     name = "Gorbys"
     expected = "Gryphon Knight"
     responses.add(responses.GET,
                   '{}/{}'.format(player_url, name),
                   body=file_get_contents('./test/fixtures/gorbys.html'),
                   status=200)
     char = PhoenixParser(name)
     p = char.info
     self.assertEqual(p.player_pretty_rr, expected)
コード例 #3
0
 def test_player_guild(self):
     name = "Gorbys"
     expected = "Svea Bordercontrol"
     responses.add(responses.GET,
                   '{}/{}'.format(player_url, name),
                   body=file_get_contents('./test/fixtures/gorbys.html'),
                   status=200)
     char = PhoenixParser(name)
     p = char.info
     self.assertEqual(p.player_guild, expected)
コード例 #4
0
 def test_get_last_updated(self):
     name = "Gorbys"
     expected = "4/26/19 9:05:45 AM"
     responses.add(responses.GET,
                   '{}/{}'.format(player_url, name),
                   body=file_get_contents('./test/fixtures/gorbys.html'),
                   status=200)
     char = PhoenixParser(name)
     p = char.info
     self.assertEqual(p.last_updated, expected)
コード例 #5
0
ファイル: bot.py プロジェクト: mattiasr/phoenix-herald
async def show_me(ctx, in_db, sort_order=None):
    if len(in_db) == 0:
        await ctx.send("No saved players, please use '!me add <name>'")
        return
    embed = discord.Embed(title="Characters", color=16312092)

    player_list = []
    for char in in_db:
        try:
            player = PhoenixParser(char)
            p = player.info
            player_dict = {
                'name': p.player_name.capitalize(),
                'level': int(p.player_level),
                'race': p.player_race,
                'realm': p.player_realm,
                'class': p.player_class,
                'rp': p.rp_all_time_amount,
                'rp_as_int': int(p.rp_all_time_amount.replace(',', '')),
                'rr': p.player_rr,
                'rr_name': p.player_pretty_rr
            }
            player_list.append(player_dict)
        except Exception:
            pass
    if sort_order == "level":
        player_list = sorted(player_list,
                             key=lambda k: k['level'],
                             reverse=True)
    elif sort_order == "realm":
        player_list = sorted(player_list, key=lambda k: k['realm'])
    elif sort_order == "rp":
        player_list = sorted(player_list,
                             key=lambda k: k['rp_as_int'],
                             reverse=True)
    elif sort_order == "name":
        player_list = sorted(player_list, key=lambda k: k['name'])
    else:
        player_list = sorted(player_list, key=lambda k: k['name'])

    for x in player_list:
        embed.add_field(
            name="{} (Lvl {} {} {})".format(x['name'], x['level'], x['race'],
                                            x['class']),
            value="Total: {} - {} ({})".format(x['rp'], x['rr'], x['rr_name']),
            inline=False)
    await ctx.send(embed=embed)
コード例 #6
0
async def who(ctx, player):
    try:
        char = PhoenixParser(player)
        p = char.info

        rr = RealmRanks(p.player_rr,
                        int(p.rp_all_time_amount.replace(",", "")))

        embed = discord.Embed(
            title="{}, ({} {})".format(
                p.player_name,
                p.player_race,
                p.player_class),
            url=p.player_url,
            description="Guild: {} - Level: {}".format(
                p.player_guild,
                p.player_level),
            color=p.realm_color
        )

        embed.add_field(
            name="Total: {} - {} ({})".format(
                p.rp_all_time_amount,
                p.player_rr,
                p.player_pretty_rr),
            value="Left to, {}: {}, {}: {}\n\
            Server: #{} - {}: #{} - {}: #{}".format(
                rr.next_rank(pretty=True),
                rr.next_rank(),
                rr.next_level(pretty=True),
                rr.next_level(),
                p.rp_all_time_server,
                p.player_realm,
                p.rp_all_time_realm,
                p.player_class,
                p.rp_all_time_class),
            inline=False)

        embed.add_field(
            name="Last Week: {}".format(
                p.rp_last_week_amount),
            value="Server: #{} - {}: #{} - {}: #{}".format(
                p.rp_last_week_server,
                p.player_realm,
                p.rp_last_week_realm,
                p.player_class,
                p.rp_last_week_class),
            inline=False)

        embed.add_field(
            name="This Week: {}".format(
                p.rp_this_week_amount),
            value="Server: #{} - {}: #{} - {}: #{}".format(
                p.rp_this_week_server,
                p.player_realm,
                p.rp_this_week_realm,
                p.player_class,
                p.rp_this_week_class),
            inline=False)

        embed.add_field(
            name="Last 48 hours: {}".format(
                p.rp_last_48h_amount),
            value="Server: #{} - {}: #{} - {}: #{}".format(
                p.rp_last_48h_server,
                p.player_realm,
                p.rp_last_48h_realm,
                p.player_class,
                p.rp_last_48h_class),
            inline=False)

        embed.set_footer(text="Updated: {}".format(p.last_updated))
        await ctx.send(embed=embed)
    except Exception:
        embed = discord.Embed(
            title="Unable to find player {}".format(player),
            description="This player does not exist or was misspelled",
            color=16312092
        )
        await ctx.send(embed=embed)
コード例 #7
0
ファイル: bot.py プロジェクト: mattiasr/phoenix-herald
async def me(ctx, *args):
    # query db and get matches based on your id
    # we always want that list due to add/delete functions.
    in_db = await db_get_chars(ctx.author.id)

    if not args:
        await db_insert_command(ctx.author.id, ctx.guild, "!me", "")
        await show_me(ctx, in_db, sort_order=None)
    else:
        if args[0].lower() == "sort":
            if len(args) > 1:
                sort_order = list(args)
                sort_order.pop(0)
                await db_insert_command(ctx.author.id, ctx.guild, "!me",
                                        "sort")
                await show_me(ctx, in_db, sort_order=sort_order[0])
            else:
                await db_insert_command(ctx.author.id, ctx.guild, "!me", "")
                await ctx.send("sort argument: name, level, rp, realm")
            return
        if args[0].lower() == "add" and len(args) > 1:
            # Check if player exist by query
            # IF exist, check if not alread in db
            # If in db, just skip, else add
            characters = list(args)
            characters.pop(0)
            saved = []
            alread_added = []

            try:
                for char in characters:
                    char = char.capitalize()
                    if char not in in_db:
                        PhoenixParser(char)
                        saved.append(char)
                        await db_insert_char(ctx.author.id, char)
                    else:
                        alread_added.append(char)
            except Exception:
                pass

            if len(saved) > 0:
                await ctx.send("Saved: {}".format(', '.join(saved)))
                if len(alread_added) > 0:
                    await ctx.send("Already saved: {}".format(
                        ', '.join(alread_added)))
            else:
                if len(alread_added) > 0:
                    await ctx.send("Already saved: {}".format(
                        ', '.join(alread_added)))
                else:
                    await ctx.send("No valid players found")
            await db_insert_command(ctx.author.id, ctx.guild, "!me", "add")
        elif args[0].lower() == "del" and len(args) > 1:
            # check if you have the player in your db list
            # If in db, delete record
            characters = list(args)
            characters.pop(0)
            deleted = []
            for char in characters:
                char = char.capitalize()
                if char in in_db:
                    await db_delete_char(ctx.author.id, char)
                    deleted.append(char)
            if len(deleted) > 0:
                await ctx.send("Removing: {}".format(', '.join(deleted)))
            else:
                await ctx.send("Unable to delete anything")
            await db_insert_command(ctx.author.id, ctx.guild, "!me", "del")
    return