diff --git a/steam/client/builtins/user.py b/steam/client/builtins/user.py index f7165a2..c1b7f2a 100644 --- a/steam/client/builtins/user.py +++ b/steam/client/builtins/user.py @@ -6,6 +6,15 @@ from steam.core.msg import MsgProto from steam.util import proto_fill_from_dict class User(object): + EVENT_CHAT_MESSAGE = 'chat_message' + """On new private chat message + + :param user: steam user + :type user: :class:`.SteamUser` + :param message: message text + :type message: str + """ + persona_state = EPersonaState.Online #: current persona state user = None #: :class:`.SteamUser` instance once logged on @@ -17,6 +26,12 @@ class User(object): self.on(self.EVENT_DISCONNECTED, self.__handle_disconnect) self.on(self.EVENT_LOGGED_ON, self.__handle_set_persona) self.on(EMsg.ClientPersonaState, self.__handle_persona_state) + self.on(EMsg.ClientFriendMsgIncoming, self.__handle_message_incoming) + + def __handle_message_incoming(self, msg): + if msg.body.chat_entry_type == 1: + user = self.get_user(msg.body.steamid_from) + self.emit("chat_message", user, msg.body.message) def __handle_disconnect(self): self.user = None diff --git a/steam/client/user.py b/steam/client/user.py index 04d3bf3..485543d 100644 --- a/steam/client/user.py +++ b/steam/client/user.py @@ -3,6 +3,8 @@ from binascii import hexlify from gevent.event import Event from steam.steamid import SteamID from steam.enums import EFriendRelationship, EPersonaState +from steam.enums.emsg import EMsg +from steam.core.msg import MsgProto class SteamUser(object): """Holds various functionality and data related to a steam user @@ -84,3 +86,15 @@ class SteamUser(object): url = "http://cdn.akamai.steamstatic.com/steamcommunity/public/images/avatars/%s/%s%s.jpg" return url % (ahash[:2], ahash, sizes[size]) + + def send_message(self, message): + """Send chat message to this steam user + + :param message: message to send + :type message: str + """ + self._steam.send(MsgProto(EMsg.ClientFriendMsg), { + 'steamid': self.steam_id, + 'chat_entry_type': 1, + 'message': message.encode('utf8'), + })