1
0
Disbranĉigi 0

Make reply-function a bit more readable

This commit is contained in:
Jaidyn Ann 2023-05-29 11:00:52 -05:00
parent 325e94dbdd
commit 82599798fc

View File

@ -21,7 +21,7 @@
;; ;;
(import scheme (import scheme
(chicken file) (chicken io) (chicken pathname) (chicken file) (chicken file posix) (chicken io) (chicken pathname)
(chicken process-context) (chicken process-context posix) (chicken process-context) (chicken process-context posix)
(chicken string) (chicken string)
srfi-1 srfi-18 srfi-69 srfi-1 srfi-18 srfi-69
@ -95,34 +95,33 @@
(define (make-irc-reply-callback conn) (define (make-irc-reply-callback conn)
(let ([root-dir (hash-table-ref conn 'directory)]) (let ([root-dir (hash-table-ref conn 'directory)])
(lambda (conn reply params #!optional sender) (lambda (conn reply params #!optional sender)
(cond (let ([channel (second params)])
;; If topic set, output to a channel's .topic file (cond
[(and (eq? reply RPL_TOPIC) ;; If topic set, output to a channel's .topic file
(irc:channel? (second params))) [(and (eq? reply RPL_TOPIC)
(chatdir:channel-metadata-set! root-dir (second params) (irc:channel? channel))
"topic" (last params))] (chatdir:channel-metadata-set! root-dir channel
"topic" (last params))]
[(and (eq? reply RPL_TOPICWHOTIME) [(and (eq? reply RPL_TOPICWHOTIME)
(irc:channel? (second params))) (irc:channel? (second params)))
(chatdir:channel-metadata-set! root-dir (second params) (chatdir:channel-metadata-set! root-dir channel
"topic" #f "topic" #f
`((user.chat.sender . ,(third params)) `((user.chat.sender . ,(third params))
(user.chat.date . ,(last params))))] (user.chat.date . ,(last params))))]
;; We've got to add users, when they join the room! ;; We've got to add users, when they join the room!
[(or (and (irc:capability? conn 'userhost-in-names) [(or (and (irc:capability? conn 'userhost-in-names)
(eq? reply RPL_ENDOFNAMES)) (eq? reply RPL_ENDOFNAMES))
(eq? reply RPL_ENDOFWHO)) (eq? reply RPL_ENDOFWHO))
(map (lambda (nick) (map (lambda (nick)
(let ([hostmask (irc:user-get conn nick 'hostmask)] (let ([hostmask (irc:user-get conn nick 'hostmask)])
[channel (second params)]) (chatdir:channel-user-add! root-dir channel nick)
(chatdir:channel-user-add! root-dir channel nick) (chatdir:channel-user-toggle-states! root-dir channel nick
(chatdir:channel-user-toggle-states! root-dir channel nick "online" "offline")))
"online" "offline"))) (irc:channel-users conn (second params)))]
(irc:channel-users conn (second params)))] [(string? (last params))
(chatdir:channel-message-add! root-dir ".server" (last params))])))))
[#t
(chatdir:channel-message-add! root-dir ".server" (last params) "server")]))))
(define *help-msg* (define *help-msg*
@ -226,7 +225,7 @@
;; Kick off the main loop! ;; Kick off the main loop!
(irc:loop connection (irc:loop connection
(make-irc-command-callback connection) (make-irc-command-callback connection)
(make-irc-reply-callback connection))))) (make-irc-reply-callback connection))))
(main) (main)