Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.50 KB | None | 0 0
  1. import sys, socket, string, os
  2.  
  3. HOST='chat.freenode.net'
  4. PORT=6667
  5. NICK='m4db0t'
  6. OWNER='m4dc0d3r'
  7. CHANNELINIT='#polyphasers'
  8. readbuffer=''
  9.  
  10. s=socket.socket()
  11.  
  12. def send(msg):
  13.     print msg
  14.     s.send(msg)
  15.  
  16. def privmsg(channel, msg):
  17.         msg = msg.rstrip()
  18.     send('PRIVMSG '+channel+' :'+msg+'\r\n')
  19.  
  20. print 'connecting...'
  21. s.connect((HOST,PORT))
  22. send('NICK '+NICK+'\r\n')
  23. send('USER '+NICK+' '+NICK+' '+NICK+' :'+NICK+'\r\n')
  24. send('JOIN '+CHANNELINIT+'\r\n')
  25.  
  26. def celsius(fahrenheit):
  27.     try:
  28.         return (float(fahrenheit)-32)/1.8
  29.     except ValueError:
  30.         return False
  31.  
  32. def fahrenheit(celsius):
  33.     try:
  34.     return float(celsius)*1.8+32
  35.     except ValueError:
  36.         return False
  37.  
  38. def parsemsg(msg):
  39.     cmd = msg.split(' ')[0]
  40.     if cmd == 'PING':
  41.         send('PONG :'+msg.split(':')[1])
  42.                 return
  43.     sender=msg.split('!')[0].replace(':','')
  44.     text = msg.split(':')[2]
  45.         channel = msg.split(' ')[2]
  46.     command = text.split(' ')[0]
  47.         try:
  48.         arg1 = text.split(' ')[1]
  49.         except IndexError:
  50.             arg1 = ''
  51.    
  52.     if command == '!f':
  53.                 result = fahrenheit(arg1)
  54.                 if result != False:
  55.             privmsg(channel, str(float(arg1))+' C = '+str(result)+' F.')
  56.     if command == '!c':
  57.                 result = celsius(arg1)
  58.                 if result != False:
  59.             privmsg(channel, str(float(arg1))+' F = '+str(result)+' C.')
  60.        
  61. line = ''
  62. while 1:
  63.     line = s.recv(500)
  64.     print line
  65.     parsemsg(line)
  66.     line=line.rstrip()
  67.     line=line.split()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement