3 changed files with 33 additions and 29 deletions
@ -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) |
|||
|
Loading…
Reference in new issue