diff --git a/steam/client/__init__.py b/steam/client/__init__.py index 7a34816..d29aa8c 100644 --- a/steam/client/__init__.py +++ b/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 diff --git a/steam/client/builtins/user.py b/steam/client/builtins/user.py index a588498..ced9c3d 100644 --- a/steam/client/builtins/user.py +++ b/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) diff --git a/steam/enums/common.py b/steam/enums/common.py index b512c75..434f059 100644 --- a/steam/enums/common.py +++ b/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