IRC bot

Someone Something fordhaivat at gmail.com
Sun Sep 13 16:43:48 EDT 2009


Thanks a lot!

On Sun, Sep 13, 2009 at 4:29 PM, MRAB <python at mrabarnett.plus.com> wrote:

> Someone Something wrote:
>
>> I"m trying to write an IRC bot just for fun (in python of course). Here's
>> my current code:
>>
>>  1 #!/usr/local/bin/python
>>  2 import time
>>  3 import socket
>>  4
>>  5 def message (x, channel,s):
>>  6     y="PRIVMSG"+" "+ channel+" :"+x
>>  7     s.send(y);
>>  8 host="irc.freenode.net <http://irc.freenode.net>";
>>  9 port=6667;
>>  10 size=1024;
>>  11 channel="#dhaivatrocks";
>>  12 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM);
>>  13 s.connect((host,port));
>>  14 s.send("NICK PoincareBot");
>>  15 s.send("USER  PoincareBot 8 *  : Paul Mutton");
>>  16 time.sleep(5);
>>  17 s.send("JOIN #dhaivatrocks");
>>  18 s.send(PRIVMSG #dhaivatrocks :Hello everybody!
>>  19 while True:
>>  20     pass;
>>  21
>> What I don't understand is that it doesn't display any messages or show a
>> new message login on my IRC client. What's wrong with my code?
>>
> You probably need to put some sort of line ending on what you send, eg
> "\n" or "\r\n". Also, it's better to use 'sendall' insetad of 'send'.
>
> BTW, you don't need to put a semicolon on the end of the lines.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090913/23bc5f97/attachment.html>


More information about the Python-list mailing list