ingx24

Untitled

Sep 8th, 2011
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.29 KB | None | 0 0
  1. import socket
  2.  
  3. class Bot:
  4.     def __init__(self, server, port, nick, channel, ident, name):
  5.         self.server = server
  6.         self.port = port
  7.         self.nick = nick
  8.         self.channel = channel
  9.         self.ident = ident
  10.         self.name = name
  11.        
  12.     def connect(self):
  13.         self.s=socket.socket( ) #Create the socket
  14.         self.s.connect((self.server, self.port)) #Connect to server
  15.         self.s.send('NICK '+self.nick+'n') #Send the nick to server
  16.         self.s.send('USER '+self.ident+' '+self.server+' bla :'+self.name+'n') #Identify to server
  17.         self.s.send('JOIN '+self.channel+'n') #Join a channel
  18.    
  19.     def connect_and_listen(self):
  20.         self.connect()
  21.         while 1:
  22.             line=self.s.recv(500) #recieve server messages
  23.             print line #server message is output
  24.             if line.find('PRIVMSG')!=-1: #Call a parsing function
  25.                 parsemsg(line)
  26.                 line=line.rstrip() #remove trailing 'rn'
  27.                 line=line.split()
  28.                 if(line[0]=='PING'): #If server pings then pong
  29.                     self.s.send('PONG '+line[1]+'n')
  30.                
  31. testbot = Bot("irc.metroid2002.com", 6667, "Testbot", "#zeldafuntalk", "Testbot", "Testbot")
  32. testbot.connect_and_listen()
Advertisement
Add Comment
Please, Sign In to add comment