Esempio n. 1
0
class TestProfileMixin(object):
    def setup(self):
        self.params = {'access_token': 'secret'}

        self.api = WowApi('client-id', 'client-secret')
        self.api._access_tokens = {
            'us': {
                'token': 'secret',
                'expiration': datetime.utcnow() + timedelta(hours=1)
            }
        }

    # Character Achievements API

    def test_get_character_achievements_summary(self, response_mock):
        self.api.get_character_achievements_summary('us', 'dynamic-us',
                                                    'khadgar', 'blizzpower')
        params = copy.deepcopy(self.params)
        params['namespace'] = 'dynamic-us'
        response_mock.assert_called_with(
            'https://us.api.blizzard.com/profile/wow/character/khadgar/blizzpower/achievements',
            params=params)

    # Character Appearance API

    def test_get_character_appearance_summary(self, response_mock):
        self.api.get_character_appearance_summary('us', 'dynamic-us',
                                                  'khadgar', 'blizzpower')
        params = copy.deepcopy(self.params)
        params['namespace'] = 'dynamic-us'
        response_mock.assert_called_with(
            'https://us.api.blizzard.com/profile/wow/character/khadgar/blizzpower/appearance',
            params=params)

    # Character Equipment API

    def test_get_character_equipment_summary(self, response_mock):
        self.api.get_character_equipment_summary('us', 'dynamic-us', 'khadgar',
                                                 'blizzpower')
        params = copy.deepcopy(self.params)
        params['namespace'] = 'dynamic-us'
        response_mock.assert_called_with(
            'https://us.api.blizzard.com/profile/wow/character/khadgar/blizzpower/equipment',
            params=params)

    # Character Media API

    def test_get_character_media_summary(self, response_mock):
        self.api.get_character_media_summary('us', 'dynamic-us', 'khadgar',
                                             'blizzpower')
        params = copy.deepcopy(self.params)
        params['namespace'] = 'dynamic-us'
        response_mock.assert_called_with(
            'https://us.api.blizzard.com/profile/wow/character/khadgar/blizzpower/character-media',
            params=params)

    # Character Profile API

    def test_get_character_profile_summary(self, response_mock):
        self.api.get_character_profile_summary('us', 'dynamic-us', 'khadgar',
                                               'blizzpower')
        params = copy.deepcopy(self.params)
        params['namespace'] = 'dynamic-us'
        response_mock.assert_called_with(
            'https://us.api.blizzard.com/profile/wow/character/khadgar/blizzpower',
            params=params)

    # Character PvP API

    def test_get_character_pvp_bracket_stats(self, response_mock):
        self.api.get_character_pvp_bracket_stats('us', 'dynamic-us', 'khadgar',
                                                 'blizzpower', '3v3')
        params = copy.deepcopy(self.params)
        params['namespace'] = 'dynamic-us'
        response_mock.assert_called_with(
            'https://us.api.blizzard.com/profile/wow/character/khadgar/blizzpower/pvp-bracket/3v3',
            params=params)

    def test_get_character_pvp_summary(self, response_mock):
        self.api.get_character_pvp_summary(
            'us',
            'dynamic-us',
            'khadgar',
            'blizzpower',
        )
        params = copy.deepcopy(self.params)
        params['namespace'] = 'dynamic-us'
        response_mock.assert_called_with(
            'https://us.api.blizzard.com/profile/wow/character/khadgar/blizzpower/pvp-summary',
            params=params)

    # Character Specializations API

    def test_get_character_specializations_summary(self, response_mock):
        self.api.get_character_specializations_summary(
            'us',
            'dynamic-us',
            'khadgar',
            'blizzpower',
        )
        params = copy.deepcopy(self.params)
        params['namespace'] = 'dynamic-us'
        response_mock.assert_called_with(
            'https://us.api.blizzard.com/profile/wow/character/khadgar/blizzpower/specializations',
            params=params)

    # Character Statistics API

    def test_get_character_stats_summary(self, response_mock):
        self.api.get_character_stats_summary(
            'us',
            'dynamic-us',
            'khadgar',
            'blizzpower',
        )
        params = copy.deepcopy(self.params)
        params['namespace'] = 'dynamic-us'
        response_mock.assert_called_with(
            'https://us.api.blizzard.com/profile/wow/character/khadgar/blizzpower/statistics',
            params=params)

    # Character Titles API

    def test_get_character_titles_summary(self, response_mock):
        self.api.get_character_titles_summary(
            'us',
            'dynamic-us',
            'khadgar',
            'blizzpower',
        )
        params = copy.deepcopy(self.params)
        params['namespace'] = 'dynamic-us'
        response_mock.assert_called_with(
            'https://us.api.blizzard.com/profile/wow/character/khadgar/blizzpower/titles',
            params=params)

    # WoW Mythic Keystone Character Profile API

    def test_get_character_mythic_keystone_profile(self, response_mock):
        self.api.get_character_mythic_keystone_profile('us', 'profile-us',
                                                       'blackmoore', 'ayanda')

        params = copy.deepcopy(self.params)
        params['namespace'] = 'profile-us'

        response_mock.assert_called_with(
            '{0}/profile/wow/character/blackmoore/ayanda/mythic-keystone-profile'
            .format('https://us.api.blizzard.com'),
            params=params)

    def test_get_character_mythic_keystone_profile_season(self, response_mock):
        self.api.get_character_mythic_keystone_profile_season(
            'us', 'profile-us', 'blackmoore', 'ayanda', '1')

        params = copy.deepcopy(self.params)
        params['namespace'] = 'profile-us'

        response_mock.assert_called_with(
            '{0}/profile/wow/character/blackmoore/ayanda/mythic-keystone-profile/season/1'
            .format('https://us.api.blizzard.com'),
            params=params)
Esempio n. 2
0
class WorldofWarcraft(Cog):
    """WOW API"""
    def __init__(self, bot):
        bot.log.info(f"loaded {__name__}")

        self.bot = bot
        self.config = self.bot.config["wow"]
        self.api = WowApi(self.config["wow_id"], self.config["wow_secret"])
        self.regions = ["eu", "us"]

    # noinspection PyMethodMayBeStatic
    def _get_link(self, site, profile):
        url = None

        if site == "armory":
            url = "https://worldofwarcraft.com/en-us/character"
        elif site == "raiderio":
            url = "https://raider.io/characters"
        elif site == "warcraftlogs":
            url = "https://www.warcraftlogs.com/character"
        elif site == "wowprogress":
            url = "https://www.wowprogress.com/character"

        return f"{url}/{profile}"

    async def _get_character(self, ctx, realm, region, name):
        namespace = f"profile-{region}"

        self.api.get_character_profile_status(region, namespace, realm, name)
        character = self.api.get_character_profile_summary(
            region, f"profile-{region}", realm, name)
        assets = self.api.get_character_media_summary(region,
                                                      f"profile-{region}",
                                                      realm, name)["assets"]
        profile_picture = [
            asset for asset in assets if asset["key"] == "avatar"
        ][0]["value"]

        return character, profile_picture

    # noinspection PyMethodMayBeStatic
    def _get_raiderio_score(self, region, realm, name):
        base_url = "https://raider.io/api/v1/characters/profile"
        args = f"?region={region}&realm={realm}&name={name}&fields=mythic_plus_scores_by_season:current"

        req = requests.get(f"{base_url}{args}")

        if req.status_code == 200:
            resp = req.json()

            if len(resp["mythic_plus_scores_by_season"]) > 0:
                return resp["mythic_plus_scores_by_season"][0]["scores"]["all"]
            else:
                return None

    # noinspection PyMethodMayBeStatic
    def _get_best_mythic_keys(self, region, realm, name):
        base_url = "https://raider.io/api/v1/characters/profile"
        args = f"?region={region}&realm={realm}&name={name}&fields=mythic_plus_best_runs"

        req = requests.get(f"{base_url}{args}")

        if req.status_code == 200:
            resp = req.json()

            keys = []
            for key in resp["mythic_plus_best_runs"]:
                base_datetime = dt(1970, 1, 1)
                delta = td(milliseconds=key["clear_time_ms"])
                target_date = base_datetime + delta
                keys.append({
                    "dungeon": key["short_name"],
                    "level": key["mythic_level"],
                    "clear_time": target_date.strftime("%M:%S"),
                })

            return keys

    @group(invoke_without_command=True)
    async def wow(self, ctx):
        """Get ALL the Infos about WoW"""
        if ctx.invoked_subcommand is None:
            await ctx.send_help(ctx.command)

    @wow.command(aliases=["search", "char"])
    async def armory(self, ctx, name: str, realm: str, region: str = None):
        """
        search for character

        name and realm are required parameters.
        region is optional, but if you want to search on another realm than your discord server runs on, you need to set it.
        """
        try:
            async with ctx.typing():
                if region is None:
                    region = ctx.guild.region[0][:2]

                realm = realm.lower()
                name = name.lower()
                profile = f"{region}/{realm}/{name}"

                character, profile_picture = await self._get_character(
                    ctx, realm, region, name)

                best_keys = self._get_best_mythic_keys(region, realm, name)
                rio_score = self._get_raiderio_score(region, realm, name)

                armory = self._get_link("armory", profile)
                raiderio = self._get_link("raiderio", profile)
                warcraftlogs = self._get_link("warcraftlogs", profile)
                wowprogress = self._get_link("wowprogress", profile)

                emb = discord.Embed(
                    title=
                    f'{character["name"]} | {realm.capitalize()} | {region.upper()} | {character["active_spec"]["name"]["en_US"]} {character["character_class"]["name"]["en_US"]} | {character["equipped_item_level"]} ilvl',
                    url=armory,
                    color=discord.Color(value=int("0099ff", 16)),
                    description=
                    f'{character["gender"]["name"]["en_US"]} {character["race"]["name"]["en_US"]}',
                )
                emb.set_thumbnail(url=profile_picture)
                emb.add_field(name="Level",
                              value=character["level"],
                              inline=True)
                emb.add_field(name="Faction",
                              value=character["faction"]["name"]["en_US"],
                              inline=True)
                if "guild" in character:
                    emb.add_field(name="Guild",
                                  value=character["guild"]["name"],
                                  inline=True)
                emb.add_field(name="\u200b", value="\u200b", inline=False)

                if len(best_keys) > 0:
                    keys = ""
                    for key in best_keys:
                        keys += f'+{key["level"]} - {key["dungeon"]} - {key["clear_time"]}\n'

                    emb.add_field(name="Best M+ Keys", value=keys, inline=True)
                if rio_score is not None:
                    emb.add_field(name="M+ Score",
                                  value=rio_score,
                                  inline=True)

                emb.add_field(name="\u200b", value="\u200b", inline=False)
                emb.add_field(
                    name="External Sites",
                    value=
                    f"[Raider.io]({raiderio}) | [Armory]({armory}) | [WarcraftLogs]({warcraftlogs}) | [WoWProgress]({wowprogress})",
                    inline=True,
                )

            await self.bot.sendc(ctx, "", emb)
        except WowApiException:
            await self.bot.sendc(ctx, "No Character with this name found.")
Esempio n. 3
0
class TestProfileMixin(object):
    def setup(self):
        self.params = {'access_token': 'secret'}

        self.api = WowApi('client-id', 'client-secret')
        self.api._access_tokens = {
            'us': {
                'token': 'secret',
                'expiration': datetime.utcnow() + timedelta(hours=1)
            }
        }

    # Account Profile API

    def test_get_account_profile_summary(self, response_mock):
        self.api.get_account_profile_summary('us', 'dynamic-us',
                                             'profile-token')

        params = {'namespace': 'dynamic-us', 'access_token': 'profile-token'}

        response_mock.assert_called_with(
            'https://us.api.blizzard.com/profile/user/wow', params=params)

    def test_get_protected_character_profile_summary(self, response_mock):
        self.api.get_protected_character_profile_summary(
            'us', 'dynamic-us', 'profile-token', 1, 9000)

        params = {'namespace': 'dynamic-us', 'access_token': 'profile-token'}

        response_mock.assert_called_with(
            'https://us.api.blizzard.com/profile/user/wow/protected-character/1-9000',
            params=params)

    def test_get_account_collection_index(self, response_mock):
        self.api.get_account_collection_index('us', 'dynamic-us',
                                              'profile-token')

        params = {'namespace': 'dynamic-us', 'access_token': 'profile-token'}

        response_mock.assert_called_with(
            'https://us.api.blizzard.com/profile/user/wow/collections',
            params=params)

    def test_get_mount_collection_summary(self, response_mock):
        self.api.get_mount_collection_summary('us', 'dynamic-us',
                                              'profile-token')

        params = {'namespace': 'dynamic-us', 'access_token': 'profile-token'}

        response_mock.assert_called_with(
            'https://us.api.blizzard.com/profile/user/wow/collections/mounts',
            params=params)

    def test_get_pet_collection_summary(self, response_mock):
        self.api.get_pet_collection_summary('us', 'dynamic-us',
                                            'profile-token')

        params = {'namespace': 'dynamic-us', 'access_token': 'profile-token'}

        response_mock.assert_called_with(
            'https://us.api.blizzard.com/profile/user/wow/collections/pets',
            params=params)

    # Character Achievements API

    def test_get_character_achievements_summary(self, response_mock):
        self.api.get_character_achievements_summary('us', 'dynamic-us',
                                                    'khadgar', 'asmon')
        params = copy.deepcopy(self.params)
        params['namespace'] = 'dynamic-us'
        response_mock.assert_called_with(
            'https://us.api.blizzard.com/profile/wow/character/khadgar/asmon/achievements',
            params=params)

    def test_get_character_achievements_statistics(self, response_mock):
        self.api.get_character_achievements_statistics('us', 'dynamic-us',
                                                       'moon', 'asmon')
        params = copy.deepcopy(self.params)
        params['namespace'] = 'dynamic-us'
        response_mock.assert_called_with(
            'https://us.api.blizzard.com/profile/wow/character/moon/asmon/achievements/statistics',
            params=params)

    # Character Appearance API

    def test_get_character_appearance_summary(self, response_mock):
        self.api.get_character_appearance_summary('us', 'dynamic-us',
                                                  'khadgar', 'asmon')
        params = copy.deepcopy(self.params)
        params['namespace'] = 'dynamic-us'
        response_mock.assert_called_with(
            'https://us.api.blizzard.com/profile/wow/character/khadgar/asmon/appearance',
            params=params)

    # Character Collections API

    def test_get_character_collection_index(self, response_mock):
        self.api.get_character_collection_index('us', 'dynamic-us', 'khadgar',
                                                'asmon')

        params = copy.deepcopy(self.params)
        params['namespace'] = 'dynamic-us'
        response_mock.assert_called_with(
            'https://us.api.blizzard.com/profile/wow/character/khadgar/asmon/collections',
            params=params)

    def test_get_character_mount_collection_index(self, response_mock):
        self.api.get_character_mount_collection_index('us', 'dynamic-us',
                                                      'khadgar', 'asmon')

        params = copy.deepcopy(self.params)
        params['namespace'] = 'dynamic-us'
        response_mock.assert_called_with(
            'https://us.api.blizzard.com/profile/wow/character/khadgar/asmon/collections/mounts',
            params=params)

    def test_get_character_pet_collection_index(self, response_mock):
        self.api.get_character_pet_collection_index('us', 'dynamic-us',
                                                    'khadgar', 'asmon')

        params = copy.deepcopy(self.params)
        params['namespace'] = 'dynamic-us'
        response_mock.assert_called_with(
            'https://us.api.blizzard.com/profile/wow/character/khadgar/asmon/collections/pets',
            params=params)

    # Character Encounters API

    def test_get_character_encounters_summary(self, response_mock):
        self.api.get_character_encounters_summary('us', 'dynamic-us',
                                                  'khadgar', 'asmon')

        params = copy.deepcopy(self.params)
        params['namespace'] = 'dynamic-us'
        response_mock.assert_called_with(
            'https://us.api.blizzard.com/profile/wow/character/khadgar/asmon/encounters',
            params=params)

    def test_get_character_dungeons(self, response_mock):
        self.api.get_character_dungeons('us', 'dynamic-us', 'khadgar', 'asmon')

        params = copy.deepcopy(self.params)
        params['namespace'] = 'dynamic-us'
        response_mock.assert_called_with(
            'https://us.api.blizzard.com/profile/wow/character/khadgar/asmon/encounters/dungeons',
            params=params)

    def test_get_character_raids(self, response_mock):
        self.api.get_character_raids('us', 'dynamic-us', 'khadgar', 'asmon')

        params = copy.deepcopy(self.params)
        params['namespace'] = 'dynamic-us'
        response_mock.assert_called_with(
            'https://us.api.blizzard.com/profile/wow/character/khadgar/asmon/encounters/raids',
            params=params)

    # Character Equipment API

    def test_get_character_equipment_summary(self, response_mock):
        self.api.get_character_equipment_summary('us', 'dynamic-us', 'khadgar',
                                                 'asmon')
        params = copy.deepcopy(self.params)
        params['namespace'] = 'dynamic-us'
        response_mock.assert_called_with(
            'https://us.api.blizzard.com/profile/wow/character/khadgar/asmon/equipment',
            params=params)

    # Character Hunter Pets API

    def test_get_character_hunter_pets_summary(self, response_mock):
        self.api.get_character_hunter_pets_summary('us', 'dynamic-us',
                                                   'khadgar', 'asmon')
        params = copy.deepcopy(self.params)
        params['namespace'] = 'dynamic-us'
        response_mock.assert_called_with(
            'https://us.api.blizzard.com/profile/wow/character/khadgar/asmon/hunter-pets',
            params=params)

    # Character Media API

    def test_get_character_media_summary(self, response_mock):
        self.api.get_character_media_summary('us', 'dynamic-us', 'khadgar',
                                             'asmon')
        params = copy.deepcopy(self.params)
        params['namespace'] = 'dynamic-us'
        response_mock.assert_called_with(
            'https://us.api.blizzard.com/profile/wow/character/khadgar/asmon/character-media',
            params=params)

    # WoW Mythic Keystone Character Profile API

    def test_get_character_mythic_keystone_profile(self, response_mock):
        self.api.get_character_mythic_keystone_profile('us', 'profile-us',
                                                       'blackmoore', 'ayanda')

        params = copy.deepcopy(self.params)
        params['namespace'] = 'profile-us'

        response_mock.assert_called_with(
            '{0}/profile/wow/character/blackmoore/ayanda/mythic-keystone-profile'
            .format('https://us.api.blizzard.com'),
            params=params)

    def test_get_character_mythic_keystone_profile_season(self, response_mock):
        self.api.get_character_mythic_keystone_profile_season(
            'us', 'profile-us', 'blackmoore', 'ayanda', '1')

        params = copy.deepcopy(self.params)
        params['namespace'] = 'profile-us'

        response_mock.assert_called_with(
            '{0}/profile/wow/character/blackmoore/ayanda/mythic-keystone-profile/season/1'
            .format('https://us.api.blizzard.com'),
            params=params)

    # Character Professions API

    def test_get_character_professions_summary(self, response_mock):
        self.api.get_character_professions_summary('us', 'dynamic-us',
                                                   'khadgar', 'asmon')
        params = copy.deepcopy(self.params)
        params['namespace'] = 'dynamic-us'
        response_mock.assert_called_with(
            'https://us.api.blizzard.com/profile/wow/character/khadgar/asmon/professions',
            params=params)

    # Character Profile API

    def test_get_character_profile_summary(self, response_mock):
        self.api.get_character_profile_summary('us', 'dynamic-us', 'khadgar',
                                               'asmon')
        params = copy.deepcopy(self.params)
        params['namespace'] = 'dynamic-us'
        response_mock.assert_called_with(
            'https://us.api.blizzard.com/profile/wow/character/khadgar/asmon',
            params=params)

    def test_get_character_profile_status(self, response_mock):
        self.api.get_character_profile_status('us', 'dynamic-us', 'khadgar',
                                              'asmon')
        params = copy.deepcopy(self.params)
        params['namespace'] = 'dynamic-us'
        response_mock.assert_called_with(
            'https://us.api.blizzard.com/profile/wow/character/khadgar/asmon/status',
            params=params)

    # Character PvP API

    def test_get_character_pvp_bracket_stats(self, response_mock):
        self.api.get_character_pvp_bracket_stats('us', 'dynamic-us', 'khadgar',
                                                 'asmon', '3v3')
        params = copy.deepcopy(self.params)
        params['namespace'] = 'dynamic-us'
        response_mock.assert_called_with(
            'https://us.api.blizzard.com/profile/wow/character/khadgar/asmon/pvp-bracket/3v3',
            params=params)

    def test_get_character_pvp_summary(self, response_mock):
        self.api.get_character_pvp_summary(
            'us',
            'dynamic-us',
            'khadgar',
            'asmon',
        )
        params = copy.deepcopy(self.params)
        params['namespace'] = 'dynamic-us'
        response_mock.assert_called_with(
            'https://us.api.blizzard.com/profile/wow/character/khadgar/asmon/pvp-summary',
            params=params)

    # Character Quests API

    def test_get_character_quests(self, response_mock):
        self.api.get_character_quests(
            'us',
            'dynamic-us',
            'khadgar',
            'asmon',
        )
        params = copy.deepcopy(self.params)
        params['namespace'] = 'dynamic-us'
        response_mock.assert_called_with(
            'https://us.api.blizzard.com/profile/wow/character/khadgar/asmon/quests',
            params=params)

    def test_get_character_completed_quests(self, response_mock):
        self.api.get_character_completed_quests(
            'us',
            'dynamic-us',
            'khadgar',
            'asmon',
        )
        params = copy.deepcopy(self.params)
        params['namespace'] = 'dynamic-us'
        response_mock.assert_called_with(
            'https://us.api.blizzard.com/profile/wow/character/khadgar/asmon/quests/completed',
            params=params)

    # Character Reputations API

    def test_get_character_reputations_summary(self, response_mock):
        self.api.get_character_reputations_summary(
            'us',
            'dynamic-us',
            'khadgar',
            'asmon',
        )
        params = copy.deepcopy(self.params)
        params['namespace'] = 'dynamic-us'
        response_mock.assert_called_with(
            'https://us.api.blizzard.com/profile/wow/character/khadgar/asmon/reputations',
            params=params)

    # Character Specializations API

    def test_get_character_specializations_summary(self, response_mock):
        self.api.get_character_specializations_summary(
            'us',
            'dynamic-us',
            'khadgar',
            'asmon',
        )
        params = copy.deepcopy(self.params)
        params['namespace'] = 'dynamic-us'
        response_mock.assert_called_with(
            'https://us.api.blizzard.com/profile/wow/character/khadgar/asmon/specializations',
            params=params)

    # Character Statistics API

    def test_get_character_stats_summary(self, response_mock):
        self.api.get_character_stats_summary(
            'us',
            'dynamic-us',
            'khadgar',
            'asmon',
        )
        params = copy.deepcopy(self.params)
        params['namespace'] = 'dynamic-us'
        response_mock.assert_called_with(
            'https://us.api.blizzard.com/profile/wow/character/khadgar/asmon/statistics',
            params=params)

    # Character Titles API

    def test_get_character_titles_summary(self, response_mock):
        self.api.get_character_titles_summary(
            'us',
            'dynamic-us',
            'khadgar',
            'asmon',
        )
        params = copy.deepcopy(self.params)
        params['namespace'] = 'dynamic-us'
        response_mock.assert_called_with(
            'https://us.api.blizzard.com/profile/wow/character/khadgar/asmon/titles',
            params=params)

    # Guild API

    def test_get_guild(self, response_mock):
        self.api.get_guild('us', 'dynamic-us', 'khadgar', 'bestguild')
        params = copy.deepcopy(self.params)
        params['namespace'] = 'dynamic-us'
        response_mock.assert_called_with(
            'https://us.api.blizzard.com/data/wow/guild/khadgar/bestguild',
            params=params)

    def test_get_guild_activity(self, response_mock):
        self.api.get_guild_activity('us', 'dynamic-us', 'khadgar', 'bestguild')
        params = copy.deepcopy(self.params)
        params['namespace'] = 'dynamic-us'
        response_mock.assert_called_with(
            'https://us.api.blizzard.com/data/wow/guild/khadgar/bestguild/activity',
            params=params)

    def test_get_guild_achievements(self, response_mock):
        self.api.get_guild_achievements('us', 'dynamic-us', 'khadgar',
                                        'bestguild')
        params = copy.deepcopy(self.params)
        params['namespace'] = 'dynamic-us'
        response_mock.assert_called_with(
            'https://us.api.blizzard.com/data/wow/guild/khadgar/bestguild/achievements',
            params=params)

    def test_get_guild_roster(self, response_mock):
        self.api.get_guild_roster('us', 'dynamic-us', 'khadgar', 'bestguild')
        params = copy.deepcopy(self.params)
        params['namespace'] = 'dynamic-us'
        response_mock.assert_called_with(
            'https://us.api.blizzard.com/data/wow/guild/khadgar/bestguild/roster',
            params=params)