Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys, socket, string, os
- HOST='chat.freenode.net'
- PORT=6667
- NICK='m4db0t'
- OWNER='m4dc0d3r'
- CHANNELINIT='#polyphasers'
- readbuffer=''
- s=socket.socket()
- def send(msg):
- print msg
- s.send(msg)
- def privmsg(channel, msg):
- msg = msg.rstrip()
- send('PRIVMSG '+channel+' :'+msg+'\r\n')
- print 'connecting...'
- s.connect((HOST,PORT))
- send('NICK '+NICK+'\r\n')
- send('USER '+NICK+' '+NICK+' '+NICK+' :'+NICK+'\r\n')
- send('JOIN '+CHANNELINIT+'\r\n')
- def celsius(fahrenheit):
- try:
- return (float(fahrenheit)-32)/1.8
- except ValueError:
- return False
- def fahrenheit(celsius):
- try:
- return float(celsius)*1.8+32
- except ValueError:
- return False
- def parsemsg(msg):
- cmd = msg.split(' ')[0]
- if cmd == 'PING':
- send('PONG :'+msg.split(':')[1])
- return
- sender=msg.split('!')[0].replace(':','')
- text = msg.split(':')[2]
- channel = msg.split(' ')[2]
- command = text.split(' ')[0]
- try:
- arg1 = text.split(' ')[1]
- except IndexError:
- arg1 = ''
- if command == '!f':
- result = fahrenheit(arg1)
- if result != False:
- privmsg(channel, str(float(arg1))+' C = '+str(result)+' F.')
- if command == '!c':
- result = celsius(arg1)
- if result != False:
- privmsg(channel, str(float(arg1))+' F = '+str(result)+' C.')
- line = ''
- while 1:
- line = s.recv(500)
- print line
- parsemsg(line)
- line=line.rstrip()
- line=line.split()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement