Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ pom.xml.asc
/.idea/*
marrano-bot.imlconfig.edn
db.edn
/.cpcache/
3 changes: 1 addition & 2 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ java -Dconfig="<path/to/config.edn>" -jar marrano-bot-0.1.0-SNAPSHOT-standalone.

** Options

``` edn
#+BEGIN_SRC edn
#+BEGIN_SRC clojure
{:webhook "https://bot.example.net"
:token "botABC:123467"}
#+END_SRC
Expand Down
4 changes: 4 additions & 0 deletions src/marrano_bot/db.clj
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,7 @@
(defn inc!
[& k]
(apply-in! k inc 1))

(defn inc-by!
[n & k]
(apply-in! k inc n))
25 changes: 25 additions & 0 deletions src/marrano_bot/grumpyness.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
(ns marrano-bot.grumpyness
(:require [marrano-bot.stats :refer [get-all-stats]]
[clojure.string :as string]))

(def score
[[-3 :russacchiotta :polacchina :potta]
[-2 :bell]
[-1 :amiga :commodore :retro :warez]
[1 :marrano :umme :mj]
[2 :umme :brutt]
[3 :bigdata :coin :chiesa]])

(defn calculate-thing-grumpyness
[thing]
(->>
(map #(if (.contains % thing) (first %) 0)
score)
(reduce + 0)))

(defn calculate-grumpyness
[phrase]
(->> phrase
(get-all-stats)
(map calculate-thing-grumpyness)
(reduce +)))
42 changes: 32 additions & 10 deletions src/marrano_bot/marrano.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
(:require [marrano-bot.parse :as p]
[marrano-bot.db :as db]
[marrano-bot.stats :refer [get-stats-from-phrase]]
[marrano-bot.grumpyness :refer [calculate-grumpyness]]
[morse.handlers :as h]
[morse.api :as t]
[muuntaja.core :as m]
Expand Down Expand Up @@ -74,6 +75,7 @@


;; Photo
;;


(defn ricorda-photo
Expand All @@ -91,6 +93,7 @@
#(= (:photo_id %) photo)))

;; Help message
;;
(defn- paris-help
[]
(let [list (->> (keys (db/get-in! [:commands]))
Expand All @@ -99,7 +102,8 @@
(apply str))]
(str "Helpy *paris*:\n\n" list)))

;; links
;; Link
;;
(defn- as-json
[data]
(->> data
Expand Down Expand Up @@ -136,23 +140,34 @@
:text "🖕 LMGIFY"}]
results)))))

;; Grumpyness
;;
(defn update-grumpyness
[username text]
(when (and username text)
(let [grumpyness (calculate-grumpyness text)]
(db/inc-by! grumpyness :grumpyness username))))

(defn get-grumpyness
[]
(->> (db/get-in! [:grumpyness])
(sort-by second)
(map #(str "- _" (first %) "_ *" (second %) "*"))
(s/join "\n")))

;; Stats
;;
(defn update-stats
[text]
"increments stats based on spoken words"
(loop [stats (seq (get-stats-from-phrase text))]
(when (first stats)
(debug "stats:" stats)
(db/inc! :stats (first stats)))
(when (next stats)
(recur (next stats)))))
(doseq [stat (get-stats-from-phrase text)]
(db/inc! :stats stat)))

(defn get-stats
[]
(->> (db/get-in! [:stats])
(sort-by second)
(map #(str "- `" (first %) "` :: *" (second %) "*"))
(map #(str "- _" (first %) "_ *" (second %) "*"))
(s/join "\n")))

(defn prometheus-metrics
Expand Down Expand Up @@ -181,9 +196,10 @@
parts))

(defn bot-api
[{{id :id chat-type :type} :chat caption :caption photo :photo text :text}]
[{{username :username} :from {id :id chat-type :type} :chat caption :caption photo :photo text :text}]
(when text
(update-stats text))
(do (update-stats text)
(update-grumpyness username text)))
(let [caption (or caption "")
text (or text "")]
(cond (s/starts-with? text "/paris")
Expand Down Expand Up @@ -229,6 +245,12 @@
(send-message {:chat_id id
:text (get-stats)})
;;
;; Grumpyness
;;
(and text (s/starts-with? text "/grumpy"))
(send-message {:chat_id id
:text (get-grumpyness)})
;;
;; /ricorda
;;
(s/starts-with? text "/ricorda")
Expand Down
39 changes: 24 additions & 15 deletions src/marrano_bot/stats.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,23 @@
(def stat-words
[[:russacchiotta "russa" "russacchiotta"]
[:polacchina "pupy" "pupa" "poska" "polacchina"]
[:potta "figa" "potta" "signorina" "tette" "pheega"]
[:aliemmo "aliemmo" "aliem" "lorenzo" "lallini" "lallo"]
[:gatto "grumpycat" "gatto" "gattino" "bibbiano"]
[:lukke "lukke" "luca" "bertolovski"]
[:suppah "suppah" "supphppa" "suppahsrv" "munne"]
[:gatto "grumpycat" "gatto" "gattino" "bibbiano"]
[:aliemmo "aliemmo" "aliem" "lorenzo" "lallini"]
[:marrano "marran" "marrans" "marrani" "mrrny"]
[:amiga "amiga" "vampire" "cd32" "a1200" "a600" "acceleratore" "blitter" "aga" "terriblefire" "tf330" "tf530" "warp"]
[:amiga "amiga" "vampire" "cd32" "a1200" "a600" "acceleratore" "blitter" "terriblefire" "tf330" "tf530" "warp"]
[:commodore "commodore" "c64" "vic20"]
[:retro "spectrum" "speccy" "coleco" "atari" "falcon"]
[:warez "warez" "crack" "key" "chiave"]
[:bigdata "mongo" "elasticsearch" "elastic" "bigdata"]
[:coin "bitcoin" "litecoin" "coin" "musk" "elon" "elon musk" "speculazione"]
[:umme "umme" "ummme" "ummmeee" "umm3"]
[:potta "figa" "potta" "signorina" "tette"]
[:bigdata "mongo" "elasticsearch" "elastic" "bigdata"]])
[:chiesa "dio" "papa" "chiesa" "religione" "porco"]
[:mj "lsd" "mj" "marjuana" "erba" "pianta" "piantina"]
[:marrano "marran" "marrans" "marrani" "mrrny"]
[:brutt "grumpy" "grumpizza" "ummatore" "cattiv" "biden" "trump" "putin" "puteen" "moo" "pastoso" "lento" "manno" "mannosu" "brutto"]
[:bell "brav" "bella" "ciccia" "pizza" "pasta" "vodka" "essi" "essisu" "massisu"]])

(defn calculate-distance
[w1 w2]
Expand All @@ -31,15 +37,18 @@
0 words))

(defn calculate-rank
[phrase words]
(->> (string/split phrase #"\s+")
(map #(calculate-rank-word % words))
(apply max)))
[word words]
(->> words
(map #(calculate-rank-word word %))))

(defn get-stats-from-phrase
[phrase]
[word]
(->> stat-words
(filterv #(< 0.4 (calculate-rank phrase
(rest %))))
(map first)
(reduce conj #{})))
(filterv #(< 0.6 (calculate-rank-word word (rest %))))
(map first)))

(defn get-all-stats
[phrase]
(let [words (string/split phrase #"\s+")]
(->> words
(mapcat get-stats-from-phrase))))