diff options
author | aashiks <aashiks@gmail.com> | 2009-04-30 18:01:29 +0530 |
---|---|---|
committer | aashiks <aashiks@gmail.com> | 2009-04-30 18:01:29 +0530 |
commit | 1cf818e1bb91ad9f9ab50ab7227dd64b72fcc9fc (patch) | |
tree | 6c2b3619c05c92824eca7f5427e012b8b2f9e4a7 /bots | |
parent | 560d36aa534a458eee1663e56bf600286c802c6d (diff) | |
download | AnjaliOldLipi.git-1cf818e1bb91ad9f9ab50ab7227dd64b72fcc9fc.tar.gz AnjaliOldLipi.git-1cf818e1bb91ad9f9ab50ab7227dd64b72fcc9fc.tar.xz AnjaliOldLipi.git-1cf818e1bb91ad9f9ab50ab7227dd64b72fcc9fc.zip |
Initial version of Mandoos - this does only logging.
usage --
python mandoos.py ircnetworkname nickname '#channel'
Diffstat (limited to 'bots')
-rw-r--r-- | bots/mandoos.py | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/bots/mandoos.py b/bots/mandoos.py new file mode 100644 index 0000000..772a5ff --- /dev/null +++ b/bots/mandoos.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +import socket +import sys +import datetime +import time + +#get stuff from command line +network = sys.argv[1] +port = 6667 +nick = sys.argv[2] +channel = sys.argv[3] + +#setup socket and connect to network +sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +sock.connect((network,port)) + +#send nick, user info to network +sock.send('NICK ' + nick + '\r\n') +sock.send('USER ' + nick + ' ' + nick + ' '+ nick + ' :' + 'localhost\r\n') + +#join channel +sock.send('JOIN ' + channel + '\r\n') + +currentdate = str(datetime.date.today()) +filename = currentdate + '-' + channel + '.log' +#Loop to keep listening +while True: + data = sock.recv(5120) + #check current date and if changed open new file + if currentdate != str(datetime.date.today()): + #close existing log + logfile.close() + + #update filename + currentdate = str(datetime.date.today()); + filename = currentdate + '-' + channel + '.log' + #open new log + logfile = open(filename ,'a') + + #check for PING from server and reply with PONG if found + if data.find('PING')!=-1 : + sock.send('PONG ' + data.split()[1] + '\r\n') + if data.find('PRIVMSG ' + channel) != -1: + logfile = open(filename,'a') + speaker = data.split('!')[0].replace(':','') + message = ''.join(data.split(':')[2:]) + logfile.write('<' + str(time.strftime("%H:%M:%S", time.localtime())) + '> ' + speaker + ' : ' + message) + logfile.close()
\ No newline at end of file |