Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. import socket, string, os, re, time
  2.  
  3. #some user data, change as per your taste
  4. SERVER = 'irc.freenode.net'
  5. PORT = 6667
  6. NICKNAME = 'MsgToSpeech'
  7. CHANNEL = '#itunix-eu'
  8.  
  9. #open a socket to handle the connection
  10. IRC = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  11.  
  12. #open a connection with the server
  13. def irc_conn():
  14. IRC.connect((SERVER, PORT))
  15.  
  16. #simple function to send data through the socket
  17. def send_data(command):
  18. IRC.send(command + '\n')
  19.  
  20. #join the channel
  21. def join(channel):
  22. send_data("JOIN %s" % channel)
  23.  
  24. #send login data (customizable)
  25. def login(nickname, username='user', password = None, realname='Pythonist', hostname='Helena', servername='Server'):
  26. send_data("USER %s %s %s %s" % (username, hostname, servername, realname))
  27. send_data("NICK " + nickname)
  28.  
  29. irc_conn()
  30. login(NICKNAME)
  31. join(CHANNEL)
  32.  
  33. while (1):
  34. buffer = IRC.recv(1024)
  35. msg = string.split(buffer)
  36.  
  37. if msg [1] == 'PRIVMSG':
  38. message = ' '.join(msg[3:])
  39. print message
  40. os.system('espeak -v en "{0}" --stdout | aplay 2>/dev/null >/dev/null'.format(message)) #speech this!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement