I Am trying to make a very simple irc bot in python, but can’t figure out how to do that with sockets.
The only thing i want it to is: Connect to irc server, set nick (and name), join a channel, and write a message to the irc channel.
Anyone who can lead me in the right direction or small example of code?
import socket
name = raw_input("Enter your name: ")
nick = raw_input("IRC Handle: ")
irc_serv = "irc.freenode.net"
port = 6667
conn = socket.socket()
conn.connect((irc_serv, port))
conn.send("NICK "), nick
conn.send("NAME "), nick
conn.send("JOIN #king")
conn.send("PRIVMSG #king test message")
I Run it, enters name and nick, but it doesnt join the channel (checking with xchat connected to the channel)
As J. Steen pointed out, your question is too broad for this site and there is no single answer.
Here is some starters advice :
You are using python. Python has a lot of libraries made to help you with a lot of stuff. First try to find out if what you require is already done by some one. Don’t reinvent the wheel.
In your case I can point you to the Twisted which has a implementation of the IRC protocol. Twisted is a well written, well maintained, modular and asynchronous framework and I would suggest you use it.
Here is the Twisted IRC Client API Docmentation.
Here is an example IRC bot implemented with twised. You can look into it to start out.
It seems you are starting out so I helped out, but next time you can try google. This site generally doesn’t support spoon feeding and user are advised to try stuff on there own before asking for help, this leads to better learning.
Best of luck for you project.
PS : This question might already have been asked and answered here, all the more reason you should search first.