Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import socket
- class Bot:
- def __init__(self, server, port, nick, channel, ident, name):
- self.server = server
- self.port = port
- self.nick = nick
- self.channel = channel
- self.ident = ident
- self.name = name
- def connect(self):
- self.s=socket.socket( ) #Create the socket
- self.s.connect((self.server, self.port)) #Connect to server
- self.s.send('NICK '+self.nick+'n') #Send the nick to server
- self.s.send('USER '+self.ident+' '+self.server+' bla :'+self.name+'n') #Identify to server
- self.s.send('JOIN '+self.channel+'n') #Join a channel
- def connect_and_listen(self):
- self.connect()
- while 1:
- line=self.s.recv(500) #recieve server messages
- print line #server message is output
- if line.find('PRIVMSG')!=-1: #Call a parsing function
- parsemsg(line)
- line=line.rstrip() #remove trailing 'rn'
- line=line.split()
- if(line[0]=='PING'): #If server pings then pong
- self.s.send('PONG '+line[1]+'n')
- testbot = Bot("irc.metroid2002.com", 6667, "Testbot", "#zeldafuntalk", "Testbot", "Testbot")
- testbot.connect_and_listen()
Advertisement
Add Comment
Please, Sign In to add comment