[Tutor] How to interact with users on IRC using Python

Samuel Toogood sam at pognet.org.uk
Mon Apr 16 19:07:30 CEST 2012


On 16/04/12 16:11, Surya K wrote:
> Actually, I am writing a small IRC bot for a game (A Multiplayer one). 
> 
> 
> This how my code looks. (I this code, I am just trying to read from IRC
> client and send a message to it..)
> 
>         import sys
> 
>         import socket
> 
>         import string
> 
> 
>         HOST="irc.freenode.net"
> 
>         PORT=6667
> 
>         NICK="MyBot"
> 
>         IDENT="Mybot"
> 
>         REALNAME="Python"
> 
>         readbuffer=""
> 
> 
>         s=socket.socket( )
> 
>         s.connect((HOST, PORT))
> 
>         s.send("NICK %s\r\n" % NICK)
> 
>         s.send("USER %s %s bla :%s\r\n" % (IDENT, HOST, REALNAME))
> 
>         s.send("JOIN ##MyChannel\n")
> 
> 
>         while 1:
> 
>             readbuffer=readbuffer+s.recv(1024)
> 
>             print readbuffer
> 
>             s.send("text:")
> 
>             .... # MY Code goes like this.
> 
> 
> Actually, I am not even aware of IRC commands.. so I thought to take
> some help to carry on
> 
> 
> This is what I require:
> 
> As my game is quite simple, I just need to transfer a small string from
> each player to another.
> 
> My game will have a two players.. so, Each user will join my
> ##myExampleChannel.
> Say, a player (or a IRC user) "p1" wants to play with "p2". They simply
> have to exchange private messages from each other.
> 
> So, what IRC commands should I use and how do I typically implement them?
> 
> 
> Let me put the above this way:
> 
> How do I create a small IRC program which can send and receive private
> messages from users?
> 
> 
> 
> Thanks for reading! Hope you help me.

Does http://www.devshed.com/c/a/Python/Python-and-IRC/ help at all?

Kind regards,

Sam


More information about the Tutor mailing list