idk
This commit is contained in:
+71
-20
@@ -1,5 +1,6 @@
|
||||
(ns wiktlarp.main
|
||||
(:require [clojure.java.io :as io]
|
||||
[clojure.core.match :refer [match]]
|
||||
[cheshire.core :as json]
|
||||
[babashka.fs :as fs]
|
||||
[babashka.process :as p]
|
||||
@@ -10,6 +11,8 @@
|
||||
[hawk.core :as hawk]
|
||||
[next.jdbc :as sql]
|
||||
[integrant.core :as ig])
|
||||
(:import (java.time Instant Duration)
|
||||
(java.time.temporal ChronoUnit))
|
||||
(:gen-class))
|
||||
|
||||
(def chat-message-regexp #"(\*사망\* )?(.*?) : (.*)")
|
||||
@@ -18,13 +21,15 @@
|
||||
|
||||
(def ^:dynamic *db*)
|
||||
|
||||
(def cooldown 3)
|
||||
|
||||
(def last-sent (atom (.minusSeconds (Instant/now) 3)))
|
||||
|
||||
(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]
|
||||
@@ -32,11 +37,27 @@
|
||||
word])
|
||||
(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]
|
||||
(if-some [fuckyou (parse-fuckyou word)]
|
||||
fuckyou
|
||||
(->> word
|
||||
query-word
|
||||
(mapcat :senses)
|
||||
(mapcat (some-fn :raw_glosses :glosses))
|
||||
first)))
|
||||
|
||||
(defn etymology-word [word]
|
||||
(->> word
|
||||
query-word
|
||||
(mapcat :senses)
|
||||
(mapcat (some-fn :raw_glosses :glosses))
|
||||
(map :etymology_text)
|
||||
first))
|
||||
|
||||
(defn parse-chat-message [x]
|
||||
@@ -45,27 +66,54 @@
|
||||
{:author author :body body}))
|
||||
|
||||
(defn say [s]
|
||||
(->> s
|
||||
(take 128) ; truncate to 128 chars
|
||||
(apply str)
|
||||
(format "say \"%s\"")
|
||||
(rcon/exec *rcon*)))
|
||||
(let [now (Instant/now)]
|
||||
(when (< (compare (Duration/ofSeconds 3)
|
||||
(Duration/between @last-sent now))
|
||||
0)
|
||||
(reset! last-sent now)
|
||||
(->> s
|
||||
(take 128) ; truncate to 128 chars
|
||||
(apply str)
|
||||
(format "say \"%s\"")
|
||||
(rcon/exec *rcon*)))))
|
||||
|
||||
(defn find-word [s]
|
||||
(some-> (or (re-find #"\[\[([^]]+)]]" s)
|
||||
(re-find #"define\s+(\w+)" s))
|
||||
second))
|
||||
|
||||
(defn do-definition [s]
|
||||
(when-some [w (find-word s)]
|
||||
(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 find-etymology [s]
|
||||
(some-> (or (and (re-find #"ety(?:m(?:ology)?)?" s)
|
||||
(re-find #"\[\[([^]]+)]]" s))
|
||||
(re-find #"etymology of \s+(\w+)" s))
|
||||
second))
|
||||
|
||||
(defn parse-command [s]
|
||||
(if-let [x (find-etymology s)]
|
||||
[:etymology x]
|
||||
(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]
|
||||
(l/info "attempting rcon connection...")
|
||||
@@ -82,7 +130,10 @@
|
||||
(defn handle-console-event [s]
|
||||
(l/infof "! %s" 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*)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user