Advertisement
amigojapan

small python IRC client

Sep 28th, 2014
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. http://archive.oreilly.com/pub/h/1968
  2. import errno
  3. import socket
  4. import sys
  5.  
  6. nick = sys.argv[1]
  7.  
  8. def send(*args):
  9. line = ' '.join(args) + '\r\n'
  10. conn.sendall(line.encode('utf-8'))
  11.  
  12. conn = socket.create_connection(('localhost', 6667))
  13. send('NICK', nick)
  14. send('USER', nick, nick, nick, nick)
  15. send('JOIN', '#c1')
  16. while True:
  17. #import readline; print readline.redisplay
  18. msg = input('> ')
  19. try:
  20. buf = conn.recv(1024, socket.MSG_DONTWAIT)
  21. except socket.error as e:
  22. if e.errno != errno.EAGAIN:
  23. raise
  24. else:
  25. print(buf.decode('utf-8'))
  26. if msg:
  27. send('PRIVMSG', '#c1', ':' + msg)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement