Skip to content

Commit

Permalink
Update README + minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
vbauer committed Mar 9, 2015
1 parent 19d4a05 commit ca6c029
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 14 deletions.
32 changes: 26 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ Default configuration is stored in project resources (config.edn) in [EDN format
:password "Fill me up!"
:host "Fill me up!"
:domain "Fill me up!"}
:watchdog {:folder "scripts"
:delay 1000}}
:scripts {:folder "scripts"
:watchdog 1000}}
```

Before using, it is necessary to configure the following parameters:
Expand All @@ -35,8 +35,8 @@ All parameters from this file override default config parameters.
## Development

To develop Jabber command, you need to create Clojure file in the script `:folder`.
When `:delay` parameter is defined, then FS watchdog will check changes and reload scripts in runtime.
It could be useful in development mode, but you can switch if off in production mode (using `:delay` equals 0).
When `:watchdog` parameter is defined, then FS watchdog will check changes and reload scripts in runtime echo *N* milliseconds.
It could be useful in development mode, but you can switch if off in production mode (using `:watchdog` equals 0).

It is necessary to follow several rules during Jabber command development:

Expand All @@ -47,16 +47,36 @@ It is necessary to follow several rules during Jabber command development:
* Result of the last function is the answer message, it will be sent to user.


### Script context

Each script receives context parameters, for example:

```clojure
{:subject nil
:from "bauer.vlad@gmail.com/gmail.3167A379"
:to "jabberjay@gmail.com"
:thread nil
:error nil
:packet-id "5A19D18217BBD43_1"
:type :chat
:from-name "bauer.vlad@gmail.com"
:body "Hi Bot"
:text "Bot"}
```


### Example

This simple command always returns "Hello!", when client sends "Hi" ("HI", "hi", "hI"):
This simple command always returns "Hello, <your jabber account>", when client sends "Hi" ("HI", "hi", "hI"):

```clojure
(ns hi)

(defn init
"Simple module for greating"
[msg] "Hello!")
[data]
(str "Hello, " (or (:from-name data)
(:from data))))
```

Another example: [scripts/weather.clj](scripts/weather.clj).
Expand Down
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject jabberjay "0.1.1"
(defproject jabberjay "0.2.0"
:description "Jabberjay - simple framework for creating Jabber bots"
:url "https://github.com/vbauer/jabberjay"
:license {:name "Eclipse Public License"
Expand Down
4 changes: 2 additions & 2 deletions resources/config.edn
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
:password "Fill me up!"
:host "Fill me up!"
:domain "Fill me up!"}
:watchdog {:folder "scripts"
:delay 1000}}
:scripts {:folder "scripts"
:watchdog 1000}}
4 changes: 2 additions & 2 deletions scripts/hi.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
(defn init
"Simple module for greating"
[data]
(let [user (:from-name data)]
(str "Hello, " user)))
(str "Hello, " (or (:from-name data)
(:from data))))
6 changes: 3 additions & 3 deletions src/jabberjay/script.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

(def ^:private SCRIPTS (atom nil))

(defn- conf-wd [k] ((get config/config :watchdog) k))
(defn- conf-delay [] (conf-wd :delay))
(defn- conf-folder [] (fs/file (conf-wd :folder)))
(defn- conf-scripts [k] ((get config/config :scripts) k))
(defn- conf-delay [] (conf-scripts :watchdog))
(defn- conf-folder [] (fs/file (conf-scripts :folder)))


; Internal API: Script engine
Expand Down

0 comments on commit ca6c029

Please sign in to comment.