January 28th, 2004, 08:11 PM
I'm interessted in making a simple IRC bot, but I'm knew at Python and have no experience in making bots. Does anybody know any good resources? How much work is it to write one to simple connect to an IRC network and say "Hello, World!" ?
From what I understand, Strike, you are developing an IRC bot (it's acutaly where I got the idea ), but I downloaded the source and it looks a bit much for me, hehe .
Last edited by XxChris; January 28th, 2004 at 08:15 PM.
January 28th, 2004, 08:27 PM
Basic example (the IRC thing i wrote for X):
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.send('NICK %s\n\r' % self.nick)
self.sock.send('USER localhost localhost localhost : Python Powered\n\r')
self.sock.send('JOIN %s\n\r' % self.room)
self.sock.send('PRIVMSG %s : Python Powered\n\r' % self.room)
print 'Error Occured'
line = self.sock.recv(self.byte)
self.sock.send('PONG : PING\n\r')
return 'PONG has been sent'
if __name__ == '__main__':
pybot = IRC()
pybot.host = 'irc.h4ckerx.net'
pybot.room = '#bot'
pybot.nick = 'Netytan'
pybot.port = 6667
pybot.byte = 1025
January 28th, 2004, 08:46 PM
Thanks alot for the code. I'm not sure if it's working right, though (for Quakenet anyway)
 It didn't work on irc.wyldryde.net but did on irc.freenode.net. What's making the difference between servers and is it easy to fix? [/edit]
[Aurora:~/dev/python] chris% python pybot.py
NOTICE AUTH :*** Looking up your hostname
NOTICE AUTH :*** Checking Ident
NOTICE AUTH :*** Found your hostname
NOTICE AUTH :*** No ident response
PONG has been sent
:tiscali.dk.quakenet.org 513 shpleh :To connect, type /QUOTE PONG 980340643
Last edited by XxChris; January 28th, 2004 at 08:52 PM.
January 28th, 2004, 08:55 PM
Mmmm, sorry, don't know what the problem here is sorry, works fine for me as is... Think Strikes the guy for this one!!!
January 28th, 2004, 10:02 PM
Actually, as far as low-level IRC stuff goes, I'm not so great with it. Though this is the second Python bot I'll have worked with (the first one being one that I built along with another coder), I've never actually built the base IRC library. For moobot (the first bot, the one for which I did the majority of the coding), I used Joel Rosdahl's IRC library. For supybot, I'm using jemfinch's (project founder) IRC library which is a lot better than Joel's, though a bit more complex, I believe.
I'd recommend using an existing IRC library and playing around with that in order to make your bot. Joel's will do for you (it's the most widely used, I think, search for python irclib), but note that it is limited in capability. I believe Twisted has one as well, I'm not too familiar with it. And jemfinch's is of course, excellent, but I'm not so sure how complex it is or how newbie friendly it might be.
January 29th, 2004, 04:51 PM
Thanks Strike. One question though: I see that when I talk in the channel, my message appears in the Bot window. For the bot to recognize commands, do I simply parse that output?
:firstname.lastname@example.org PRIVMSG #thisisatest :Test
January 29th, 2004, 05:12 PM
Are you trying to develop for supybot? If so, check out all the stuff in the docs/ folder. There are a lot of good tips and hints in there. If you want more specific info, feel free to drop by #supybot on either irc.freenode.net or irc.oftc.net (a supybot runs a relay between the two) and ask people who are about. jemfinch (the founder/creator), jamessan, and I in particular are fairly well-versed on the internals of the bot.
January 29th, 2004, 05:37 PM
At the moment I've just been messing with netytan's code and what I posted earlier was the output I get when I type something into the channel. I'm just not sure if this is the proper way to parse for a command like ".say Hello"... I'd see:
Parse out '.say Hello' and get the bot to say 'Hello'.
email@example.com PRIVMSG #thisisatest :.say Hello
I will take a look at supybot when I have a bit more time, and I'll probably drop by #supybot sometime
August 27th, 2004, 05:01 PM
Heya, I had the same problem and just found the solution. Although this thread is old enough that you probably already know the answer lol :P
Originally Posted by XxChris
Basically, the server is PINGing your client with a random number and you have to PONG that number back at him. All you're sending at the moment is a straight string "PONG : PING" which is incorrect. The link I provided explains it much better than I can lol
November 20th, 2004, 04:58 AM
I dont know Python at all but i know why its asking to quote with the unique PONG is part of the p10 protocol. You have to add a snippit into the PONG reply in your script to send back the PONG with the quote'd number. If that makes any sense at all... It happens with really any language you program bots with. p10 or I think most server protocol's these days will require you send a PONG back with the respective number it generates.