Skip to content

Instantly share code, notes, and snippets.

@Nezzerath
Created January 10, 2013 20:40
Show Gist options
  • Save Nezzerath/4505594 to your computer and use it in GitHub Desktop.
Save Nezzerath/4505594 to your computer and use it in GitHub Desktop.
import sys, socket, string, os, threading, time, random
from os import system
windowtitle = "IRC Bot"
system("title "+windowtitle)
host = raw_input("Hostname: ")
nickname = raw_input("Nickname: ")
password = raw_input("Password: ")
channel = raw_input("Channel: ")
PORT = 6667
realname = nickname
ident = nickname
s=socket.socket( )
def connect(host, PORT, nickname, ident, realname, password, channel):
s.connect((host, PORT))
s.send("NICK %s\r\n" % nickname)
s.send("USER %s %s bla :%s\r\n" % (ident, host, realname))
s.send("nickserv IDENTIFY %s\r\n" % password)
s.send("JOIN :%s\r\n" % channel)
connect(host, PORT, nickname, ident, realname, password, channel) #calls a function
def commands(msgparts):
if nickname.lower() in msgparts[4]:
if "hello" in msgparts[4]:
s.send("PRIVMSG %s :%s\r\n" % (channel, "Hello" + " " + name))
if "disconnect" in msgparts[4]:
sys.exit()
def parse(msg):
global msgparts
msgparts = []
try:
msgparts = [
msg.split( ":" )[ 1 ].split( "!" )[ 0 ], #nick
msg.split( "!" )[ 1 ].split( "@" )[ 0 ], #user
msg.split( " " )[ 0 ].split( "@" )[ 1 ], #host
msg.split( " " )[ 2 ], #Channel, Message
":".join( msg.split( ":" )[ 2: ] ), True ] # Channel or PM
if not msgparts[ 3 ][ 0 ] == "#":
msgparts[ 5 ] = False
return msgparts
except Exception, Error: print "Error: %s" % ( Error )
while True:
time.sleep(5)
data = s.recv(4096)
data = data.lower()
print data
if data.find ( 'ping' ) != -1:
s.send ( 'PONG ' + data.split() [ 1 ] + '\r\n' )
if not data.find( "privmsg" ) == -1:
parse(data)#calls a function
commands(msgparts)#calls a function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment