[cvs-annodex] commit (/annodex): scripts/trunk/ircLogBot.py

conrad nobody at lists.annodex.net
Mon Feb 21 19:35:42 EST 2005


Update of /annodex (new revision 919)

Modified files:
   scripts/trunk/ircLogBot.py

Log Message:
format the irc log output as CMML, remove all other logging and privmsg
handling


Modified: scripts/trunk/ircLogBot.py
===================================================================
--- scripts/trunk/ircLogBot.py	2005-02-21 08:28:00 UTC (rev 918)
+++ scripts/trunk/ircLogBot.py	2005-02-21 08:35:40 UTC (rev 919)
@@ -50,14 +50,23 @@
     """
     def __init__(self, file):
         self.file = file
+        timestamp = self.gettimestamp()
+	self.file.write('<cmml>\n')
+	self.file.write('<stream timebase=\"%s\"/>\n' % timestamp)
+	self.file.write('<head/>\n')
 
+    def gettimestamp(self):
+        timestamp = time.strftime("clock:%Y%m%d%H%M%S", time.localtime(time.time()))
+	return timestamp
+
     def log(self, message):
         """Write a message to the file."""
-        timestamp = time.strftime("[%H:%M:%S]", time.localtime(time.time()))
-        self.file.write('%s %s\n' % (timestamp, message))
+        timestamp = self.gettimestamp()
+        self.file.write('<clip start=\"%s\"><desc>%s</desc></clip>\n' % (timestamp, message))
         self.file.flush()
 
     def close(self):
+	self.file.write('</cmml>\n')
         self.file.close()
 
 
@@ -65,18 +74,18 @@
     """A logging IRC bot."""
     
     def __init__(self):
-        self.nickname = "twistedbot"
+        self.nickname = "cmmlbot"
 
     def connectionMade(self):
         irc.IRCClient.connectionMade(self)
         self.logger = MessageLogger(open(self.factory.filename, "a"))
-        self.logger.log("[connected at %s]" % 
-                        time.asctime(time.localtime(time.time())))
+        #self.logger.log("[connected at %s]" % 
+        #                time.asctime(time.localtime(time.time())))
 
     def connectionLost(self, reason):
         irc.IRCClient.connectionLost(self, reason)
-        self.logger.log("[disconnected at %s]" % 
-                        time.asctime(time.localtime(time.time())))
+        #self.logger.log("[disconnected at %s]" % 
+        #                time.asctime(time.localtime(time.time())))
         self.logger.close()
 
 
@@ -93,12 +102,12 @@
     def privmsg(self, user, channel, msg):
         """This will get called when the bot receives a message."""
         user = user.split('!', 1)[0]
-        self.logger.log("<%s> %s" % (user, msg))
-        if msg.startswith("%s:" % self.nickname):
-            # someone is talking to me, lets respond:
-            msg = "%s: I am a log bot" % user
-            self.say(channel, msg)
-            self.logger.log("<%s> %s" % (self.nickname, msg))
+        self.logger.log("%s: %s" % (user, msg))
+        #if msg.startswith("%s:" % self.nickname):
+        #    # someone is talking to me, lets respond:
+        #    msg = "%s: I am a log bot" % user
+        #    self.say(channel, msg)
+        #    self.logger.log("<%s> %s" % (self.nickname, msg))
 
     def action(self, user, channel, msg):
         """This will get called when the bot sees someone do an action."""


-- 
conrad



More information about the cvs-annodex mailing list