#lang imperative-syndicate

(require "protocol.rkt")
(require "message.rkt")

(require/activate imperative-syndicate/reload)

(spawn #:name 'greeter
       (stop-when-reloaded)
       (on (asserted (ircd-channel-member $Ch $conn))
           (match-define (ircd-connection-info _ N U)
             (immediate-query [query-value #f ($ I (ircd-connection-info conn _ _)) I]))
           ;; TODO: history replay? As the following illustrates, we are able to forge messages
           (send! (ircd-event conn (irc-message (irc-source-nick N U) "PRIVMSG" (list Ch)
                                                (format "Welcome to ~a, ~a!" Ch N))))))

(spawn #:name 'authenticator
       (stop-when-reloaded)
       (during (observe (ircd-credentials $nick $user $password _))
         (log-info "Credentials: ~a ~a ~a" nick user password)
         (assert (ircd-credentials nick user password (equal? password "foobar")))))
