#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2005
    Posts
    5
    Rep Power
    0

    Need help with an IRC bot


    I'm a nubie here so go on easy on me...

    Code:
    import socket
    
    passwd = "asdfasdf"
    nick = "goon"
    channel = "#somerandomchannel"
    server = 'irc.sorcery.net'
    
    socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    socket.connect((server, 6667))
    socket.send('NICK %s\r\n' % nick)
    #socket.send('PASS ' + passwd + '\r\n')
    socket.send('USER moo 0 * : moo\r\n')
    socket.send('JOIN %s\r\n' % channel)
    socket.send('PRIVMSG #infoceptor :Hullo.\r\n')
    
    while 1:
    	data = socket.recv(1024)
    	print data
    	
    	if data.find('VERSION'):
    		socket.send('PRIVMSG %s :testbot v.01 linux\r\n' % data.split('!')[0].replace(':',''))
    
    	if data.startswith("PING"):
    		socket.send('PONG %s\r\n' % data.split(":")[1])
    The problem is that when connecting to this particular server, it versions each and every client before letting them do anything else. If no answer is given the client is disconnected. On other servers where version is not required, the bot connects and does its stuff (as much as it can do for now...) just fine.

    The bold part of the code is what's giving me trouble. When the server's auth bot versions my bot, the code should cut out auth bot's name on the same line between the colon and DNS mask and privmsg back the version information to it. However what actually happens is for some reason it skips a couple of lines down and does the slicing on a completely different line sending the information to servername.sorcery.net and in turn my bot into an infinite loop, since the server send back a 451 error, (451 ERR_NOTREGISTERED ":You have not registered" - Returned by the server to indicate that the client MUST be registered before the server will allow it to be parsed in detail.)

    Anyone know what i'm doing wrong, or what i should do to stop the line skipping? Also i hope i made atleast a small ammount of sense...
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Location
    Regensburg, Germany
    Posts
    147
    Rep Power
    17
    The find() method of a string returns
    • -1 if the string is not found
    • 0 if the string is found at the beginning and
    • the string position if it is found somewhere else

    In your code the condition will be true anytime except when 'data' starts with "VERSION". So modify the if statement to:
    Code:
            if data.find("VERSION") >= 0:
                    ...
    Maybe the 'data.split(...' statement doesn't work either. If you could post an example for 'data' I could try to check this.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2005
    Posts
    5
    Rep Power
    0
    Yeah you're right it's not catching the line 'VERSION' is on.

    This is 'data's' data:

    :zaphire.sorcery.net NOTICE AUTH :*** Hello, you are connecting to zaphire.sorcery.net, the progress of your connection follows
    :zaphire.sorcery.net NOTICE AUTH :*** If you experience problems connecting, you may wish to try reconnecting with /server irc.sorcery.net 9000
    :zaphire.sorcery.net NOTICE AUTH :*** Looking up your hostname...
    :zaphire.sorcery.net NOTICE AUTH :*** Found your hostname (cached)

    :zaphire.sorcery.net NOTICE AUTH :*** If you are having problems connecting due to ping timeouts, please type /notice FB2219D4 nospoof now.
    :zaphire.sorcery.net NOTICE AUTH :*** If you still have trouble connecting, then please see: http://www.sorcery.net/help/connecting.html
    PING :FB2219D4
    :Auth-45CDC779!auth@nil.imsk PRIVMSG goon :VERSION

    :zaphire.sorcery.net 451 * :You have not registered
    :zaphire.sorcery.net 451 * :You have not registered

    :zaphire.sorcery.net 451 * :You have not registered

    :zaphire.sorcery.net 451 * :You have not registered



    And this is what data.split is holding:

    data.split('!')[0].replace(':','')
    'zaphire.sorcery.net 451 * You have not registered\r\n'

    Any ideas why it's skipping lines?
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2005
    Posts
    5
    Rep Power
    0
    So yeah any ideas? :/

IMN logo majestic logo threadwatch logo seochat tools logo