|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
IRC Bot
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. |
|
#2
|
||||
|
||||
|
Basic example (the IRC thing i wrote for X):
Code:
#!/usr/bin/env python
import socket
class IRC:
def __init__(self):
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
def connect(self):
try:
self.sock.connect((self.host, self.port))
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)
self.sock.send('NAMES\n\r')
while True:
print self.recieve()
except:
print 'Error Occured'
def recieve(self):
line = self.sock.recv(self.byte)
if line.startswith('PING'):
self.sock.send('PONG : PING\n\r')
return 'PONG has been sent'
else:
return line
if __name__ == '__main__':
pybot = IRC()
pybot.host = 'irc.h4ckerx.net'
pybot.room = '#bot'
pybot.nick = 'Netytan'
pybot.port = 6667
pybot.byte = 1025
pybot.connect()
Mark. |
|
#3
|
|||
|
|||
|
Thanks alot for the code. I'm not sure if it's working right, though (for Quakenet anyway)
Code:
[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 [edit] 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] Last edited by XxChris : January 28th, 2004 at 08:52 PM. |
|
#4
|
||||
|
||||
|
Mmmm, sorry, don't know what the problem here is sorry, works fine for me as is... Think Strikes the guy for this one!!!
Mark. |
|
#5
|
|||
|
|||
|
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. |
|
#6
|
|||
|
|||
|
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?
Code:
:port80_!~chris@bleh.net PRIVMSG #thisisatest :Test |
|
#7
|
|||
|
|||
|
Quote:
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. ![]() |
|
#8
|
|||
|
|||
|
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:
Code:
rt80_!~chris@bleh.net PRIVMSG #thisisatest :.say Hello Parse out '.say Hello' and get the bot to say 'Hello'. I will take a look at supybot when I have a bit more time, and I'll probably drop by #supybot sometime ![]() |
|
#9
|
|||
|
|||
|
Quote:
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 http://web.irc.org/mla/ircd-users/2002/msg00141.html 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 Steve |
|
#10
|
|||
|
|||
|
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.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > IRC Bot |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|