]> gitweb.factorcode.org Git - factor.git/commitdiff
irc.logbot: fix up logbot to allow more custom configuration.
authorDoug Coleman <doug.coleman@gmail.com>
Sun, 8 May 2016 19:17:30 +0000 (12:17 -0700)
committerDoug Coleman <doug.coleman@gmail.com>
Sun, 8 May 2016 19:20:05 +0000 (12:20 -0700)
extra/irc/logbot/logbot.factor

index 0bc4d71707c3aa9084a2fda6ac5d6d5fc5d718dc..069a54524cbfcb053475b080f99ae2c1eeb28e7b 100644 (file)
@@ -1,30 +1,44 @@
 ! Copyright (C) 2009 Bruno Deferrari.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors calendar calendar.format destructors fry io io.encodings.8-bit
-io.files io.pathnames irc.client irc.client.chats irc.messages
-irc.messages.base kernel make namespaces sequences threads
-irc.logbot.log-line io.encodings.8-bit.latin1 ;
+USING: accessors calendar calendar.format destructors fry io
+io.directories io.encodings.utf8 io.files io.pathnames
+irc.client irc.client.chats irc.logbot.log-line splitting
+irc.messages.base kernel make namespaces sequences threads ;
 IN: irc.logbot
 
 CONSTANT: bot-channel "#concatenative"
-CONSTANT: log-directory "/tmp/logs"
+CONSTANT: default-log-directory "resource:logs/irc"
+CONSTANT: default-nickserv-handle "flogbot2"
+
+SYMBOL: ircbot-log-directory
+SYMBOL: nickserv-handle
+SYMBOL: nickserv-password
 
 SYMBOL: current-day
 SYMBOL: current-stream
 
 : bot-profile ( -- obj )
-    "irc.freenode.org" 6667 "flogger" f <irc-profile> ;
+    "irc.freenode.org" 6667
+    nickserv-handle get default-nickserv-handle or
+    nickserv-password get <irc-profile> ;
 
 : add-timestamp ( string timestamp -- string )
     timestamp>hms [ "[" % % "] " % % ] "" make ;
 
+: make-log-path ( -- path )
+    ircbot-log-directory get default-log-directory or
+    bot-channel "#" ?head drop
+    append-path ;
+
 : timestamp-path ( timestamp -- path )
-    timestamp>ymd ".log" append log-directory prepend-path ;
+    timestamp>ymd ".log" append
+    make-log-path dup make-directories
+    prepend-path ;
 
 : update-current-stream ( timestamp -- )
     current-stream get [ dispose ] when*
     [ day-of-year current-day set ]
-    [ timestamp-path latin1 <file-appender> ] bi
+    [ timestamp-path utf8 <file-appender> ] bi
     current-stream set ;
 
 : same-day? ( timestamp -- ? ) day-of-year current-day get = ;