我有一些麻煩,我的Python IRC聊天機器人。Python IRC聊天機器人
使用Koryls建議
import socket
authlist = "achubra alice_mayami andyzaft ariayesassistant badass001 celebrations celoricqt damonzgaming deadlyabyss deathgazeqtt elvinemod flamespark0 ig_feeds jeboogie kuocolaya madlibx mezukage pwrpuff sikkfromtm socaldesigner whuda wtducksauce xinyi331"
server = "ariayesassistant.jtvirc.com"
name = "ariayesassistant"
port = 6667
channel = "#ariayethehuntress"
password = "xx"
irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
irc.connect((server, port))
irc.send("PASS " + password + "\n")
irc.send("NICK " + name + "\n")
irc.send("USER ariayesassistant ariayesassistant ariayesassistant :AriayesBot\n")
irc.send("JOIN " + channel + "\n")
while True:
def message(msg):
irc.send("PRIVMSG " + channel + " :" + msg + "\n")
data = irc.recv(1204)
data = data.strip('\r\n')
senderusr = data.split(" ")
senderusr = senderusr[0]
senderusr = senderusr.split("!")
senderusr = senderusr[0]
senderusr = senderusr.strip(":")
print data
if data.find == "PONG" :
irc.send("PING")
if data.find("!facebook") and authlist.find(senderusr):
message("Add Angie on Facebook: https://facebook.com/AngieJHagedorn")
#if data.find(":!twitter") and authlist.find(senderusr) != -1:
# message("Follow Angie on Twitter: https://twitter.com/AriayeHuntress")
#if data.find(":!fanpage") and authlist.find(senderusr) != -1:
# message("Like Angie's Fanpage on Facebook: http://facebook.com/AriayeTheHuntress")
#if data.find(":!bg") and authlist.find(senderusr) != -1:
# message("Wanna play BGs with Angie on WoW? Add her battletag: Ariaye#1211")
#if data.find(":!youtube") and authlist.find(senderusr) != -1:
# message("Subscribe to Angie on Youtube! http://youtube.com/ariayethehuntress")
的!Facebook的命令,如果我輸入通道任何事情都會執行之後。 (我的暱稱= badass001)
我將如何正確地執行if命令。 (非常新的蟒蛇)
究竟是什麼問題? – Wug
行if data [0] ==「PONG」!= -1:不需要!= -1。你實際上正在評估False!= -1,它總是爲True。 – korylprince
與第二條if語句相同。它永遠是真的,這可能是你的問題來自何處。無需與-1進行比較。實際上在Python中,-1與False不同。 – korylprince