Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.63 KB | None | 0 0
  1. import platform
  2. import socket
  3. import getpass
  4.  
  5. # Global Variables
  6. ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  7. server = "your.server.choice"
  8. channel = "#YourChannelHere"
  9.  
  10. # IRC Socket & User/Nick Functions
  11. ircsock.connect((server, 6667))
  12. ircsock.send(bytes("USER "+ botnick +" "+ botnick +" "+ botnick + " " + botnick + "\n", "UTF-8"))
  13. ircsock.send(bytes("NICK "+ botnick +"\n", "UTF-8")) # assign the nick to the bot
  14.  
  15. # System Info
  16. username = getpass.getuser()
  17. hostname = socket.gethostname()
  18. PS = platform.system()
  19. PR = platform.release()
  20. PS = "Z"
  21. PR = "6"
  22. if PS == "Windows":
  23.      PS3 = "W"
  24. if PR == "8.1":
  25.      PR3 = "8"
  26. if PR == "Vista":
  27.      PR3 = "V"
  28.  
  29. # Respond to Pings
  30. def ping():
  31.      global ircsock
  32.      ircsock.send(bytes("PONG :pingis\n", "UTF-8"))
  33.  
  34. # Join Channel & Strip & Print Messages from IRC
  35. def joinchan(chan):
  36.      ircsock.send(bytes("JOIN "+ chan +"\n", "UTF-8"))
  37.      ircmsg = ""
  38.      while ircmsg.find("End of /NAMES list.") == -1:
  39.           ircmsg = ircsock.recv(2048).decode("UTF-8")
  40.           ircmsg = ircmsg.strip('\n\r')
  41.           print(ircmsg)
  42.  
  43. def main():
  44.      joinchan(channel)
  45.      while 1:
  46.           ircmsg = ircsock.recv(2048).decode("UTF-8")
  47.           ircmsg = ircmsg.strip('\n\r')
  48.           print(ircmsg)
  49.           if ircmsg.find("PING :") != -1:
  50.                ping()
  51.           if ircmsg.find("PRIVMSG") != -1:
  52.                name = ircmsg.split('!', 1)[0][1:]
  53.                message = ircmsg.split('PRIVMSG', 1)[1].split(':', 1)[1]
  54.                if len(name) < 17:
  55.                     if ircmsg.find("PING :") != -1:
  56.                          ping()
  57.  
  58. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement