     (.substring str 0 max)
     str))
 
-(defn handle-xlogfile-line [irc line]
+(defn handle-xlogfile-line [irc file line]
   (sql/with-connection db
     (sql/transaction
-     (insert-xlogfile-line-db line)))
-  (let [data (parse-line line)]
+     (insert-xlogfile-line-db (region-from-fn file) line)))
+  (let [data (assoc (parse-line line) :region (region-from-fn file))]
     (if (and (or (< (Integer/parseInt (:turns data)) 10)
                  (< (Integer/parseInt (:points data)) 10))
              (or (= (:death data) "quit")

                    (if (not (or (= achieve-diff 0)
                                 (= achieve-diff 0x200)
                                 (= achieve-diff 0x400)))
                      (parse-bitfield achievements achieve-diff)))

    (str "unhandled line: " data)))

(defn handle-livelog-line [irc line]
  (let [data (parse-line line)]
    (if (not (is-scum (:player data)))
      (let [out (make-livelog-out data)]
        (if out

  (let [bitfield (if (integer? bitfield)
                   bitfield
                   (bitfield-to-int bitfield))]
    (filter string?
            (map (fn [idx]
                   (if (bit-test bitfield idx)
                     (nth values idx)
                     nil))
                 (range (count values))))))

(defn make-livelog-out [data]
  (condp #(contains? %2 %1) data
