Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 28th, 2004, 08:11 PM
XxChris XxChris is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 217 XxChris User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #2  
Old January 28th, 2004, 08:27 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,536 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 11 m 13 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
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.
__________________
programming language development: www.netytan.com Hula


Reply With Quote
  #3  
Old January 28th, 2004, 08:46 PM
XxChris XxChris is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 217 XxChris User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #4  
Old January 28th, 2004, 08:55 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,536 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 11 m 13 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
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.

Reply With Quote
  #5  
Old January 28th, 2004, 10:02 PM
Strike Strike is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2001
Location: Houston, TX
Posts: 383 Strike User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 41 m 27 sec
Reputation Power: 7
Send a message via ICQ to Strike Send a message via AIM to Strike Send a message via Yahoo to Strike
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.

Reply With Quote
  #6  
Old January 29th, 2004, 04:51 PM
XxChris XxChris is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 217 XxChris User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #7  
Old January 29th, 2004, 05:12 PM
Strike Strike is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2001
Location: Houston, TX
Posts: 383 Strike User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 41 m 27 sec
Reputation Power: 7
Send a message via ICQ to Strike Send a message via AIM to Strike Send a message via Yahoo to Strike
Quote:
Originally posted by XxChris
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

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.
__________________
Debian - because life's too short for worrying.
Best. (Python.) IRC bot. ever.

Reply With Quote
  #8  
Old January 29th, 2004, 05:37 PM
XxChris XxChris is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 217 XxChris User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #9  
Old August 27th, 2004, 05:01 PM
Master-Andra Master-Andra is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 1 Master-Andra User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally Posted by XxChris
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]


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

Reply With Quote
  #10  
Old November 20th, 2004, 04:58 AM
Xolt Xolt is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 1 Xolt User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 48 sec
Reputation Power: 0
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > IRC Bot


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT