Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Copyright 2014 Usmar Padow (amigojapan) usmpadow@gmail.com
- import socket
- import string
- import time
- from random import randint
- #Configuration
- HOST="irc.dal.net"
- PORT=6667
- NICK="DataBot"
- PASS="enterprise"
- IDENT="DataBot"
- REALNAME="DataBot"
- CHAN="#depression"
- ECHO=True
- TIMEOUT=200
- #DELAY_FOR_MOTD=30#this is the delay that I estimate may take for MOTD to come out( quick and dirty fix, fix later)
- readbuffer=""
- def IRCconnect(s):
- s.settimeout(TIMEOUT)#this value seems to be in seconds
- s.connect((HOST, PORT))
- ##join with a random nickname, release the real nick then identify
- RANDNICK="RANDNICK"+str(randint(100,1000))
- s.send("PASS testpassword\r\n")
- s.send("NICK %s\r\n" % RANDNICK)
- s.send("USER %s %s bla :%s\r\n" % (IDENT, HOST, REALNAME))
- #print "Delaying "+str(DELAY_FOR_MOTD)+" Seconds in hope MOTD has gone by"
- #time.sleep(DELAY_FOR_MOTD)
- s.send("PRIVMSG NickServ@services.dal.net :RELEASE "+NICK+" "+PASS+"\r\n")
- s.send("NICK "+NICK+"\r\n")
- s.send("PRIVMSG NickServ@services.dal.net :IDENTIFY "+PASS+"\r\n")
- s.send("JOIN :%s\r\n" % CHAN)
- s.send("PRIVMSG %s :%s\r\n" % (CHAN, "bot activated"))
- s=socket.socket( )
- IRCconnect(s)
- while 1:
- try:
- readbuffer=readbuffer+s.recv(1024)
- if ECHO:
- print readbuffer
- temp=string.split(readbuffer, "\n")
- readbuffer=temp.pop( )
- #put all parameters after the commands in the params variable and command in command variable
- for line in temp:
- line=string.rstrip(line)
- line=string.split(line)
- if len(line)>3:
- command= line[3][1:len(line[3])]
- params=""
- for a in range(4, len(line)):
- params=params+line[a]+" "
- params=params[:-1]#strip the extra space
- #Bot commands
- #if command=="!say":
- # s.send("PRIVMSG %s :%s\r\n" % (CHAN, params))
- if command=="!help":
- s.send("PRIVMSG %s :%s\r\n" % (CHAN, "Sorry, help is not available"))
- command=""
- if(line[0]=="PING"):
- s.send("PONG %s\r\n" % line[1])
- except socket.timeout:
- s.shutdown(socket.SHUT_RDWR)
- s=socket.socket( )
- print "Connection timed out, reconnecting..."
- IRCconnect(s)
- except socket.error:
- s.shutdown(socket.SHUT_RDWR)
- s=socket.socket( )
- print "Connection reset by peer, reconnecting..."
- IRCconnect(s)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement