Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2014
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.36 KB | None | 0 0
  1. import socket
  2.  
  3. """Set up basic connection variables"""
  4.  
  5. nick = 'Biobot312' # Define nick on IRC
  6. debug = False # For debug mode
  7. network = 'irc.freenode.net' # Define IRC network
  8. port = 6667 # Define IRC server port
  9.  
  10. """Set up debug mode"""
  11.  
  12. if debug == True:
  13. chan = '#Biobot312Testing'
  14. elif debug == False:
  15. chan = '#awesomehash'
  16.  
  17. """Connect"""
  18.  
  19. irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #Define IRC socket
  20. irc.connect((network,port)) #Connect to the server
  21.  
  22. """Set up receive buffer and send user info and such"""
  23.  
  24. irc.recv (4096) #Setting up the Buffer
  25. irc.send('NICK ' + nick + '\r\n') #Send nick to the server
  26. irc.send('USER AffixBot AffixBot AffixBot :Affix IRC\r\n') #Send user info to the server
  27. irc.send('JOIN ' + chan + '\r\n') #Join chan
  28. irc.send('PRIVMSG ' + chan + ' :Biobot is IN THE BUILDING!\r\n') #Send joining message
  29.  
  30. """Start main loop and create receive buffer"""
  31.  
  32. while True: #While Connection is Active
  33. data = irc.recv (4096) #Make "data" the receive buffer
  34. print data #For debug
  35.  
  36. """Keep from pinging out"""
  37.  
  38. if data.find('PING') != -1: #If PING is Found in the Data
  39. irc.send('PONG ' + data.split()[1] + '\r\n') #Send back a PONG
  40.  
  41. """Handle commands"""
  42.  
  43. if data.find('PRIVMSG') != -1: #IF PRIVMSG is in the Data Parse it
  44. message = ':'.join(data.split (':')[2:]) #Split the command from the message
  45. if message.lower().find(chan) == -1 or message.lower().find('Biobot312') == -1: #If chan or Biobot312 is in the message continue
  46. nick = data.split('!')[ 0 ].replace(':','') #The nick of the user issueing the command is taken from the hostname
  47. destination = ''.join (data.split(':')[:2]).split (' ')[-2] #Destination is taken from the data
  48. print 'Message is ' + message + ' from ' + nick + '\r\n' #For debug
  49. if message.strip() != '': #If there is not just whitespace in the message
  50. function = message.split( )[0] #The function is the first thing in the message
  51. print 'Funtion is ' + function + ' From ' + nick + '\r\n' #For debug
  52. arg = message.split(" ") #Finally Split the Arguments by space (arg[0] will be the actual command)
  53. args = '' #Create the Variable for use
  54. for index,item in enumerate(arg) : #For every index and item in arg
  55. if index > 0 : # If the word is not the command
  56. if args == '': # If there are no Current Args
  57. args = item #Make Item the First Argument
  58. else:
  59. args += ' ' + item #Add the item to the string
  60.  
  61. """Respond to commands"""
  62.  
  63. if function == ',say' and nick == 'Bioman312' and destination == 'Biobot312': #If I pm ",say" to the bot
  64. irc.send('PRIVMSG ' + chan + ' :' + args + '\r\n') #Prints args
  65. elif function == ',help': #If function is ",help"
  66. irc.send('PRIVMSG ' + chan + ' :' + 'Hello! I am Bioman312\'s IRC bot! Commands are: ,help; !mobilize; ,window' + '\r\n') #Prints help text
  67. elif function == '!mobilize': #If function is "!mobilize"
  68. irc.send('PRIVMSG ' + chan + ' :' + 'BIOBOT ROLLING OUT!' + '\r\n') #Prints mobilize reply
  69. elif function == ',exit' and nick == 'Bioman312': #If function is ",exit" and I say it
  70. irc.send('PRIVMSG ' + chan + ' :' + 'Biobot shutting down.' + '\r\n') #Prints shutting down text
  71. sys.exit()
  72. elif function == ',window': #If function is ",window"
  73. irc.send('PRIVMSG ' + chan + ' :' + 'Throw it out the window, the window, the second-story window!' + '\r\n') #Prints window reply
  74. 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!"
  75. irc.send('PRIVMSG ' + chan + ' :' + 'United we stand!' + '\r\n') #Prints moon reply
  76. 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!"
  77. irc.send('PRIVMSG ' + chan + ' :' + 'I can tie a bowline.' + '\r\n') #Prints noom reply
  78. elif function == 'BLOCK' and arg[1] == 'FOUND:' and nick == 'AwesomeHashBot': #If AHBot reports a block found
  79. irc.send('PRIVMSG ' + chan + ' :' + 'AYYYYYYYYYY!' + '\r\n') #Prints block found reply
  80. elif function == 'Username:' and arg[1].lower() == 'bioman312' and nick == 'AwesomeHashBot': #If AHBot reports my hashrate
  81. irc.send('PRIVMSG ' + chan + ' :' + 'LOOK AT DAT HAAAASH!' + '\r\n') #Prints hashrate reply
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement