Make a simple IRC bot. Task


  Make a simple IRC bot which does simple task like greeting user.


Detail

(You may see this RFC document.)

Write a complete program that perform these:


The program inputs nickname and realname from the user.


All nickname and realname which form is [A-Za-z0-9]+ should be allowed, but it isn't  important whether other forms are allowed. For example, if the user wants 1234qwerty as nickname and 5319009 as realname, the program should use those names, but it isn't important whether the program can use ^^☆Rick Astley☆^^ (which includes non-alphabet&amp;decimals) as (nickname or realname) or not, even thought this name may be rejected by the server.

The program inputs serverAddress from the user.


The form of serverAddress is serverIP:serverPort, where serverIP is the IP address of the server and serverPort is the port num of the server.

The program connects to port serverPort at IRC server serverIP, and it should set it's nickname as nickname and realname as realname by sending USER realname 0 * :realname and NICK nickname.
The program inputs a single channelName which doesn't include #, and join to the channel #channelName.
Send a private message Hello, world! to the #channelName channel like this: PRIVMSG #channelName :Hello, world!
Then, the program does these:

A. If someone joins, greeting him by saying Hello, @! to #channelName, where @ is the nickname of him/her.

B. If the program is kicked, try re-joining.

C. If a person is kicked or banned, say POW HAHA.

D. If a person leaves (PART or QUIT), say Goodbye, @!, where @ is the nickname of him/her.

E. If someone says some text including Turing test or turing test, say I'm a human!.

F. If someone says some text including 6*9, quit by sending QUIT :42 to the server.

G. If someone says some text including all your base are belong to us(case-insensitive), quit by sending QUIT :What you say! to the server.

H. If someone says some text preceding with a space and above acts aren't performed by the text, say the sum of charcode of all (except the first space) chars in the text.


If an error is occurred

If an error (such as connection error or invalid nickname) is occurred, you can do what you want to do. For example, if the nickname is already in use, the program may stop, gets a new nickname from the user, or automatically change the nickname and retry.

Restriction

The program


Should not use any internal functions or libraries which is for IRC client/bot making. i.e. something like IRC client libraries 
Should prompt what it'll input, before it gets an input. For example, before inputs serverAddress, it should prompt Write the address of server:, serverIP:serverPort &gt; , serverAddress &gt;, or some text that the user can recognize.
Should work on several IRC servers using UTF-8. (i.e. not for single server)
's messages send to server shouldn't be NOTICE. (RFC 2812, 3.3.2 Notice : The difference between NOTICE and PRIVMSG is that automatic replies MUST NEVER be sent in response to a NOTICE message.)
Should send a message where the request came from (#channelName or nickname).
Should PONG when PINGed, of course.


PS

Well, I just made this, because there was no puzzle about IRC bot.

Edit

After reading @dmckee's comment, I changed the rule for choosing winner.


Default bonus = +0
If somehow the program can connect to a channel (even if it's not #channelName), bonus = 1
If the program can perform step 1~5, bonus *= 2.
For each tasks A~H in step 6, if the program implements, bonus *= 1.2.
For each six restrictions, if the program follows that, bonus *= 1.05.


and score = int(codelength/bonus).

Program with lowest score is winner. If two answers have same score, then the answer with highest votes wins.

EDIT Edit : I think 1.2 and 1.05 in step 4 and 5 should be adjusted slightly bigger.. What do you think about this?

The winner is decided, however, I think there was too few entries.

Anyone still may submit the code.. :P
Python - 125 points


304 chars
follows steps 1-5 (works for me on irc.freenode.net:6667. if you try there, remember IDENT might take a while, so give it 20+ seconds to connect and speak)
follows 4 restrictions (assuming the NOTICE restriction which is a bit unclear. the UTF restriction counts because python won't choke if it doesn't need to parse any UTF).


score math (python):

bonus = 1 # connects to channel
bonus *= 2 # steps 1-5
for i in xrange(4):
    bonus *= 1.05 # 4 restrictions

int(304.0/bonus)
&gt; 125


code:

import socket
i=raw_input
u=i('user# ')
n=i('nick# ')
h,p=i('host:port# ').split(':',1)
p=int(p)
c='#'+i('chan# ')
z=0
while 1:
 try:
  def s(m): z.send(m+'\r\n')
  z.recv(9)
 except:
  z=socket.socket();z.connect((h,p));s('USER '+n+' 0 * :'+n);s('NICK '+n);s('JOIN '+c);s('PRIVMSG '+c+' :Hello, world!')