Advertisement
Guest User

Untitled

a guest
Jul 1st, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. # ircecho.py
  4. # Copyright (C) 2011 : Robert L Szkutak II - http://robertszkutak.com
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License along
  17. # with this program; if not, write to the Free Software Foundation, Inc.,
  18. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19.  
  20. import sys
  21. import string
  22. import socket
  23. import ssl
  24. import time
  25. import types
  26.  
  27. def recvall(sock):
  28. data=""
  29. while True:
  30. chunk=str(sock.recv(4096),"utf-8")
  31. data+=chunk
  32. if data.endswith("\n"):
  33. return data.splitlines()
  34.  
  35. def send(sock,data,verbose=True):
  36. if verbose:print(">",data)
  37. return sock.send(bytes(data,"utf-8")+b"\n")
  38.  
  39. def recvall(sock):
  40. data=""
  41. while True:
  42. chunk=str(sock.recv(4096),"utf-8")
  43. data+=chunk
  44. if data.endswith("\n"):
  45. return data.splitlines()
  46.  
  47. ## Settings
  48. ### IRC
  49. server = "irc.bonerjamz.us"
  50. port = 6697
  51. channel = "#idletown"
  52. botnick = "welpbot"
  53. irc_s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  54. irc = ssl.wrap_socket(irc_s) #defines the socket
  55. print("Establishing connection to [{}]".format(server))
  56. irc.connect((server, port))
  57. send(irc,"USER "+ botnick +" "+ botnick +" "+ botnick +" :welpbot\n")
  58. send(irc,"NICK "+ botnick +"\n")
  59. send(irc,"JOIN "+ channel +"\n")
  60. send(irc,"NICK "+ botnick +"\n")
  61.  
  62. lines=[]
  63. while 1:
  64. lines += recvall(irc)
  65.  
  66. while lines:
  67. line = lines.pop()
  68. print(line)
  69. line = str.rstrip(line)
  70. line = str.split(line)
  71.  
  72. if(line[0] == "PING"):
  73. send(irc,"PONG {}\r\n".format(line[1]))
  74. if(line[1] == "MSG"):
  75. if line.contains("welp"):
  76. message = "welp!"
  77. send(irc,"MSG {} {} \r\n".format(message))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement