Created
January 10, 2013 20:40
-
-
Save Nezzerath/4505594 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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