I'm trying to make a basic Skype bot using Skype4Py
and have encountered a rather serious error. I am working on a 64 bit windows 7 with the 32bit Python 2.7.8. installed, along with the latest version of Skype4Py.
My main demand is that the bot has an overview of 5
different Skype chats: four individual chats with four users and one common chat in which all four users participate. To that end, I have written two different functions handling individual responses and the group chat:
class SkypeBot(object):
def __init__(self):
self.skype = Skype4Py.Skype(Events=self)
self.skype.Attach()
self.active_chat = find_conference_chat()
def MessageStatus(self, msg, status):
if status == Skype4Py.cmsReceived:
if msg.Chat.Name == self.active_chat.Name:
msg.Chat.SendMessage(respond_to_group(msg))
else:
msg.Chat.SendMessage(respond_to_individual(msg))
bot = SkypeBot()
The above code (there's much more to it, but the core of it is written down) is supposed to answer each message that any user sends either privately or in the group chat.
However, there's a problem. Usually, this code works just fine. The bot responds to each individual user as well as the group chat. Then, every once in a while (once every 10 chats), the bot stops responding to individual messages. The function MessageStatus
simply does not fire, which made me think that there may be some other event I need to catch. So I added one general event catcher to the bot:
def Notify(self, notification):
print "NOTIFICATION:"
print notification
print "=========================="
The only purpose of this code was to see if I am missing any event. So I waited for a bit, and when the bot did not respond, I checked the printout of the function.
- Usually, the bot recieves several notifications when a message arrives: there's the chatmessage recieved notification, the chat activity timestamp notification and some others. The chatmessage recieved notification is the one that eventually triggers the
MessageStatus
event. - In the case when the bot did not respond, only one notification came through. It was the notification
CHAT **** ACTIVITY_TIMESTAMP ******
. There was no notification that a chatmessage was recieved, so no message to respond do.
When I manually clicked on my Skype client and focused my window on the message recieved, the MessageStatus
evend finally fired and the bot responded, but that was way too late.
My question has several parts:
- Is my general code correct? Should, if
Skype4Py
worked flawlessly, my code work OK? - Did anyone else encounter this error where a certain event did not fire?
- If you encountered a similar error, have you solved it? If not, did you at least discover how to consistently reproduce this problem? I can't even debug it because it appears suddenly and out of nowhere...