Compare commits
4 Commits
856432516c
...
91cbdb69da
Author | SHA1 | Date |
---|---|---|
|
91cbdb69da | |
|
fecd09c656 | |
|
0abd793fe7 | |
|
56094478db |
12
README.md
12
README.md
|
@ -66,18 +66,18 @@ Since `matchbot` uses Clojure's [tools.deps library](https://clojure.org/guides/
|
||||||
You can create, start and stop an instance of the chatbot process with the functions in the `system` namespace:
|
You can create, start and stop an instance of the chatbot process with the functions in the `system` namespace:
|
||||||
|
|
||||||
``` clojure
|
``` clojure
|
||||||
;; creating a new instance
|
;; creating a new instance - an empty Var
|
||||||
(def my-instance (atom (system/system)))
|
(def my-instance nil)
|
||||||
|
|
||||||
;; starting the instance
|
;; starting the instance
|
||||||
(swap! my-instance system/start)
|
(alter-var-root #'my-instance system/start)
|
||||||
|
|
||||||
;; restarting the instance
|
;; restarting the instance
|
||||||
(system/restart my-instance)
|
(system/restart #'my-instance)
|
||||||
|
|
||||||
;; stopping and resetting the instance
|
;; stopping and resetting the instance
|
||||||
(swap! my-instance stop)
|
(alter-var-root #'my-instance system/stop)
|
||||||
(reset! my-instance (system/system))
|
(alter-var-root #'my-instance (constantly nil))
|
||||||
```
|
```
|
||||||
|
|
||||||
Once you are familiar with nREPL, you can additionally use [tools.namespace.repl](https://github.com/clojure/tools.namespace) to make reevaluating (reloading) your changes easier:
|
Once you are familiar with nREPL, you can additionally use [tools.namespace.repl](https://github.com/clojure/tools.namespace) to make reevaluating (reloading) your changes easier:
|
||||||
|
|
|
@ -34,12 +34,7 @@
|
||||||
(yaml/parse-stream datafile))
|
(yaml/parse-stream datafile))
|
||||||
(catch Exception e nil)))
|
(catch Exception e nil)))
|
||||||
|
|
||||||
(defn system []
|
(defn start [_]
|
||||||
{:config nil
|
|
||||||
:state nil
|
|
||||||
:irc nil})
|
|
||||||
|
|
||||||
(defn start [system]
|
|
||||||
(let [config (load-config "config.yaml")
|
(let [config (load-config "config.yaml")
|
||||||
state (atom (load-state (:data-file config)))
|
state (atom (load-state (:data-file config)))
|
||||||
irc (irc/new-irc-connection state config)]
|
irc (irc/new-irc-connection state config)]
|
||||||
|
@ -55,14 +50,12 @@
|
||||||
(deref (:state system)))
|
(deref (:state system)))
|
||||||
(irclj.core/quit (system :irc))))
|
(irclj.core/quit (system :irc))))
|
||||||
|
|
||||||
(defn restart [system-atom]
|
(defn restart [system-var]
|
||||||
(do
|
(do
|
||||||
(swap! system-atom stop)
|
(stop (deref system-var))
|
||||||
(reset! system-atom (system))
|
(alter-var-root system-var start)))
|
||||||
(swap! system-atom start)))
|
|
||||||
|
|
||||||
(defn -main [& args]
|
(defn -main [& args]
|
||||||
(let [main-system (atom (system/system))]
|
(let [main-system (system/start nil)]
|
||||||
(swap! main-system system/start)
|
|
||||||
(.addShutdownHook (Runtime/getRuntime)
|
(.addShutdownHook (Runtime/getRuntime)
|
||||||
(Thread. (partial swap! main-system stop)))))
|
(Thread. #(stop main-system)))))
|
||||||
|
|
Loading…
Reference in New Issue