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