Advertisement
Guest User

Untitled

a guest
Sep 28th, 2016
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. import socket, string, datetime, subprocess
  2.  
  3. # some user data, change as per your taste
  4. SERVER = 'chat.freenode.net'
  5. # SERVER = 'irc.swiftirc.net'
  6. PORT = 6667
  7. NICKNAME = 'gest'
  8. PASS = 'aUOi5ffea4CGSEQekKKxlXBo'
  9. CHANNEL = '##linux'
  10. # CHANNEL = '#unmod'
  11.  
  12. # open a socket to handle the connection
  13. IRC = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  14.  
  15. # open a connection with the server
  16. def irc_conn():
  17. IRC.connect((SERVER, PORT))
  18.  
  19. # simple function to send data through the socket
  20. def send_data(command):
  21. IRC.send(command + '\n')
  22.  
  23. # join the channel
  24. def join(channel):
  25. send_data("JOIN %s" % channel)
  26.  
  27. # send login data (customizable)
  28. def login(nickname, username='tezsting', password = PASS, realname='madison', hostname='testifng', servername='teszting'):
  29. send_data("USER %s %s %s %s" % (username, hostname, servername, realname))
  30. send_data("NICK " + nickname)
  31.  
  32. irc_conn()
  33. login(NICKNAME)
  34. join(CHANNEL)
  35.  
  36. x = 0
  37.  
  38. while (1):
  39. buffer = IRC.recv(1024)
  40. msg = string.split(buffer)
  41. print msg
  42. # if msg[0] ==
  43. # nickname, trash = msg[0].partition('!')
  44. # print nickname
  45. if msg[0] == "PING": #check if server have sent ping command
  46. send_data("PONG %s" % msg[1]) #answer with pong as per RFC 1459
  47. if msg[1] == 'PRIVMSG':
  48. # rm = message(msg)
  49. # print rm.time, " : ", rm.nick, " - ", rm.text
  50. sep = '!'
  51. nickstart = msg[0].split(sep, 1)[0]
  52. nick = nickstart[1:]
  53. time = datetime.datetime.now()
  54. del msg[:3]
  55. msg[0] = msg[0][1:]
  56. print 'Message length:', len(msg)
  57. msgstr = " ".join(str(e) for e in msg)
  58. print msgstr
  59.  
  60. print 'At', time, ',', nick, 'said:', msgstr
  61.  
  62. subprocess.call(['powershell.exe', 'C:\Scripts\orgmail.ps1', '-ircuser', nick, '-ircmessage', msgstr])
  63.  
  64.  
  65. # f = open('msg.txt', 'a+')
  66. # filetxt = open('msg.txt', 'a+') #open an arbitrary file to store the messages
  67. # nick_name = msg[0][:string.find(msg[0],"!")] #if a private message is sent to you catch it
  68. # message = ' '.join(msg[3:])
  69. # filetxt.write(string.lstrip(nick_name, ':') + ' -> ' + string.lstrip(message, ':') + '\n') #write to the file
  70. # filetxt.flush() #don't wait for next message, write it now!
  71. # filetxt.close()
  72. # print '\n\n\nfile close\n\n\n\n'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement