Guest User

Untitled

a guest
Aug 4th, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.87 KB | None | 0 0
  1.  
  2.  
  3. import sys, socket, os
  4.  
  5. readbuffer = ''
  6. step = 0
  7. channel = '#admin'
  8. username = 'WordBot'
  9. password = 'password'
  10. server = 'irc.minecraft.co.nz'
  11. port = 6667
  12. connected = False
  13.  
  14. words = ['justinbeiber','onedirection','corrin','corrinlakeland']
  15. def IRCUser(line):
  16.     return line[0].split(':')[1].split('!')[0]
  17. s = socket.socket( socket.AF_INET, socket.SOCK_STREAM )
  18. print('Connecting to '+server+':'+bin(port))
  19. try:
  20.     s.connect( (server,port) )
  21.     s.send('NICK '+username+'\r\n')
  22.     s.send('USER '+username+' '+username+' '+username+' :TTOBOT\r\n' )
  23. except:
  24.     print('Failed to connect.', sys.exc_info() )
  25. running = 1
  26. while running:
  27.     readbuffer = readbuffer + s.recv(1024)
  28.     lines = readbuffer.split('\n')
  29.     readbuffer = lines.pop()
  30.     for line in lines:
  31.         print(line)
  32.         line = line.rstrip().split()
  33.         if 'PING' in line: s.send('PONG '+line[1] +'\r\n')
  34.         if '/MOTD' in line:
  35.             s.send('JOIN '+channel+'\r\n')
  36.             connected = 1
  37.             print("Connected!")
  38.             s.send('PRIVMSG '+channel+' Watching for these words:\r\n')
  39.             for word in words:
  40.                 s.send('PRIVMSG '+channel+' '+word+'\r\n')
  41.         if connected==0:
  42.             s.send('JOIN '+channel+'\r\n')
  43.             connected = 1
  44.             print("Connected!")
  45.         if connected:
  46.             #s.send('PING');
  47.             if (len(line) > 3):
  48.                 for section in line:
  49.                     section = section.lower().replace(":","")
  50.                     if section in words:
  51.                         if(IRCUser(line)!=username):
  52.                             s.send('PRIVMSG '+channel+' Kicking '+IRCUser(line)+ ' for saying '+section+'\r\n')
  53.                             s.send('KICK '+channel+" "+IRCUser(line)+' saying '+section+'\r\n')
  54.                             print("Kicked: "+IRCUser(line))
  55.                 if("pissoffbot" in line[3]):
  56.                     s.send('PRIVMSG '+channel+' OK. Cya later.\r\n')
  57.                     print("Quitting: "+IRCUser(line))
  58.                     running = 0
  59.             if 'KICK' in line:
  60.                 connected = 0
  61.             if '353'in line:
  62.                 s.send('PRIVMSG MineBot !login '+password+'\r\n')
  63. s.close()
  64. sys.exit()
Add Comment
Please, Sign In to add comment