Advertisement
MrPoxipol

Python simple irc bot

Sep 14th, 2013
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.40 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2.  
  3. import socket
  4.  
  5. owner = 'MrPoxipol'
  6.  
  7. serv = 'irc.freenode.org'
  8. port = 6667
  9.  
  10. chan = '#poxipol_chan'
  11. nick = 'MrPoxipol1'
  12.  
  13. prefix = '@'
  14.  
  15. locked = False
  16.  
  17. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  18. s.connect((serv, port))
  19.  
  20. s.recv(4096)
  21. s.send('USER ja-abus abuse abuse :TAK!\r\n')
  22. s.send('NICK ' + nick + '\r\n')
  23. s.send('JOIN ' + chan + '\r\n')
  24.  
  25. def getMsgNick(data, i):
  26.     user = data[1:i]
  27.     ni = user.find('!')
  28.     return user[:ni]
  29.  
  30. while 1:
  31.     data = s.recv(4096)
  32.     print (data)
  33.    
  34.     if data.find( 'PING' ) != -1:
  35.         s.send('PONG ' + data.split() [1] + '\r\n')
  36.    
  37.     index = data.find('Witaj, ' + nick)
  38.     if index != -1:
  39.         s.send('PRIVMSG ' + chan + ' :' + 'Czesc ' + getMsgNick(data, index) + '!\r\n')
  40.        
  41.     index = data.find(prefix + 'won')
  42.     if index != -1:
  43.         if getMsgNick(data, index) == owner:
  44.             s.send('QUIT :Pa, pa')
  45.             break;
  46.         else:
  47.             s.send('PRIVMSG ' + chan + ' :' + '<Nie masz praw>\r\n')
  48.            
  49.     index = data.find(prefix + 'google')
  50.     if index != -1:
  51.         str = data[index+len('google')+2:]
  52.         str = str.rstrip()
  53.         send = False;
  54.         if len(str) > 1:
  55.             if str[1] == ' ':
  56.                 str = str.lstrip()
  57.             send = True
  58.         if send:
  59.             s.send('PRIVMSG ' + chan + ' :' + 'http://google.pl/search?q=' + str.replace(' ', '+') + '\r\n')
  60.            
  61.     if data.find(prefix + 'help') != -1:
  62.         s.send('PRIVMSG ' + chan + ' :' + 'Dostępne komendy: help, google, won*\r\n')
  63.  
  64. s.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement