Add 'Reloaded' system for interactive development
Signed-off-by: Sebastian Crane <seabass-labrax@gmx.com>
This commit is contained in:
parent
aacf1cad28
commit
a2a041c9d1
|
@ -2,7 +2,8 @@
|
||||||
;; SPDX-FileCopyrightText: 2022 Sebastian Crane <seabass-labrax@gmx.com>
|
;; SPDX-FileCopyrightText: 2022 Sebastian Crane <seabass-labrax@gmx.com>
|
||||||
|
|
||||||
(ns system
|
(ns system
|
||||||
(:require [clojure.data.json :as json]
|
(:require [irc]
|
||||||
|
[clojure.data.json :as json]
|
||||||
[clj-yaml.core :as yaml]))
|
[clj-yaml.core :as yaml]))
|
||||||
|
|
||||||
(defn json-data-reader [key value]
|
(defn json-data-reader [key value]
|
||||||
|
@ -32,3 +33,30 @@
|
||||||
(with-open [datafile (clojure.java.io/reader f)]
|
(with-open [datafile (clojure.java.io/reader f)]
|
||||||
(yaml/parse-stream datafile))
|
(yaml/parse-stream datafile))
|
||||||
(catch Exception e nil)))
|
(catch Exception e nil)))
|
||||||
|
|
||||||
|
(defn system []
|
||||||
|
{:config nil
|
||||||
|
:state nil
|
||||||
|
:irc nil})
|
||||||
|
|
||||||
|
(defn start [system]
|
||||||
|
(let [config (load-config "config.yaml")
|
||||||
|
state (atom (load-state (:data-file config)))
|
||||||
|
irc (irc/new-irc-connection state config)]
|
||||||
|
(irclj.core/join irc (get-in config [:irc :channel]))
|
||||||
|
{:config config
|
||||||
|
:state state
|
||||||
|
:irc irc}))
|
||||||
|
|
||||||
|
(defn stop [system]
|
||||||
|
(do
|
||||||
|
(save-state
|
||||||
|
(get-in system [:config :data-file])
|
||||||
|
(deref (:state system)))
|
||||||
|
(irclj.core/quit (system :irc))))
|
||||||
|
|
||||||
|
(defn restart [system-atom]
|
||||||
|
(do
|
||||||
|
(swap! system-atom stop)
|
||||||
|
(reset! system-atom (system))
|
||||||
|
(swap! system-atom start)))
|
||||||
|
|
Loading…
Reference in New Issue