S(c)htick


Welcome. Have a Nice Time at S(c)htick


Connecting to an IRC Server in Python


Step 1


Importing the right modules


import socket

import sys


Step 2


Connecting To Server


server = "chat.freenode.net"

channel = "#kmakandraven"

botnick = "bot1"

irc = socket.socket(socke
t.AF_INET, socket
.SOCK_STREAM)

print "connecting to:"+server

irc.connect((server, 6667))

irc.send("USER "+ botnick +" "+ botnick +" "+ botnick +" :This is a fun bot!\n")

irc.send("NICK "+ botnick +"\n")

irc.send("PRIVMSG nickserv :iNOOPE\r\n")

irc.send("JOIN "+ channel +"\n")


Step 3


Commands/Reading Lines

while 1:

text=irc.recv(2040)

print text

if text.find(':!hi') !=-1:

t = text.split(':!hi')

to = t[1].strip()

irc.send('PRIVMSG '+channel+' :Hello '+str(to)+'! \r\n')