Skip to content

Commit

Permalink
Change message handling
Browse files Browse the repository at this point in the history
  • Loading branch information
bkmeneguello committed Feb 21, 2014
1 parent e7966f2 commit f783e98
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions sevabot/bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from inspect import getmembers, isclass

import Skype4Py
from Skype4Py.utils import chop

from sevabot.bot import handlers
from sevabot.utils import get_chat_id
Expand Down Expand Up @@ -40,7 +41,7 @@ def start(self):
self.skype.Attach()

logger.debug("Skype API connection established")
self.skype.RegisterEventHandler('MessageStatus', self.handleMessages)
self.skype.RegisterEventHandler('Notify', self.handleMessages)

self.cacheChats()

Expand Down Expand Up @@ -93,15 +94,27 @@ def getOpenChats(self):
for chat_id, chat in self.chats.items():
yield chat_id, chat

def handleMessages(self, msg, status):
def handleMessages(self, notification):
"""
Handle incoming messages.
"""

logger.debug("Incoming %s - %s - %s: %s" % (status, msg.Chat.FriendlyName,
msg.FromHandle, msg.Body))

self.handler.handle(msg, status)
logger.debug(notification)
a, b = chop(notification)
if a == 'CHAT':
object_type, object_id, prop_name, value = [a] + chop(b, 2)
skype = self.getSkype()
if prop_name == 'ACTIVITY_TIMESTAMP':
for message in skype.MissedMessages:
logger.debug('SEEN: %s', message.Body)
message.MarkAsSeen()
self.handler.handle(message, 'RECEIVED')

#logger.debug("Incoming %s - %s - %s: %s" % (status, msg.Chat.FriendlyName,
# msg.FromHandle, msg.Body))

#msg.MarkAsSeen()
#self.handler.handle(msg, status)

def sendMessage(self, chat, msg):
"""
Expand Down

0 comments on commit f783e98

Please sign in to comment.