#!/usr/bin/env python """ bot.py - bot Author: Jon About: (non) """ import ircMath import socket network = 'irc.freenode.net' port = 6667 irc = socket.socket ( socket.AF_INET, socket.SOCK_STREAM ) irc.connect ( ( network, port ) ) irc.recv ( 4096 ) irc.send ( 'NICK rbirnt\r\n' ) irc.send ( 'USER rbirnt rbirnt rbirnt :Python IRC\r\n' ) irc.send ( 'JOIN #Vectorbot\r\n' ) irc.send ( 'PRIVMSG #Vectorbot :Hello.\r\n' ) while True: data = irc.recv ( 4096 ) if data.find ( 'PING' ) != -1: irc.send ( 'PONG ' + data.split() [ 1 ] + '\r\n' ) elif data.find ( 'PRIVMSG' ) != -1: message = ':'.join ( data.split ( ':' ) [ 2: ] ) if message.lower().find ( '%rbirnt' ) == 0: nick = data.split ( '!' ) [ 0 ].replace ( ':', '' ) destination = ''.join ( data.split ( ':' ) [ :2 ] ).split ( ' ' ) [ -2 ] function = message.split ( ' ' ) [ 1 ] if function == 'calc': try: args = message.split ( ' ' ) [ 2: ] solution = ircMath.arithmatic ( args ) irc.send ( 'PRIVMSG ' + destination + ' :' + nick + ': ' + solution + '\r\n' ) except: pass if function == 'sin': try: args = message.split ( ' ' ) [ 2: ] solution = ircMath.sine ( args ) irc.send ( 'PRIVMSG ' + destination + ' :' + nick + ': ' + solution + '\r\n' ) except: pass if function == 'cos': try: args = message.split ( ' ' ) [ 2: ] solution = ircMath.cosine ( args ) irc.send ( 'PRIVMSG ' + destination + ' :' + nick + ': ' + solution + '\r\n' ) except: pass if function == 'tan': try: args = message.split ( ' ' ) [ 2: ] solution = ircMath.tangent ( args ) irc.send ( 'PRIVMSG ' + destination + ' :' + nick + ': ' + solution + '\r\n' ) except: pass if message.startswith ( 'rbirnt' ): irc.send ( 'PRIVMSG #Vectorbot :WHAT???\r\n' )