hawkeye -> hawk
This commit is contained in:
@@ -190,6 +190,16 @@
|
|||||||
"mvn-repo": "https://repo.clojars.org/",
|
"mvn-repo": "https://repo.clojars.org/",
|
||||||
"hash": "sha256-q4PzoWHUY53W2TZWihPpw+qXB4QWWVnS1iW3WlvIxFg="
|
"hash": "sha256-q4PzoWHUY53W2TZWihPpw+qXB4QWWVnS1iW3WlvIxFg="
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"mvn-path": "integrant/integrant/1.0.1/integrant-1.0.1.jar",
|
||||||
|
"mvn-repo": "https://repo.clojars.org/",
|
||||||
|
"hash": "sha256-dHxoCJNqPEcXakMdx6T89cQKH7ZQf9LmZtMO4fzr7f0="
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"mvn-path": "integrant/integrant/1.0.1/integrant-1.0.1.pom",
|
||||||
|
"mvn-repo": "https://repo.clojars.org/",
|
||||||
|
"hash": "sha256-zaEWby3a9q8gwevhNdchEwERgzbUG9NgqSBQ83C3Wdo="
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"mvn-path": "io/aleph/dirigiste/0.1.3/dirigiste-0.1.3.jar",
|
"mvn-path": "io/aleph/dirigiste/0.1.3/dirigiste-0.1.3.jar",
|
||||||
"mvn-repo": "https://repo1.maven.org/maven2/",
|
"mvn-repo": "https://repo1.maven.org/maven2/",
|
||||||
@@ -564,6 +574,16 @@
|
|||||||
"mvn-path": "tigris/tigris/0.1.2/tigris-0.1.2.pom",
|
"mvn-path": "tigris/tigris/0.1.2/tigris-0.1.2.pom",
|
||||||
"mvn-repo": "https://repo.clojars.org/",
|
"mvn-repo": "https://repo.clojars.org/",
|
||||||
"hash": "sha256-H9VZA1l1INzUrnbmoz7/XjWmFUIrutKo7ZrDMqr75KA="
|
"hash": "sha256-H9VZA1l1INzUrnbmoz7/XjWmFUIrutKo7ZrDMqr75KA="
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"mvn-path": "weavejester/dependency/1.0.0/dependency-1.0.0.jar",
|
||||||
|
"mvn-repo": "https://repo.clojars.org/",
|
||||||
|
"hash": "sha256-XxpuyFNiyj3VVUj25hocVNmbLc0vv9/EdIBK5m0TbpI="
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"mvn-path": "weavejester/dependency/1.0.0/dependency-1.0.0.pom",
|
||||||
|
"mvn-repo": "https://repo.clojars.org/",
|
||||||
|
"hash": "sha256-5NIafyzna3LBsVI8OHFubwOWmDYklwz18sPRfLp9WzY="
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,5 +10,6 @@
|
|||||||
hawk/hawk {:mvn/version "0.2.11"}
|
hawk/hawk {:mvn/version "0.2.11"}
|
||||||
ch.qos.logback/logback-classic #:mvn{:version "1.1.3"}
|
ch.qos.logback/logback-classic #:mvn{:version "1.1.3"}
|
||||||
io.github.anteoas/hawkeye
|
io.github.anteoas/hawkeye
|
||||||
{:git/sha "5b3f5a99e9edfe482174258a864b577f7a4eeb47"}}
|
{:git/sha "5b3f5a99e9edfe482174258a864b577f7a4eeb47"}
|
||||||
|
integrant/integrant {:mvn/version "1.0.1"}}
|
||||||
:paths ["src" "resources"]}
|
:paths ["src" "resources"]}
|
||||||
|
|||||||
Generated
+22
-1
@@ -128,7 +128,28 @@
|
|||||||
"root": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"clj-nix": "clj-nix",
|
"clj-nix": "clj-nix",
|
||||||
"nixpkgs": "nixpkgs_2"
|
"nixpkgs": "nixpkgs_2",
|
||||||
|
"sydpkgs": "sydpkgs"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"sydpkgs": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs": [
|
||||||
|
"nixpkgs"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1775943619,
|
||||||
|
"narHash": "sha256-UwowTI+MSA4SD+Oebxnj02vAou8GNjvZYrCQBwKe5q0=",
|
||||||
|
"ref": "refs/heads/main",
|
||||||
|
"rev": "e44c957573baa6a196e8de107cfc5bba31caf29a",
|
||||||
|
"revCount": 39,
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://git.deertopia.net/msyds/sydpkgs"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://git.deertopia.net/msyds/sydpkgs"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -2,6 +2,10 @@
|
|||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
||||||
clj-nix.url = "github:jlesquembre/clj-nix";
|
clj-nix.url = "github:jlesquembre/clj-nix";
|
||||||
|
sydpkgs = {
|
||||||
|
url = "git+https://git.deertopia.net/msyds/sydpkgs";
|
||||||
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = { self, nixpkgs, clj-nix, ... }@inputs:
|
outputs = { self, nixpkgs, clj-nix, ... }@inputs:
|
||||||
@@ -29,10 +33,12 @@
|
|||||||
|
|
||||||
packages = each-system ({ pkgs, ... }: {
|
packages = each-system ({ pkgs, ... }: {
|
||||||
default = pkgs.callPackage ./default.nix {};
|
default = pkgs.callPackage ./default.nix {};
|
||||||
|
make-db = pkgs.callPackage ./make-db {};
|
||||||
});
|
});
|
||||||
|
|
||||||
devShells = each-system ({ pkgs, system, ... }: {
|
devShells = each-system ({ pkgs, system, ... }: {
|
||||||
default = pkgs.mkShell {
|
default = pkgs.mkShell {
|
||||||
|
inputsFrom = [ self.packages.${system}.make-db ];
|
||||||
packages = with pkgs; [
|
packages = with pkgs; [
|
||||||
zprint
|
zprint
|
||||||
clojure
|
clojure
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
make-db
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
CFLAGS= \
|
||||||
|
-std=c99 \
|
||||||
|
-Wall \
|
||||||
|
-O3 \
|
||||||
|
-Wextra
|
||||||
|
LIBS=ncurses sqlite3
|
||||||
|
CFLAGS+=$(shell pkg-config --cflags $(LIBS))
|
||||||
|
LDFLAGS+=$(shell pkg-config --libs $(LIBS))
|
||||||
|
|
||||||
|
SOURCES=$(wildcard *.c)
|
||||||
|
EXECUTABLES=$(patsubst %.c,%,$(SOURCES))
|
||||||
|
|
||||||
|
all: $(EXECUTABLES)
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
{ stdenv
|
||||||
|
, sqlite
|
||||||
|
, ncurses
|
||||||
|
, pkg-config
|
||||||
|
, progressbar
|
||||||
|
}:
|
||||||
|
|
||||||
|
stdenv.mkDerivation {
|
||||||
|
pname = "make-db";
|
||||||
|
version = "0.0.0";
|
||||||
|
nativeBuildInputs = [
|
||||||
|
sqlite
|
||||||
|
ncurses
|
||||||
|
pkg-config
|
||||||
|
progressbar.dev
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sqlite3.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
const char *word_db_path = "../words.db";
|
||||||
|
const char *word_plaintext_path = "../words.gz";
|
||||||
|
|
||||||
|
char buf[2048] = "";
|
||||||
|
|
||||||
|
char *word = buf;
|
||||||
|
|
||||||
|
char *read_entry () {
|
||||||
|
const char *s = fgets (buf, 2048, stdin);
|
||||||
|
if (s == NULL) {
|
||||||
|
return NULL;
|
||||||
|
} else {
|
||||||
|
char *r = strchr (buf, '\t');
|
||||||
|
if (r != NULL) {
|
||||||
|
*r = '\0';
|
||||||
|
return r + 1;
|
||||||
|
} else {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main () {
|
||||||
|
if (access (word_db_path, F_OK)) {
|
||||||
|
remove (word_db_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
sqlite3 *db = NULL;
|
||||||
|
if (! sqlite3_open (word_db_path, &db) == SQLITE_OK) {
|
||||||
|
fprintf (stderr, "couldn't open sqlite: %s\n", sqlite3_errmsg (db));
|
||||||
|
} else {
|
||||||
|
fprintf (stderr, "sqlite open }:3\n");
|
||||||
|
char *s = read_entry ();
|
||||||
|
if (s == NULL) {
|
||||||
|
printf ("%s: %s\n", word, s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
{ stdenv
|
||||||
|
, ncurses
|
||||||
|
}:
|
||||||
|
|
||||||
|
stdenv.mkDerivation {}
|
||||||
+91
-33
@@ -2,10 +2,14 @@
|
|||||||
(:require [clojure.java.io :as io]
|
(:require [clojure.java.io :as io]
|
||||||
[babashka.fs :as fs]
|
[babashka.fs :as fs]
|
||||||
[babashka.process :as p]
|
[babashka.process :as p]
|
||||||
|
[progrock.core :as prog]
|
||||||
[clj-rcon.core :as rcon]
|
[clj-rcon.core :as rcon]
|
||||||
[clojure.tools.logging :as l]
|
[clojure.tools.logging :as l]
|
||||||
[clojure.string :as str]
|
[clojure.string :as str]
|
||||||
[hawkeye.core :as hawk])
|
[hawk.core :as hawk]
|
||||||
|
[next.jdbc :as sql]
|
||||||
|
[integrant.core :as ig])
|
||||||
|
(:import (java.util.zip GZIPInputStream))
|
||||||
(:gen-class))
|
(:gen-class))
|
||||||
|
|
||||||
(def log-file
|
(def log-file
|
||||||
@@ -15,29 +19,40 @@
|
|||||||
|
|
||||||
(def words-file "words.gz")
|
(def words-file "words.gz")
|
||||||
|
|
||||||
|
(def words-db-file "words.db")
|
||||||
|
|
||||||
(def ^:dynamic *rcon*)
|
(def ^:dynamic *rcon*)
|
||||||
|
|
||||||
|
(defn parse-plaintext-entry [s]
|
||||||
|
(when-some [[_ word gloss] (re-matches #"([^\t]*)\t(.*)\n?" s)]
|
||||||
|
[word gloss]))
|
||||||
|
|
||||||
|
(defn lookup-word-plaintext [word]
|
||||||
|
(let [r (p/shell {:out :string :continue true}
|
||||||
|
"zgrep" "-m1"
|
||||||
|
(format "^%s\t[^[:space:]]" word)
|
||||||
|
words-file)]
|
||||||
|
(when (zero? (:exit r))
|
||||||
|
(->> r
|
||||||
|
:out
|
||||||
|
str/split-lines
|
||||||
|
(map #(-> % parse-plaintext-entry second))
|
||||||
|
(filter #(not (empty? %))) ; remove nil and ""
|
||||||
|
first))))
|
||||||
|
|
||||||
|
(defn lookup-word-sql [word])
|
||||||
|
|
||||||
(defn lookup-word [word]
|
(defn lookup-word [word]
|
||||||
(->> (p/shell {:out :string}
|
(lookup-word-plaintext word))
|
||||||
"zgrep"
|
|
||||||
(format "^%s\t" word)
|
|
||||||
words-file)
|
|
||||||
:out
|
|
||||||
str/split-lines
|
|
||||||
(map #(nth (re-matches #"([^\t]*)\t(.*)\n?" %)
|
|
||||||
2 nil))
|
|
||||||
(filter #(not (empty? %))) ; remove nil and ""
|
|
||||||
first))
|
|
||||||
|
|
||||||
(defn parse-chat-message [x]
|
(defn parse-chat-message [x]
|
||||||
(when-let [[_ _dead? author body]
|
(when-let [[_ _dead? author body]
|
||||||
(re-matches #"(\*사망\* )?(.*?) : (.*)" x)]
|
(re-matches #"(\*사망\* )?(.*?) : (.*)" x)]
|
||||||
{:author author :body body}))
|
{:author author :body body}))
|
||||||
|
|
||||||
(defn say-word [word]
|
(defn say [s]
|
||||||
(->> (format "%s: %s" word (or (lookup-word word)
|
(->> s
|
||||||
"no entry found }:("))
|
(take 128) ; truncate to 128 chars
|
||||||
(take 128)
|
|
||||||
(apply str)
|
(apply str)
|
||||||
(format "say \"%s\"")
|
(format "say \"%s\"")
|
||||||
(rcon/exec *rcon*)))
|
(rcon/exec *rcon*)))
|
||||||
@@ -50,7 +65,13 @@
|
|||||||
(defn do-definition [s]
|
(defn do-definition [s]
|
||||||
(when-some [w (find-word s)]
|
(when-some [w (find-word s)]
|
||||||
(l/infof "looking up word: %s" w)
|
(l/infof "looking up word: %s" w)
|
||||||
(say-word w)))
|
(let [r (lookup-word w)]
|
||||||
|
(if r
|
||||||
|
(l/infof "found word! %s" r)
|
||||||
|
(l/infof "no entry... %s" w))
|
||||||
|
(Thread/sleep 750) ; avoid ratelimit lol
|
||||||
|
(say (format "%s: %s"
|
||||||
|
w (or r "no entry found (u_u)"))))))
|
||||||
|
|
||||||
(defn rcon-connect [host port password]
|
(defn rcon-connect [host port password]
|
||||||
(l/info "attempting rcon connection...")
|
(l/info "attempting rcon connection...")
|
||||||
@@ -87,23 +108,60 @@
|
|||||||
(finally (reset! prev-size size)))))
|
(finally (reset! prev-size size)))))
|
||||||
|
|
||||||
(defn start-watcher! []
|
(defn start-watcher! []
|
||||||
(hawk/watch (str (fs/parent log-file))
|
(l/infof "watching file %s" log-file)
|
||||||
(bound-fn* (fn [ev]
|
(hawk/watch! [{:paths [(str log-file)]
|
||||||
(when (= (str (fs/file-name log-file))
|
:handler
|
||||||
(:file ev))
|
(bound-fn*
|
||||||
(handler))))
|
(fn [_ctx ev]
|
||||||
(fn [e ctx]
|
(try (handler)
|
||||||
(l/error e "error in watcher"))))
|
(catch Exception e
|
||||||
|
(l/errorf e "exception in handler")
|
||||||
|
(throw e)))))}]))
|
||||||
|
|
||||||
(defn start-logger! []
|
|
||||||
@(rcon/exec *rcon* (format "con_logfile %s"
|
|
||||||
(fs/file-name log-file)))
|
(def config
|
||||||
@(rcon/exec *rcon* "echo \"wiktionary logging now\"")
|
{:rcon/connection {:ip "127.0.0.1"
|
||||||
(Thread/sleep 400)
|
:port 27015
|
||||||
(l/info "logfile has been set up!"))
|
:password "monitor"}
|
||||||
|
:console/watcher
|
||||||
|
{:log-file
|
||||||
|
(-> (str "~/.local/share/Steam/steamapps/common/Team Fortress 2/"
|
||||||
|
"tf/console.log")
|
||||||
|
fs/expand-home
|
||||||
|
fs/file)
|
||||||
|
:handler (ig/ref :wikilinker/handler)}
|
||||||
|
:wikilinker/handler {:rcon (ig/ref :rcon/connection)
|
||||||
|
:dictionary-file "words.gz"}})
|
||||||
|
|
||||||
|
|
||||||
|
(defmethod ig/init-key :rcon/connection [_ {:keys [ip port password]}]
|
||||||
|
(rcon-connect ip port password))
|
||||||
|
|
||||||
|
(defmethod ig/halt-key! :rcon/connection [_ conn]
|
||||||
|
(.close conn))
|
||||||
|
|
||||||
|
(defmethod ig/init-key :console/watcher [_ {:keys [log-file handler]}]
|
||||||
|
(hawk/watch! [{:paths [(str log-file)]
|
||||||
|
:handler
|
||||||
|
(fn [_ctx _ev]
|
||||||
|
(try (handler)
|
||||||
|
(catch Exception e
|
||||||
|
(l/errorf e "exception in handler")
|
||||||
|
(throw e))))}]))
|
||||||
|
|
||||||
|
(defmethod ig/halt-key! :console/watcher [_ watcher]
|
||||||
|
(hawk/stop! watcher))
|
||||||
|
|
||||||
|
(defmethod ig/init-key :wikilinker/handler [_ {:keys [rcon watcher]}]
|
||||||
|
(binding [*rcon* rcon]
|
||||||
|
(bound-fn [] (handler))))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(defn -main []
|
(defn -main []
|
||||||
(binding [*rcon* (rcon-connect "127.0.0.1" 27015 "monitor")]
|
(let [system (ig/init config)]
|
||||||
(start-logger!)
|
(.addShutdownHook (Runtime/getRuntime)
|
||||||
(start-watcher!)
|
(Thread. #(do (ig/halt! system)
|
||||||
(read-line)))
|
(binding [*out* *err*]
|
||||||
|
(println "shutting down")))))))
|
||||||
|
|||||||
Reference in New Issue
Block a user