async def test_get_friends_success(plugin, read, write):
    request = {"jsonrpc": "2.0", "id": "3", "method": "import_friends"}

    read.side_effect = [
        async_return_value(create_message(request)),
        async_return_value(b"", 10)
    ]
    plugin.get_friends.return_value = async_return_value(
        [UserInfo("3", "Jan"), UserInfo("5", "Ola")])
    await plugin.run()
    plugin.get_friends.assert_called_with()

    assert get_messages(write) == [{
        "jsonrpc": "2.0",
        "id": "3",
        "result": {
            "friend_info_list": [{
                "user_id": "3",
                "user_name": "Jan"
            }, {
                "user_id": "5",
                "user_name": "Ola"
            }]
        }
    }]
Пример #2
0
async def test_get_friends_success(plugin, read, write):
    request = {
        "jsonrpc": "2.0",
        "id": "3",
        "method": "import_friends"
    }

    read.side_effect = [async_return_value(create_message(request)), async_return_value(b"", 10)]
    plugin.get_friends.return_value = async_return_value([
        UserInfo("3", "Jan", "https://avatar.url/u3", None),
        UserInfo("5", "Ola", None, "https://profile.url/u5"),
        UserInfo("6", "Ola2", None),
        UserInfo("7", "Ola3"),
    ])
    await plugin.run()
    plugin.get_friends.assert_called_with()

    assert get_messages(write) == [
        {
            "jsonrpc": "2.0",
            "id": "3",
            "result": {
                "friend_info_list": [
                    {"user_id": "3", "user_name": "Jan", "avatar_url": "https://avatar.url/u3"},
                    {"user_id": "5", "user_name": "Ola", "profile_url": "https://profile.url/u5"},
                    {"user_id": "6", "user_name": "Ola2"},
                    {"user_id": "7", "user_name": "Ola3"},
                ]
            }
        }
    ]
Пример #3
0
async def test_multiple_friends(authenticated_plugin, backend_client,
                                steam_id):
    backend_client.get_friends.return_value = [
        UserInfo("76561198040630463", "crak", "avatar", "profile"),
        UserInfo("76561198053830887", "Danpire", "avatar2", "profile2")
    ]

    result = await authenticated_plugin.get_friends()
    assert result == [
        UserInfo("76561198040630463", "crak", "avatar", "profile"),
        UserInfo("76561198053830887", "Danpire", "avatar2", "profile2")
    ]
    backend_client.get_friends.assert_called_once_with(steam_id)
Пример #4
0
        def parse_response(text):
            def parse_id(profile):
                return profile.attrs["data-steamid"]

            def parse_name(profile):
                return HTML(html=profile.html).find(
                    ".friend_block_content", first=True).text.split("\n")[0]

            def parse_avatar(profile):
                avatar_html = HTML(html=profile.html).find(".player_avatar",
                                                           first=True).html
                return HTML(html=avatar_html).find("img")[0].attrs.get("src")

            def parse_url(profile):
                return HTML(html=profile.html).find(
                    ".selectable_overlay", first=True).attrs.get('href')

            try:
                search_results = HTML(html=text).find("#search_results",
                                                      first=True).html
                return [
                    UserInfo(user_id=parse_id(profile),
                             user_name=parse_name(profile),
                             avatar_url=parse_avatar(profile),
                             profile_url=parse_url(profile))
                    for profile in HTML(
                        html=search_results).find(".friend_block_v2")
                ]
            except (AttributeError, ValueError, TypeError):
                logger.exception("Can not parse backend response")
                raise UnknownBackendResponse()
Пример #5
0
async def test_profile_parsing(http_client_mock, http_response_mock, steam_id):
    http_response_mock.text.return_value = '''
    <div class="profile_friends search_results" id="search_results">
        <div class="selectable friend_block_v2 persona offline " data-steamid="76561198056089614">
            <div class="indicator select_friend">
				<input class="select_friend_checkbox" type="checkbox">
			</div>

			<a class="selectable_overlay" data-container="#fr_112034288" href="https://steamcommunity.com/profiles/76561198056089614"></a>

			<div class="player_avatar friend_block_link_overlay online">
				<img src="https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/05/1_medium.jpg">
			</div>
            <div class="friend_block_content">На камазе!<br>
                <span class="friend_small_text"></span>
                <span class="friend_last_online_text">Last Online 189 days ago</span>
            </div>
        </div>
    </div>'''
    http_client_mock.get.return_value = http_response_mock

    assert [
        UserInfo(
            "76561198056089614", "На камазе!",
            "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/05/1_medium.jpg",
            "https://steamcommunity.com/profiles/76561198056089614")
    ] == await SteamHttpClient(http_client_mock).get_friends(steam_id)
Пример #6
0
def test_get_users_success(plugin, read, write):
    request = {
        "jsonrpc": "2.0",
        "id": "8",
        "method": "import_user_infos",
        "params": {
            "user_id_list": ["13"]
        }
    }

    read.side_effect = [json.dumps(request).encode() + b"\n", b""]
    plugin.get_users.coro.return_value = [
        UserInfo("5", False, "Ula", "http://avatar.png",
                 Presence(PresenceState.Offline))
    ]
    asyncio.run(plugin.run())
    plugin.get_users.assert_called_with(user_id_list=["13"])
    response = json.loads(write.call_args[0][0])

    assert response == {
        "jsonrpc": "2.0",
        "id": "8",
        "result": {
            "user_info_list": [{
                "user_id": "5",
                "is_friend": False,
                "user_name": "Ula",
                "avatar_url": "http://avatar.png",
                "presence": {
                    "presence_state": "offline"
                }
            }]
        }
    }
Пример #7
0
def galaxy_user_info_from_user_info(user_id, user_info):
    avatar_url = user_info.avatar_hash.hex()
    if avatar_url == NO_AVATAR_SET:
        avatar_url = DEFAULT_AVATAR
    else:
        avatar_url = AVATAR_URL_PREFIX + avatar_url[
            0:2] + '/' + avatar_url + AVATAR_URL_SUFIX
    profile_link = STEAMCOMMUNITY_PROFILE_LINK + user_id
    return UserInfo(user_id, user_info.name, avatar_url, profile_link)
Пример #8
0
 async def get_users(self):
     return [
         UserInfo(
             "5",
             False,
             "Ula",
             "http://avatar.png",
             Presence(PresenceState.Offline),
         )
     ]
Пример #9
0
        def friend_info_parser(profile):

            avatar_url = None
            for avatar in profile["avatarUrls"]:
                avatar_url = avatar["avatarUrl"]

            return UserInfo(
                user_id=str(profile["accountId"]),
                user_name=str(profile["onlineId"]),
                avatar_url=avatar_url,
                profile_url=f"https://my.playstation.com/profile/{str(profile['onlineId'])}"
            )
Пример #10
0
async def test_multiple_friends_with_nicknames(authenticated_plugin,
                                               steam_client):
    ids = ["76561198040630463", "76561198053830887"]
    steam_client.get_friends.return_value = ids
    steam_client.get_friends_info.return_value = {
        '76561198040630463':
        ProtoUserInfo(
            name='Test1',
            avatar_hash=
            b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00',
            state=EPersonaState.Invisible,
            game_id=0,
            game_name='',
            rich_presence={}),
        '76561198053830887':
        ProtoUserInfo(
            name='Test2',
            avatar_hash=
            b'\x22\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x11',
            state=None,
            game_id=None,
            game_name=None,
            rich_presence=None)
    }
    steam_client.get_friends_nicknames.return_value = {
        '76561198053830887': 'nickname'
    }
    result = await authenticated_plugin.get_friends()
    assert result == [
        UserInfo(
            "76561198040630463", "Test1",
            "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/fe/fef49e7fa7e1997310d705b2a6158ff8dc1cdfeb_full.jpg",
            "https://steamcommunity.com/profiles/76561198040630463"),
        UserInfo(
            "76561198053830887", "Test2 (nickname)",
            "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/22/2200000000000000000000000000000000000011_full.jpg",
            "https://steamcommunity.com/profiles/76561198053830887")
    ]

    steam_client.get_friends_info.assert_called_once_with(ids)
    async def get_friends(self) -> List[UserInfo]:
        xmpp_client = await self.__xmpp_get_client('WOT')

        friends = list()
        for user_id, user_name in (await xmpp_client.get_friends()).items():
            avatar_url = 'https://ru.wargaming.net/clans/media/clans/emblems/cl_307/163307/emblem_195x195.png'
            profile_url = get_profile_url(xmpp_client.get_game_id(),
                                          xmpp_client.get_realm(), user_id)
            friends.append(
                UserInfo(user_id, user_name, avatar_url, profile_url))

        logging.info('plugin/get_friends: %s' % friends)
        return friends
    async def get_users(self, user_id_list: List[str]) -> List[UserInfo]:
        result = list()

        xmpp_client = self.__xmpp_get_client()

        userinfo = WoTPAPI.get_account_info(user_id_list)
        for realm_id, users_dict in userinfo.items():
            for user_id, user_data in users_dict.items():
                is_friend = await xmpp_client.is_friend(user_id)
                username = '******' % (realm_id.upper(), user_data['nickname'])
                userinfo = UserInfo(str(user_id), is_friend, username, None,
                                    Presence(PresenceState.Unknown))
                result.append(userinfo)

        return result
async def test_add_friend(plugin, write):
    friend = UserInfo("7", "Kuba")

    plugin.add_friend(friend)
    await skip_loop()

    assert get_messages(write) == [{
        "jsonrpc": "2.0",
        "method": "friend_added",
        "params": {
            "friend_info": {
                "user_id": "7",
                "user_name": "Kuba"
            }
        }
    }]
Пример #14
0
async def test_add_friend(plugin, write):
    friend = UserInfo("7", "Kuba", avatar_url="https://avatar.url/kuba.jpg", profile_url="https://profile.url/kuba")

    plugin.add_friend(friend)
    await skip_loop()

    assert get_messages(write) == [
        {
            "jsonrpc": "2.0",
            "method": "friend_added",
            "params": {
                "friend_info": {
                    "user_id": "7",
                    "user_name": "Kuba",
                    "avatar_url": "https://avatar.url/kuba.jpg",
                    "profile_url": "https://profile.url/kuba"
                }
            }
        }
    ]
Пример #15
0
async def test_update_friend_info(plugin, write):
    plugin.update_friend_info(
        UserInfo("7", "Jakub", avatar_url="https://new-avatar.url/kuba2.jpg", profile_url="https://profile.url/kuba")
    )
    await skip_loop()

    assert get_messages(write) == [
        {
            "jsonrpc": "2.0",
            "method": "friend_updated",
            "params": {
                "friend_info": {
                    "user_id": "7",
                    "user_name": "Jakub",
                    "avatar_url": "https://new-avatar.url/kuba2.jpg",
                    "profile_url": "https://profile.url/kuba"
                }
            }
        }
    ]
Пример #16
0
 async def _parse_friends(self, friends_list: dict) -> List[UserInfo]:
     return_list = []
     for i in range(0, len(friends_list)):
         avatar_uri = f"https://a.rsg.sc/n/{friends_list[i]['displayName'].lower()}/l"
         profile_uri = f"https://socialclub.rockstargames.com/member/{friends_list[i]['displayName']}/"
         friend = UserInfo(user_id=str(friends_list[i]['rockstarId']),
                           user_name=friends_list[i]['displayName'],
                           avatar_url=avatar_uri,
                           profile_url=profile_uri)
         return_list.append(friend)
         for cached_friend in self.friends_cache:
             if cached_friend.user_id == friend.user_id:
                 break
         else:  # An else-statement occurs after a for-statement if the latter finishes WITHOUT breaking.
             self.friends_cache.append(friend)
         if LOG_SENSITIVE_DATA:
             log.debug("ROCKSTAR_FRIEND: Found " + friend.user_name + " (Rockstar ID: " +
                       str(friend.user_id) + ")")
         else:
             log.debug(f"ROCKSTAR_FRIEND: Found {friend.user_name[:1]}*** (Rockstar ID: ***)")
     return return_list
Пример #17
0
            "http://playstation.net/avatar/3RD/E9A0BB8BC40BBF9B_M.png"
        }],
        "primaryOnlineStatus":
        "offline",
        "presences": [{
            "onlineStatus": "offline",
            "lastOnlineDate": "2019-02-25T01:52:44Z"
        }],
        "friendRelation":
        "friend"
    }]
}

FRIEND_INFO_LIST = [
    UserInfo(user_id="1",
             user_name="veryopenperson",
             avatar_url="http://playstation.net/avatar/DefaultAvatar_m.png",
             profile_url="https://my.playstation.com/profile/veryopenperson"),
    UserInfo(user_id="2",
             user_name="ImTestingSth1",
             avatar_url="http://playstation.net/avatar/DefaultAvatar_m.png",
             profile_url="https://my.playstation.com/profile/ImTestingSth1"),
    UserInfo(user_id="3",
             user_name="venom6683",
             avatar_url="http://playstation.net/avatar/WWS_E/E0007_m.png",
             profile_url="https://my.playstation.com/profile/venom6683"),
    UserInfo(user_id="4",
             user_name="l_Touwa_l",
             avatar_url="http://playstation.net/avatar/DefaultAvatar_m.png",
             profile_url="https://my.playstation.com/profile/l_Touwa_l"),
    UserInfo(user_id="5",
             user_name="Resilb",
Пример #18
0
 async def get_friends(self):
     return [
         UserInfo(str(f['id']), f['username'], f.get('avatar_url'),
                  'https://osu.ppy.sh/users/' + str(f['id']))
         for f in await self._api.get_friends() if not f['is_bot']
     ]