Simple IRC bot with SSL


/ Published in: Python
Save to your folder(s)

This is a simple IRC bot connecting with SSL.


Copy this code and paste it in your HTML
  1. #!/usr/bin/python
  2. # -*- coding: utf8 -*-
  3.  
  4. import socket, string, time, ssl
  5. import urllib, re
  6.  
  7. network = 'irc.server.net'
  8. nick = 'nickname'
  9. chan = 'bot'
  10. port = 6697
  11.  
  12. socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
  13.  
  14. def main(network, nick, chan, port):
  15. socket.connect((network,port))
  16. irc = ssl.wrap_socket(socket)
  17. irc.send('NICK %s
  18. ' % nick)
  19. print irc.recv(4096)
  20. irc.send('USER %s %s %s :My bot
  21. ' % (nick,nick,nick))
  22. print irc.recv(4096)
  23. irc.send('JOIN #%s
  24. ' % chan)
  25. print irc.recv(4096)
  26.  
  27. while True:
  28. data = irc.recv(4096)
  29. print data
  30.  
  31. if data.find('PING') != -1:
  32. irc.send('PONG '+data.split()[1]+'
  33. ')
  34. if data.find('!gtfo
  35. ') != -1:
  36. irc.send('QUIT
  37. ')
  38. exit()
  39. print data
  40.  
  41. if __name__=='__main__':
  42. main(network, nick, chan, port)

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.