Skip to content
This repository has been archived by the owner on Apr 20, 2018. It is now read-only.

Commit

Permalink
Plugins will now receive a second param which is a vector of the mess…
Browse files Browse the repository at this point in the history
…age content.
  • Loading branch information
Jonathan Chauncey committed Jul 16, 2013
1 parent 3404f21 commit c6508d8
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 16 deletions.
4 changes: 2 additions & 2 deletions PLUGINS.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ Bot.addCommand("hello", "Simple Hello from Groovy", "Adam Esterline")
```

## Message -> String
When jarvis executes a plugin it only passes in 1 parameter and that is the enchanced message received from the flow.
When jarvis executes a plugin it passes in 2 parameters and that is the enchanced message received from the flow and a vector of the message content (double quoted strings will be parsed as 1 item in the vecotr).
All plugins must return a string that will be used as the content of the reply message.

```clojure
(defn my-awesome-plugin [message]
(defn my-awesome-plugin [message content-vector]
"my awesome reply")
```

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ See [INTRO](https://github.com/RallySoftware/jarvis-core/blob/master/INTRO.md) f
[org.codehaus.groovy/groovy-all "2.1.0"]
[org.clojure/java.classpath "0.2.0"]
[org.clojure/tools.logging "0.2.6"]
[org.clojure/tools.reader "0.7.5"]
[clj-http "0.7.2"]
[fs "1.3.2"]
[ch.qos.logback/logback-classic "1.0.9"]
Expand Down
3 changes: 2 additions & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject com.rallydev/jarvis-core "1.3.0"
(defproject com.rallydev/jarvis-core "1.4.0"
:description "A robot for FlowDock"
:url "http://github.com/RallySoftware/jarvis-core"
:license {:name "The MIT License (MIT)"
Expand All @@ -8,6 +8,7 @@
[org.codehaus.groovy/groovy-all "2.1.0"]
[org.clojure/java.classpath "0.2.0"]
[org.clojure/tools.logging "0.2.6"]
[org.clojure/tools.reader "0.7.5"]
[clj-http "0.7.2"]
[fs "1.3.2"]
[ch.qos.logback/logback-classic "1.0.9"]]
Expand Down
9 changes: 5 additions & 4 deletions src/main/clojure/jarvis/command.clj
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
(ns jarvis.command
(:require [clj-flowdock.api.message :as m]
(:require [jarvis.util :as util]
[clj-flowdock.api.message :as m]
[clojure.string :as s]
[clojure.tools.logging :as log]))

(declare get-user-id-from-message get-user-ids-from-tags user->id)

(defn tell [message plugin]
(when-let [reply (plugin message)]
(when-let [reply (plugin message (util/message-content->vec message))]
(let [user-ids (get-user-ids-from-tags message)]
(log/info "Plugin:" (m/content message) "replied:" (str "'" reply "'"))
(m/send-private-messages user-ids reply))))

(defn private-message [message plugin]
(when-let [reply (plugin message)]
(when-let [reply (plugin message (util/message-content->vec message))]
(let [user-id (get-user-id-from-message message)]
(log/info "Plugin:" (m/content message) "replied to user:" user-id " with content:" (str "'" reply "'"))
(m/send-private-message user-id reply))))

(defn reply [message plugin]
(when-let [reply (plugin message)]
(when-let [reply (plugin message (util/message-content->vec message))]
(log/info "Plugin:" (m/content message) "replied:" (str "'" reply "'"))
(m/reply message reply)))

Expand Down
2 changes: 1 addition & 1 deletion src/main/clojure/jarvis/plugins/help.clj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
sorted-plugin-meta (sort-by :command plugin-meta)
help-text (map #(str "\t" (:command %) ":\t" (:description %)) sorted-plugin-meta)]
(str
"\tAll known plugins\n"
"\n\tAll known plugins - \n"
(s/join "\n" help-text)
"\n\t~leave can be used to have me leave a flow. I will need to be invited back through the flowdock api to join again."
"\n\t~<command> can be used also in private-messages with me."
Expand Down
20 changes: 15 additions & 5 deletions src/main/clojure/jarvis/util.clj
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
(ns jarvis.util
(:require [jarvis.plugins :as plugins]
[jarvis.flowdock.debug :as debug]
[clj-flowdock.api.message :as m]
(:require [jarvis.flowdock.debug :as debug]
[clj-flowdock.api.flow :as f]
[clj-flowdock.api.message :as m]
[clj-flowdock.api.user :as user]
[clojure.string :as s]
[clojure.tools.logging :as log]))
[clojure.tools.logging :as log]
[clojure.tools.reader.edn :as edn]))

(defn- env-variable [name]
(-> (System/getenv)
(get name)))

(defn- build-string [content]
(str "[" content "]"))

(defn config-property
([name]
(config-property name nil))
Expand All @@ -31,4 +34,11 @@
(log/info (str "Closing flow connection - " (.flow-id flow-connection)))
(m/chat (.flow-id flow-connection) "Very well sir, goodbye.")
(f/block-user (.flow-id flow-connection) (get (user/me) "id"))
(.close flow-connection))
(.close flow-connection))

(defn message-content->vec [message]
(vec (map str (-> message
(get "content")
(subs 1)
build-string
(edn/read-string)))))
4 changes: 2 additions & 2 deletions src/test/clojure/jarvis/plugins/help_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
"happy")

(deftest help
(is (= (str "\tAll known plugins\n"
(is (= (str "\n\tAll known plugins - \n"
"\tbar:\tfoo"
"\n\t~leave can be used to have me leave a flow. I will need to be invited back through the flowdock api to join again."
"\n\t~<command> can be used also in private-messages with me."
"\n\t~~<command> @<name> will private message the people listed the results of the executed command."
"\n\tFor more details see https://github.com/RallySoftware/jarvis")
(help/help (test-util/message "~help") [#'test-plugin])))
(is (= (str "\tAll known plugins\n"
(is (= (str "\n\tAll known plugins - \n"
"\tbar:\tfoo\n"
"\tdawg:\tyo"
"\n\t~leave can be used to have me leave a flow. I will need to be invited back through the flowdock api to join again."
Expand Down
7 changes: 6 additions & 1 deletion src/test/clojure/jarvis/util_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@
(is (= (System/getenv "PWD") (util/config-property "PWD")))
(System/setProperty "some-foo-property" "some-foo-value")
(is (= "some-foo-value" (util/config-property "some-foo-property")))
(is (= "some-default-value" (util/config-property "some-property" "some-default-value"))))
(is (= "some-default-value" (util/config-property "some-property" "some-default-value"))))

(deftest message-content->vec
(is (= ["foo"] (util/message-content->vec {"content" "~foo"})))
(is (= ["foo" "bar"] (util/message-content->vec {"content" "~foo bar"})))
(is (= ["foo" "bar" "1"] (util/message-content->vec {"content" "~foo bar 1"}))))

0 comments on commit c6508d8

Please sign in to comment.