import socket, sys, string
if len(sys.argv) !=4 :
print "Usage: ./supabot.py <host> <port> <channel>"
sys.exit(1)
irc = sys.argv[1]
port = int(sys.argv[2])
chan = sys.argv[3]
sck = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sck.connect((irc, port))
sck.send('NICK supaBOT\r\n')
sck.send('USER supaBOT supaBOT supaBOT :supaBOT Script\r\n')
sck.send('JOIN ' + " " + chan + '\r\n')
data = ''
while True:
data = sck.recv(1024)
if data.find('PING') != -1:
sck.send('PONG ' + data.split() [1] + '\r\n')
print data
elif data.find('!info') != -1:
sck.send('PRIVMSG ' + chan + ' :' + ' supaBOT v1 by sourD ' + '\r\n')
print data
elif data.find('!commands') != -1:
nick = data.split('!')[ 0 ].replace(':',' ')
if nick == "s0urd":
sck.send('PRIVMSG ' + chan + ' :' + ' no commands have been set ' + '\r\n')
else:
sck.send('PRIVMSG ' + chan + ' :' + ' youre not my master ' + '\r\n')
print data
elif data.find('PRIVMSG') != -1:
message = ':'.join(data.split (':')[2:])
if message.lower().find('darkunderground') == -1:
nick = data.split('!')[ 0 ].replace(':',' ')
destination = ''.join (data.split(':')[:2]).split (' ')[-2]
function = message.split( )[0]
print nick + ' : ' + function
arg = data.split( )
print sck.recv(1024)
我在 IRC 中的昵称是 s0urd,但是当我输入 !commands 时,我得到“你不是我的主人”,但我的昵称是 s0urd。也许我做错了整个尼克的事情,我不知道,但任何帮助将不胜感激,谢谢。
第 26 行