From 1e3e978e362282bb4b86dfaad37a72606e84dfdb Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Tue, 29 Jan 2019 20:47:17 +0000 Subject: [PATCH] /LIST --- syndicate/examples/ircd/session.rkt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/syndicate/examples/ircd/session.rkt b/syndicate/examples/ircd/session.rkt index 0920158..38986ee 100644 --- a/syndicate/examples/ircd/session.rkt +++ b/syndicate/examples/ircd/session.rkt @@ -9,6 +9,7 @@ (require/activate imperative-syndicate/reload) (require/activate imperative-syndicate/drivers/tcp) (require syndicate/support/hash) +(require (only-in racket/list append*)) (define (ircd-connection-facet this-conn peer-host) (define (send-to-remote #:newline [with-newline #t] fmt . vs) @@ -160,6 +161,23 @@ (define Present (string-join (filter on? Nicks) " ")) (send! (ircd-event conn (irc-message server-prefix 303 '("*") Present))))) +(spawn #:name 'list-responder + (stop-when-reloaded) + (define/query-hash topics (ircd-channel-topic $Ch $topic) Ch topic) + (define/query-hash counts (ircd-channel-user-count $Ch $count) Ch count) + (on (message (ircd-action $conn (irc-message _ "LIST" $requested-channel-names0 _))) + (define requested-channel-names + (append* (map (lambda (ns) (string-split ns #px",+")) requested-channel-names0))) + (send! (ircd-event conn (irc-message server-prefix 321 '("*" "Channel") "Users Name"))) + (for [(Ch (if (null? requested-channel-names) + (in-hash-keys (topics)) + (in-list requested-channel-names)))] + (when (hash-has-key? (topics) Ch) + (define topic (hash-ref (topics) Ch)) + (define count (hash-ref (counts) Ch 0)) + (send! (ircd-event conn (irc-message server-prefix 322 (list "*" Ch count) topic))))) + (send! (ircd-event conn (irc-message server-prefix 323 '("*") "End of /LIST"))))) + (spawn #:name 'session-listener-factory (stop-when-reloaded) (during/spawn (ircd-listener $port)