Browse Source

implemented user chat; #13

* added send_message() on SteamUser
* added `chat_message` event for incoming friend messages
pull/41/head
Rossen Georgiev 9 years ago
parent
commit
94ec82c6c3
  1. 15
      steam/client/builtins/user.py
  2. 14
      steam/client/user.py

15
steam/client/builtins/user.py

@ -6,6 +6,15 @@ from steam.core.msg import MsgProto
from steam.util import proto_fill_from_dict from steam.util import proto_fill_from_dict
class User(object): 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 persona_state = EPersonaState.Online #: current persona state
user = None #: :class:`.SteamUser` instance once logged on 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_DISCONNECTED, self.__handle_disconnect)
self.on(self.EVENT_LOGGED_ON, self.__handle_set_persona) self.on(self.EVENT_LOGGED_ON, self.__handle_set_persona)
self.on(EMsg.ClientPersonaState, self.__handle_persona_state) 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): def __handle_disconnect(self):
self.user = None self.user = None

14
steam/client/user.py

@ -3,6 +3,8 @@ from binascii import hexlify
from gevent.event import Event from gevent.event import Event
from steam.steamid import SteamID from steam.steamid import SteamID
from steam.enums import EFriendRelationship, EPersonaState from steam.enums import EFriendRelationship, EPersonaState
from steam.enums.emsg import EMsg
from steam.core.msg import MsgProto
class SteamUser(object): class SteamUser(object):
"""Holds various functionality and data related to a steam user """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" url = "http://cdn.akamai.steamstatic.com/steamcommunity/public/images/avatars/%s/%s%s.jpg"
return url % (ahash[:2], ahash, sizes[size]) 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'),
})

Loading…
Cancel
Save