idk
This commit is contained in:
+71
-20
@@ -1,5 +1,6 @@
|
|||||||
(ns wiktlarp.main
|
(ns wiktlarp.main
|
||||||
(:require [clojure.java.io :as io]
|
(:require [clojure.java.io :as io]
|
||||||
|
[clojure.core.match :refer [match]]
|
||||||
[cheshire.core :as json]
|
[cheshire.core :as json]
|
||||||
[babashka.fs :as fs]
|
[babashka.fs :as fs]
|
||||||
[babashka.process :as p]
|
[babashka.process :as p]
|
||||||
@@ -10,6 +11,8 @@
|
|||||||
[hawk.core :as hawk]
|
[hawk.core :as hawk]
|
||||||
[next.jdbc :as sql]
|
[next.jdbc :as sql]
|
||||||
[integrant.core :as ig])
|
[integrant.core :as ig])
|
||||||
|
(:import (java.time Instant Duration)
|
||||||
|
(java.time.temporal ChronoUnit))
|
||||||
(:gen-class))
|
(:gen-class))
|
||||||
|
|
||||||
(def chat-message-regexp #"(\*사망\* )?(.*?) : (.*)")
|
(def chat-message-regexp #"(\*사망\* )?(.*?) : (.*)")
|
||||||
@@ -18,13 +21,15 @@
|
|||||||
|
|
||||||
(def ^:dynamic *db*)
|
(def ^:dynamic *db*)
|
||||||
|
|
||||||
|
(def cooldown 3)
|
||||||
|
|
||||||
|
(def last-sent (atom (.minusSeconds (Instant/now) 3)))
|
||||||
|
|
||||||
(defmacro with-conn [[conn] & body]
|
(defmacro with-conn [[conn] & body]
|
||||||
`(let [ds# (sql/get-datasource
|
`(let [ds# (sql/get-datasource
|
||||||
{:dbtype "sqlite"
|
{:dbtype "sqlite"
|
||||||
:dbname "db/words.db"})]
|
:dbname "db/words.db"})]
|
||||||
(with-open [~conn (sql/get-connection ds#)]
|
(with-open [~conn (sql/get-connection ds#)]
|
||||||
(sql/execute! ~conn ["select load_extension (?)"
|
|
||||||
(System/getenv "SPELLFIX")])
|
|
||||||
~@body)))
|
~@body)))
|
||||||
|
|
||||||
(defn query-word [word]
|
(defn query-word [word]
|
||||||
@@ -32,11 +37,27 @@
|
|||||||
word])
|
word])
|
||||||
(map #(json/parse-string (:words/info %) keyword))))
|
(map #(json/parse-string (:words/info %) keyword))))
|
||||||
|
|
||||||
|
(defn parse-fuckyou [x]
|
||||||
|
(cond (= x "peggle")
|
||||||
|
"(slang, Tiny Kitty Girl Pound) a video game, i think. idfk."
|
||||||
|
(and (re-find #"chimpanzee" x)
|
||||||
|
(re-find #"segway" x))
|
||||||
|
"(slang, Tiny Kitty Girl Pound) chimpanzeee sirdnway"
|
||||||
|
:else nil))
|
||||||
|
|
||||||
(defn gloss-word [word]
|
(defn gloss-word [word]
|
||||||
|
(if-some [fuckyou (parse-fuckyou word)]
|
||||||
|
fuckyou
|
||||||
|
(->> word
|
||||||
|
query-word
|
||||||
|
(mapcat :senses)
|
||||||
|
(mapcat (some-fn :raw_glosses :glosses))
|
||||||
|
first)))
|
||||||
|
|
||||||
|
(defn etymology-word [word]
|
||||||
(->> word
|
(->> word
|
||||||
query-word
|
query-word
|
||||||
(mapcat :senses)
|
(map :etymology_text)
|
||||||
(mapcat (some-fn :raw_glosses :glosses))
|
|
||||||
first))
|
first))
|
||||||
|
|
||||||
(defn parse-chat-message [x]
|
(defn parse-chat-message [x]
|
||||||
@@ -45,27 +66,54 @@
|
|||||||
{:author author :body body}))
|
{:author author :body body}))
|
||||||
|
|
||||||
(defn say [s]
|
(defn say [s]
|
||||||
(->> s
|
(let [now (Instant/now)]
|
||||||
(take 128) ; truncate to 128 chars
|
(when (< (compare (Duration/ofSeconds 3)
|
||||||
(apply str)
|
(Duration/between @last-sent now))
|
||||||
(format "say \"%s\"")
|
0)
|
||||||
(rcon/exec *rcon*)))
|
(reset! last-sent now)
|
||||||
|
(->> s
|
||||||
|
(take 128) ; truncate to 128 chars
|
||||||
|
(apply str)
|
||||||
|
(format "say \"%s\"")
|
||||||
|
(rcon/exec *rcon*)))))
|
||||||
|
|
||||||
(defn find-word [s]
|
(defn find-word [s]
|
||||||
(some-> (or (re-find #"\[\[([^]]+)]]" s)
|
(some-> (or (re-find #"\[\[([^]]+)]]" s)
|
||||||
(re-find #"define\s+(\w+)" s))
|
(re-find #"define\s+(\w+)" s))
|
||||||
second))
|
second))
|
||||||
|
|
||||||
(defn do-definition [s]
|
(defn find-etymology [s]
|
||||||
(when-some [w (find-word s)]
|
(some-> (or (and (re-find #"ety(?:m(?:ology)?)?" s)
|
||||||
(l/infof "looking up word: %s" w)
|
(re-find #"\[\[([^]]+)]]" s))
|
||||||
(let [r (gloss-word w)]
|
(re-find #"etymology of \s+(\w+)" s))
|
||||||
(if r
|
second))
|
||||||
(l/infof "found word! %s" r)
|
|
||||||
(l/infof "no entry... %s" w))
|
(defn parse-command [s]
|
||||||
(Thread/sleep 750) ; avoid ratelimit lol
|
(if-let [x (find-etymology s)]
|
||||||
(say (format "%s: %s"
|
[:etymology x]
|
||||||
w (or r "no entry found (u_u)"))))))
|
(if-let [x (find-word s)]
|
||||||
|
[:define x]
|
||||||
|
nil)))
|
||||||
|
|
||||||
|
(defn do-definition [w]
|
||||||
|
(l/infof "looking up word: %s" w)
|
||||||
|
(let [r (gloss-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 do-etymology [w]
|
||||||
|
(l/infof "looking up word: %s" w)
|
||||||
|
(let [r (etymology-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...")
|
||||||
@@ -82,7 +130,10 @@
|
|||||||
(defn handle-console-event [s]
|
(defn handle-console-event [s]
|
||||||
(l/infof "! %s" s)
|
(l/infof "! %s" s)
|
||||||
(when-let [{:keys [author body]} (parse-chat-message s)]
|
(when-let [{:keys [author body]} (parse-chat-message s)]
|
||||||
(do-definition body)))
|
(match (parse-command s)
|
||||||
|
[:define x] (do-definition x)
|
||||||
|
[:etymology x] (do-etymology x)
|
||||||
|
:else nil)))
|
||||||
|
|
||||||
(def ^:dynamic *prev-size*)
|
(def ^:dynamic *prev-size*)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user