This commit is contained in:
2026-08-07 09:54:27 -06:00
parent 72a8af7601
commit f0dc882945
3 changed files with 28 additions and 18 deletions
+2 -2
View File
@@ -19,9 +19,9 @@ let
# sqlite3 # sqlite3
# ]; # ];
in mkCljBin' { in mkCljBin' {
name = "wiktionary-tf2"; name = "wiktlarp";
version = "0.1.0"; version = "0.1.0";
projectSrc = lib.cleanSource ./.; projectSrc = lib.cleanSource ./.;
lockfile = ./deps-lock.json; lockfile = ./deps-lock.json;
main-ns = "wiktionary-tf2.main"; main-ns = "wiktlarp.main";
} }
+1 -1
View File
@@ -45,7 +45,7 @@
clojure clojure
babashka babashka
python3 python3
sqlite (sqlite.override { interactive = true; })
python314Packages.wiktextract python314Packages.wiktextract
sqlite-web sqlite-web
jq jq
@@ -1,4 +1,4 @@
(ns wiktionary-tf2.main (ns wiktlarp.main
(:require [clojure.java.io :as io] (:require [clojure.java.io :as io]
[cheshire.core :as json] [cheshire.core :as json]
[babashka.fs :as fs] [babashka.fs :as fs]
@@ -16,18 +16,21 @@
(def ^:dynamic *rcon*) (def ^:dynamic *rcon*)
(def ^:dynamic *dictionary-file*) (def ^:dynamic *db*)
(defn parse-plaintext-entry [s] (defmacro with-conn [[conn] & body]
(when-some [[_ word gloss] (re-matches #"([^\t]*)\t(.*)\n?" s)] `(let [ds# (sql/get-datasource
[word gloss])) {:dbtype "sqlite"
:dbname "db/words.db"})]
(with-open [~conn (sql/get-connection ds#)]
(sql/execute! ~conn ["select load_extension (?)"
(System/getenv "SPELLFIX")])
~@body)))
(defn query-word [word] (defn query-word [word]
(let [ds (sql/get-datasource {:dbtype "sqlite" :dbname "db/words.db"})] (->> (sql/execute! *db* ["select info from words where word = ?"
(with-open [conn (sql/get-connection ds)] word])
(->> (sql/execute! conn ["select info from words where word = ?" (map #(json/parse-string (:words/info %) keyword))))
word])
(map #(json/parse-string (:words/info %) keyword))))))
(defn gloss-word [word] (defn gloss-word [word]
(->> word (->> word
@@ -67,7 +70,7 @@
(defn rcon-connect [host port password] (defn rcon-connect [host port password]
(l/info "attempting rcon connection...") (l/info "attempting rcon connection...")
(or (try (let [c @(rcon/connect host port password)] (or (try (let [c @(rcon/connect host port password)]
@(rcon/exec c "echo \"WIKTIONARY CONNECTED!!!\"") @(rcon/exec c "echo \"wikilarper connected!\"")
(l/info "connected to rcon!") (l/info "connected to rcon!")
c) c)
(catch java.net.ConnectException e (catch java.net.ConnectException e
@@ -101,6 +104,8 @@
{:rcon/connection {:ip "127.0.0.1" {:rcon/connection {:ip "127.0.0.1"
:port 27015 :port 27015
:password "monitor"} :password "monitor"}
:database/connection {:dbtype "sqlite"
:dbname "db/words.db"}
:console/watcher :console/watcher
{:log-file {:log-file
(-> (str "~/.local/share/Steam/steamapps/common/Team Fortress 2/" (-> (str "~/.local/share/Steam/steamapps/common/Team Fortress 2/"
@@ -109,8 +114,7 @@
fs/file) fs/file)
:handler (ig/ref :wikilinker/handler)} :handler (ig/ref :wikilinker/handler)}
:wikilinker/handler {:rcon (ig/ref :rcon/connection) :wikilinker/handler {:rcon (ig/ref :rcon/connection)
:dictionary-file "words.gz"}}) :db (ig/ref :database/connection)}})
(defmethod ig/init-key :rcon/connection [_ {:keys [ip port password]}] (defmethod ig/init-key :rcon/connection [_ {:keys [ip port password]}]
(rcon-connect ip port password)) (rcon-connect ip port password))
@@ -118,6 +122,12 @@
(defmethod ig/halt-key! :rcon/connection [_ conn] (defmethod ig/halt-key! :rcon/connection [_ conn]
(.close conn)) (.close conn))
(defmethod ig/init-key :database/connection [_ dsinfo]
(sql/get-datasource dsinfo))
(defmethod ig/halt-key! :database/connection [_ conn]
(.close conn))
(defmethod ig/init-key :console/watcher [_ {:keys [log-file handler]}] (defmethod ig/init-key :console/watcher [_ {:keys [log-file handler]}]
(l/infof "watching file %s" log-file) (l/infof "watching file %s" log-file)
(hawk/watch! (hawk/watch!
@@ -136,9 +146,9 @@
(hawk/stop! watcher)) (hawk/stop! watcher))
(defmethod ig/init-key :wikilinker/handler (defmethod ig/init-key :wikilinker/handler
[_ {:keys [rcon dictionary-file]}] [_ {:keys [rcon db]}]
(binding [*rcon* rcon (binding [*rcon* rcon
*dictionary-file* dictionary-file] *db* db]
(bound-fn [log-file] (console-handler log-file)))) (bound-fn [log-file] (console-handler log-file))))