我一直在编写一个 IRC 聊天机器人,它检查 Google Voice 是否有 SMS 消息,然后通过端口 6667 上的套接字将它们中继到聊天室。聊天消息处理在主子中运行,无限循环,而 GV 检查在一个单独的过程。实际的检查和获取工作正常,但它是套接字不起作用;没有消息发布到频道。奇怪的是,这在 OS X 下完美运行,所以我不认为问题出在语音处理逻辑上:
def checkVoice()
while 1:
print "Update voice!"
#voice processing... edited for brevity
sendPrivateMessage(CHANNEL,message) #This doesn't work
#more code
time.sleep(10)
#main block
if __name__ == '__main__':
sendPrivateMessage(CHANNEL,"Voice checking started") #This works
p = Process(target=checkVoice)
p.start()
我认为问题在于 Windows 使用 Python 的方式,因为它适用于其他平台。
聊天机器人的完整代码可以在这里看到: bot.py
如所问,这是sendPrivateMessage
方法:
def sendPrivateMessage(channel, message):#private message send function
global mute
if mute == 0:
IRC.send("PRIVMSG " + channel + " :" + message + "\r\n")