summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoraashiks <aashiks@gmail.com>2009-04-30 18:01:29 +0530
committeraashiks <aashiks@gmail.com>2009-04-30 18:01:29 +0530
commit1cf818e1bb91ad9f9ab50ab7227dd64b72fcc9fc (patch)
tree6c2b3619c05c92824eca7f5427e012b8b2f9e4a7
parent560d36aa534a458eee1663e56bf600286c802c6d (diff)
downloadAnjaliOldLipi.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'
-rw-r--r--bots/mandoos.py48
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