Advertisement
Guest User

codigo irc simples python

a guest
Dec 31st, 2017
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. # encoding: utf-8
  3. import platform
  4. import socket
  5. import sys
  6.  
  7. reload(sys)
  8. sys.setdefaultencoding("utf8")
  9.  
  10. ##config
  11. server = "ip"
  12. channel = "#canal"
  13. nick = "nick"
  14. user = "usuario"
  15. senduser = False
  16. sendnick = False
  17. sendpassword = False
  18. password = "Senha"
  19.  
  20. irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  21. print "\nConnecting to: " + server + ":"
  22. irc.connect((server, 6667))
  23.  
  24. def sendmsg(msg):
  25. irc.send("PRIVMSG " + channel + " :" + msg + "\n")
  26.  
  27. try:
  28. while 1:
  29. text = irc.recv(2048)
  30.  
  31. if len(text) > 0:
  32. print text
  33. else:
  34. continue
  35.  
  36. if text.find("PING") != -1:
  37. irc.send("PONG " + text.split()[1] + "\n")
  38.  
  39. if senduser == False:
  40. irc.send("USER " + user + " " + user + " " + user + " :" + user + "\n")
  41. senduser = True
  42. continue
  43.  
  44. if senduser and sendnick == False:
  45. irc.send("NICK " + nick + "\n")
  46. sendnick = True
  47. continue
  48.  
  49. if sendpassword == False:
  50. irc.send("NICKSERV IDENTIFY " + password + "\r\n")
  51. sendpassword = True
  52. continue
  53.  
  54. if text.find("255 " + nick) != -1:
  55. global br
  56. irc.send("JOIN " + channel + "\n")
  57.  
  58. ##Comandos
  59. if text.find("!oi") != -1:
  60. sendmsg("ola")
  61.  
  62. except KeyboardInterrupt:
  63. sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement