Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Sep 2nd, 2010 | Syntax: None | Size: 2.20 KB | Hits: 62 | Expires: Never
Copy text to clipboard
  1. import socket
  2. import sys
  3. import time
  4. from time import gmtime, strftime # Define variables
  5. #import botdata.txt
  6. network = 'irc.freenode.net'
  7. port = 6667
  8. nick = 'Ima_bot'
  9. owner = 'Berg'
  10. password = 'icewater'
  11. channel = '##wzgm' # set up our socket
  12. irc = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
  13. irc.connect ( ( network, port ) )
  14. irc.send ( 'NICK ' + nick + '\r\n' )
  15. irc.send ( 'USER Ima_bot Ima_bot Ima_bot :Python IRC\r\n' )
  16. time.sleep(6)
  17. irc.send('PRIVMSG NICKSERV :identify ' + password + ' \r\n')
  18. time.sleep(5)
  19. irc.send ( 'JOIN ' + channel + '\r\n' )
  20. def chatuser( input ): #get the user name of who is speaking
  21.         name = input.split("!")[0].replace(":", "")
  22.         return name
  23. def sendmsg( message ): #define "sendmsg" instead of write full irc.send()
  24.         irc.send('PRIVMSG ' + channel + ' :' + message + '.\r\n')
  25.         return
  26. i=0
  27. while True:
  28.         def changedata( input ): #write changed text files entry
  29.                 change = input.split("write")[1]
  30.                 return change
  31.         time1 = strftime("%a, %d %b %Y %H:%M:%S GMT", gmtime())
  32.         data = irc.recv ( 4096 )
  33.         data1 = data.upper()
  34.         if data.find ( nick ) != -1:
  35.                 if data.find(channel) != -1 and data1.find('QUIT') != -1 and chatuser(data) == owner:
  36.                         irc.send('PRIVMSG ' + channel + ' :If I must ' + owner + '.\r\n')
  37.                         time.sleep(6)
  38.                         irc.send('PRIVMSG ' + channel + ' :Ok fine Im outa here ' + owner + '.\r\n')
  39.                         irc.send("QUIT\r\n")
  40.                         print('Exit command issued from IRC')
  41.                         sys.exit()
  42.                 elif data1.find('QUIT') != -1 and chatuser(data) != owner:
  43.                         sendmsg( 'You are not my owner ' + chatuser(data))
  44.                 if data.find(channel) != -1 and data1.find('BITEME!') != -1:
  45.                         irc.send('PRIVMSG ' + channel + ' :Bite yourself ' + chatuser(data) + '.\r\n')
  46.                 if data.find(channel) != -1 and data1.find('READ') != -1:
  47.                         try:
  48.                                 f = open("botdata.txt", "r")
  49.                                 try:
  50.                                         line = f.readline()
  51.                                         irc.send('PRIVMSG ' + channel + ' :' + line + ' ' + chatuser(data) + '.\r\n')
  52.                                         print(line)
  53.                                         i=i+1
  54.                                 finally:
  55.                                         f.close()
  56.                         except IOError:
  57.                                 pass
  58.                 if data.find(channel) != -1 and data1.find('WRITE') != -1:
  59.                         try:
  60.                                 f = open("botdata.txt", "w")
  61.                                 try:
  62.                                         f.write (changedata(data))
  63.                                 finally:
  64.                                         f.close()
  65.                         except IOError:
  66.                                 pass