#lang imperative-syndicate

(require/activate imperative-syndicate/reload)
(require/activate imperative-syndicate/supervise)
(require/activate imperative-syndicate/drivers/config)

(require "protocol.rkt")

(require racket/set)
(require (only-in racket/list append* flatten))
(require (only-in racket/string string-split))

(spawn-configuration 'ircd "ircd-config.rktd" #:hook (lambda () (stop-when-reloaded)))

(spawn #:name 'config
       (stop-when-reloaded)

       (during (config 'ircd `(port ,$port))
         (assert (ircd-listener port)))

       (during (config 'ircd `(channel ,$Ch))
         (assert (ircd-channel Ch)))

       (define/query-set motds (config 'ircd `(motd ,$text)) text)
       (assert (ircd-motd (append*
                           (map (lambda (t) (string-split t "\n"))
                                (flatten (set->list (motds))))))))
