我正在尝试制作一个我可以运行的简单skype机器人,如果在特定聊天中发送了一条消息,它会发送三条消息之一。 但是,我正在尝试找出如何在邮件发送到聊天时进行检查。
到目前为止:
import Skype4Py as skype
skypeClient = skype.Skype()
skypeClient.Attach()
def sendGroupChatMessage(topic="Topic"):
messageSent = False
messagenum = 0
for elem in skypeClient.ActiveChats:
if (messagenum == 0):
elem.SendMessage("I see")
messagenum = 1
messageSent = True
elif (messagenum == 1):
elem.SendMessage("That's amazing")
messagenum = 2
messageSent = True
elif (messagenum == 2):
elem.SendMessage("It's not your fault")
messagenum = 0
messageSent = True
if not messageSent:
for chat in skypeClient.BookmarkedChats:
if chat.Topic == topic:
chat.SendMessage("SomeMessageHere")
messageSent = True
return messageSent
if skypeClient.OnMessageStatus == 'RECEIVED':
sendGroupChatMessage()
答案 0 :(得分:3)
您必须注册事件MessageStatus
http://skype4py.sourceforge.net/doc/html/Skype4Py.skype.SkypeEvents-class.html
在那里你可以找到更多的信息。
示例代码,向发送方重新发送消息(只是回显):
import Skype4Py
skype = Skype4Py.Skype()
skype.Attach()
def onMsg(msg, status):
if status == Skype4Py.cmsReceived:
msg.Chat.SendMessage(msg.Body)
skype.RegisterEventHandler('MessageStatus', onMsg)
while 1: pass