Browse Source

SC: refactored change status

pull/41/head
Rossen Georgiev 9 years ago
parent
commit
03bf4e3cf7
  1. 1
      steam/client/__init__.py
  2. 39
      steam/client/builtins/user.py
  3. 22
      steam/enums/common.py

1
steam/client/__init__.py

@ -151,7 +151,6 @@ class SteamClient(CMClient, BuiltinBase):
if result == EResult.OK:
self._reconnect_backoff_c = 0
self.logged_on = True
self.set_persona(EPersonaState.Online)
self.emit(self.EVENT_LOGGED_ON)
return

39
steam/client/builtins/user.py

@ -1,32 +1,37 @@
from steam.enums import EPersonaState
from steam.enums.emsg import EMsg
from steam.core.msg import MsgProto
from steam.util import proto_fill_from_dict
class User(object):
persona_state = EPersonaState.Online #: current persona state
def __init__(self, *args, **kwargs):
super(User, self).__init__(*args, **kwargs)
def set_persona(self, state=None, name=None):
"""
Set persona state and/or name
self.on(self.EVENT_LOGGED_ON, self.__handle_set_persona)
:param state: persona state flag
:type state: :class:`steam.enums.common.EPersonaState`
:param name: profile name
:type name: :class:`str`
"""
if state is None and name is None:
return
def __handle_set_persona(self):
self.set_persona(persona_state=self.persona_state)
message = MsgProto(EMsg.ClientChangeStatus)
def change_status(self, **kwargs):
"""
Set name, persona state, flags
if state:
if not isinstance(state, EPersonaState):
raise ValueError("Expected state to be instance of EPersonaState")
.. note::
Changing persona state will also change :attr:`persona_state`
message.body.persona_state = state
:param persona_state: persona state (Online/Offlane/Away/etc)
:type persona_state: :class:`.EPersonaState`
:param player_name: profile name
:type player_name: :class:`str`
:param persona_state_flags: persona state flags
:type persona_state_flags: :class:`.EPersonaStateFlag`
"""
if not kwargs: return
if name:
message.body.player_name = name
self.persona_state = kwargs.get('persona_state', self.persona_state)
message = MsgProto(EMsg.ClientChangeStatus)
proto_fill_from_dict(message.body, kwargs)
self.send(message)

22
steam/enums/common.py

@ -255,17 +255,6 @@ class EOSType(SteamIntEnum):
Max = 26
class EPersonaState(SteamIntEnum):
Offline = 0
Online = 1
Busy = 2
Away = 3
Snooze = 4
LookingToTrade = 5
LookingToPlay = 6
Max = 7
class EFriendRelationship(SteamIntEnum):
No = 0
Blocked = 1
@ -324,6 +313,17 @@ class EFriendFlags(SteamIntEnum):
FlagAll = 65535
class EPersonaState(SteamIntEnum):
Offline = 0
Online = 1
Busy = 2
Away = 3
Snooze = 4
LookingToTrade = 5
LookingToPlay = 6
Max = 7
class EPersonaStateFlag(SteamIntEnum):
HasRichPresence = 1
InJoinableGame = 2

Loading…
Cancel
Save