views:

55

answers:

1
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)

my nick in IRC is s0urd but when I type !commands I get "youre not my master" but my nick is s0urd, maybe i did the whole nick thinfg wrong I dont know, any help will be appreciated, thanks.

line 26

A: 
nick = data.split('!')[ 0 ].replace(':',' ') 

That's going to replace the : with a space (), and thus the resulting string will be "s0urd ", not "s0urd". You probably meant this instead:

nick = data.split('!')[ 0 ].replace(':','')

Note the lack of space between the '' being passed as the replacement string.

Amber
Thank you amber, it works ;)
SourD