Skip to content

Instantly share code, notes, and snippets.

@nathanic
Created November 29, 2012 16:11
Show Gist options
  • Save nathanic/4170057 to your computer and use it in GitHub Desktop.
Save nathanic/4170057 to your computer and use it in GitHub Desktop.
bitsbot feelings plugin
(ns lazybot.plugins.feelings
(:require [clojure.string :as string])
(:use [lazybot registry]
[somnium.congomongo :only [fetch fetch-one insert! destroy!]]))
; feelings.clj: a lazybot plugin to remember and report how people feel about various stuff
; TODO: parameterize prefix instead of literal '@', or don't bother?
(def love-responses
["Okay."
"Your @love has been noted."
"That's beautiful."
"I could never forget a @love like yours."
"All you need is @love."
"Spread the @love! Then, query the love with @feelings <person> or @feelings-about <thing>."
"Whole lotta @love!"
"@love don't come easy, you just have to wait (several milliseconds)."
])
(def hate-responses
["Sure."
"I'll bet you do."
"Your hatred is now inscribed on my hard drive for all time (or until the the disk fails)."
"Good, goooood... Let the @hate flow through you."
"Fear leads to anger, anger leads to hate, and @hate leads to a record in my database."
])
(def indifferent-responses
["Forgotten."
"Whatever, man."
"You've got to hide your @love away. Or @hate, I forgot which."
"I'm over it if you are."
"You've lost that lovin' feeling, or possibly that hatin' one."
])
(defn forget-feeling
[person thing]
(destroy! :feelings {:person person
:thing-lower (string/lower-case thing)}))
(comment ; repl interaction area
; see all feelings
(fetch :feelings)
; forget all feelings!
(destroy! :feelings {})
)
; TODO: make some indices? m'eh, probably not enough data to matter.
(defn save-feeling
[person feeling thing]
(let [thing-lower (string/lower-case thing)]
(destroy! :feelings {:person person
:feeling feeling ; allow love and hate for the same thing?
:thing-lower thing-lower})
(insert! :feelings {:person person
:feeling feeling
:thing thing
:thing-lower thing-lower ; for case-insensitive lookup
})))
(defn things-person-feels-about
"Search your feelings... You know it to be true."
[person feeling]
(seq (map :thing
(fetch :feelings
:where {:person person
:feeling feeling}))))
(defn people-who-feel-about-thing
[thing feeling]
(seq (map :person
(fetch :feelings
:where {:thing-lower (string/lower-case thing)
:feeling feeling}))))
(defn prefix-nick
[nick & stuff]
(apply str nick ": " stuff))
(defplugin
(:cmd
"profess your love for something. syntax: @love <something you love>"
#{"love"}
(fn [{:keys [nick args] :as com-m}]
(let [thing (string/join " " args)]
(save-feeling nick :love thing)
(send-message com-m (prefix-nick nick (rand-nth love-responses))))))
(:cmd
"express your hatred for something. syntax: @hate <something you hate>"
#{"hate"}
(fn [{:keys [nick args] :as com-m}]
(let [thing (string/join " " args)]
(save-feeling nick :hate thing)
(send-message com-m (prefix-nick nick (rand-nth hate-responses))))))
(:cmd
"destroy any trace of your feelings about something. syntax: @indifferent <something you no longer care about>"
#{"indifferent"}
(fn [{:keys [nick args] :as com-m}]
(let [thing (string/join " " args)]
(forget-feeling nick thing)
(send-message com-m (prefix-nick nick (rand-nth indifferent-responses))))))
(:cmd
"peer into someone's feelings. syntax: @feelings <person>"
#{"feelings"}
(fn [{:keys [nick args] :as com-m}]
(let [target-nick (or (first args) nick) ; default to the person saying it if no args
loves (things-person-feels-about target-nick :love)
hates (things-person-feels-about target-nick :hate) ]
(when loves
(send-message com-m
(str target-nick " loves: " (string/join ", " loves))))
(when hates
(send-message com-m
(str target-nick " hates: " (string/join ", " hates))))
(when-not (or loves hates)
(send-message com-m
(str "I am not aware of any feelings on the part of " target-nick "."))))))
(:cmd
"see who loves or hates a thing. syntax: @feelings-about <thing>"
#{"feelings-about" "feelingsabout"
"who-loves" "wholoves" "who-hates" "whohates"}
(fn [{:keys [args] :as com-m}]
(let [thing (string/join " " args)
lovers (people-who-feel-about-thing thing :love)
haters (people-who-feel-about-thing thing :hate) ]
(when lovers
(send-message com-m
(str thing " is loved by: " (string/join ", " lovers))))
(when haters
(send-message com-m
(str thing " is hated by: " (string/join ", " haters))))
(when-not (or lovers haters)
(send-message com-m
(str "Nobody has told me anything about " thing ", but I'm all ears."))))))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment