Browse Source

SteamUser: add refresh() method and rework logic

pull/361/head
Rossen Georgiev 4 years ago
parent
commit
b2e1f7755c
  1. 2
      steam/client/builtins/user.py
  2. 22
      steam/client/user.py

2
steam/client/builtins/user.py

@ -114,7 +114,7 @@ class User(object):
self._user_cache[steam_id] = suser self._user_cache[steam_id] = suser
if fetch_persona_state: if fetch_persona_state:
self.request_persona_state([steam_id]) suser.refresh(wait=False)
return suser return suser

22
steam/client/user.py

@ -14,6 +14,7 @@ class SteamUser(object):
This is an internal object that can be obtained by :meth:`SteamClient.get_user` This is an internal object that can be obtained by :meth:`SteamClient.get_user`
""" """
_pstate = None _pstate = None
_pstate_requested = False
steam_id = SteamID() #: steam id steam_id = SteamID() #: steam id
relationship = EFriendRelationship.NONE #: friendship status relationship = EFriendRelationship.NONE #: friendship status
@ -30,17 +31,30 @@ class SteamUser(object):
self.state, self.state,
) )
def refresh(self, wait=True):
if self._pstate_requested and self._pstate_ready.is_set():
self._pstate_requested = False
if not self._pstate_requested:
self._steam.request_persona_state([self.steam_id])
self._pstate_ready.clear()
self._pstate_requested = True
if wait:
self._pstate_ready.wait(timeout=5)
self._pstate_requested = False
def get_ps(self, field_name, wait_pstate=True): def get_ps(self, field_name, wait_pstate=True):
"""Get property from PersonaState """Get property from PersonaState
`See full list of available fields_names <https://github.com/ValvePython/steam/blob/fa8a5127e9bb23185483930da0b6ae85e93055a7/protobufs/steammessages_clientserver_friends.proto#L125-L153>`_ `See full list of available fields_names <https://github.com/ValvePython/steam/blob/fa8a5127e9bb23185483930da0b6ae85e93055a7/protobufs/steammessages_clientserver_friends.proto#L125-L153>`_
""" """
if not wait_pstate or self._pstate_ready.wait(timeout=5): if not self._pstate_ready.is_set() and wait_pstate:
if self._pstate is None and wait_pstate: self.refresh()
self._steam.request_persona_state([self.steam_id])
self._pstate_ready.wait(timeout=5)
if self._pstate is not None:
return getattr(self._pstate, field_name) return getattr(self._pstate, field_name)
else:
return None return None
@property @property

Loading…
Cancel
Save