Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import socket
- """Set up basic connection variables"""
- nick = 'Biobot312' # Define nick on IRC
- debug = False # For debug mode
- network = 'irc.freenode.net' # Define IRC network
- port = 6667 # Define IRC server port
- """Set up debug mode"""
- if debug == True:
- chan = '#Biobot312Testing'
- elif debug == False:
- chan = '#awesomehash'
- """Connect"""
- irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #Define IRC socket
- irc.connect((network,port)) #Connect to the server
- """Set up receive buffer and send user info and such"""
- irc.recv (4096) #Setting up the Buffer
- irc.send('NICK ' + nick + '\r\n') #Send nick to the server
- irc.send('USER AffixBot AffixBot AffixBot :Affix IRC\r\n') #Send user info to the server
- irc.send('JOIN ' + chan + '\r\n') #Join chan
- irc.send('PRIVMSG ' + chan + ' :Biobot is IN THE BUILDING!\r\n') #Send joining message
- """Start main loop and create receive buffer"""
- while True: #While Connection is Active
- data = irc.recv (4096) #Make "data" the receive buffer
- print data #For debug
- """Keep from pinging out"""
- if data.find('PING') != -1: #If PING is Found in the Data
- irc.send('PONG ' + data.split()[1] + '\r\n') #Send back a PONG
- """Handle commands"""
- if data.find('PRIVMSG') != -1: #IF PRIVMSG is in the Data Parse it
- message = ':'.join(data.split (':')[2:]) #Split the command from the message
- if message.lower().find(chan) == -1 or message.lower().find('Biobot312') == -1: #If chan or Biobot312 is in the message continue
- nick = data.split('!')[ 0 ].replace(':','') #The nick of the user issueing the command is taken from the hostname
- destination = ''.join (data.split(':')[:2]).split (' ')[-2] #Destination is taken from the data
- print 'Message is ' + message + ' from ' + nick + '\r\n' #For debug
- if message.strip() != '': #If there is not just whitespace in the message
- function = message.split( )[0] #The function is the first thing in the message
- print 'Funtion is ' + function + ' From ' + nick + '\r\n' #For debug
- arg = message.split(" ") #Finally Split the Arguments by space (arg[0] will be the actual command)
- args = '' #Create the Variable for use
- for index,item in enumerate(arg) : #For every index and item in arg
- if index > 0 : # If the word is not the command
- if args == '': # If there are no Current Args
- args = item #Make Item the First Argument
- else:
- args += ' ' + item #Add the item to the string
- """Respond to commands"""
- if function == ',say' and nick == 'Bioman312' and destination == 'Biobot312': #If I pm ",say" to the bot
- irc.send('PRIVMSG ' + chan + ' :' + args + '\r\n') #Prints args
- elif function == ',help': #If function is ",help"
- irc.send('PRIVMSG ' + chan + ' :' + 'Hello! I am Bioman312\'s IRC bot! Commands are: ,help; !mobilize; ,window' + '\r\n') #Prints help text
- elif function == '!mobilize': #If function is "!mobilize"
- irc.send('PRIVMSG ' + chan + ' :' + 'BIOBOT ROLLING OUT!' + '\r\n') #Prints mobilize reply
- elif function == ',exit' and nick == 'Bioman312': #If function is ",exit" and I say it
- irc.send('PRIVMSG ' + chan + ' :' + 'Biobot shutting down.' + '\r\n') #Prints shutting down text
- sys.exit()
- elif function == ',window': #If function is ",window"
- irc.send('PRIVMSG ' + chan + ' :' + 'Throw it out the window, the window, the second-story window!' + '\r\n') #Prints window reply
- elif function.lower() == 'to' and arg[1].lower() == 'the' and (arg[2].lower() == 'moon\r\n' or arg[2].lower() == 'moon!\r\n'): #If function is "To the moon!"
- irc.send('PRIVMSG ' + chan + ' :' + 'United we stand!' + '\r\n') #Prints moon reply
- elif function.lower() == 'to' and (arg[1].lower() == 'the' or arg[1].lower() == 'teh') and (arg[2].lower() == 'noom\r\n' or arg[2].lower() == 'noom!\r\n'): #If function is "To the noom!"
- irc.send('PRIVMSG ' + chan + ' :' + 'I can tie a bowline.' + '\r\n') #Prints noom reply
- elif function == 'BLOCK' and arg[1] == 'FOUND:' and nick == 'AwesomeHashBot': #If AHBot reports a block found
- irc.send('PRIVMSG ' + chan + ' :' + 'AYYYYYYYYYY!' + '\r\n') #Prints block found reply
- elif function == 'Username:' and arg[1].lower() == 'bioman312' and nick == 'AwesomeHashBot': #If AHBot reports my hashrate
- irc.send('PRIVMSG ' + chan + ' :' + 'LOOK AT DAT HAAAASH!' + '\r\n') #Prints hashrate reply
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement