+ ("001" ; RPL_WELCOME
+ (let* ((params (murk-msg-params msg))
+ (nick (elt params 0))
+ (text (string-join (seq-drop params 1) " ")))
+ (murk-set-connection-nick network nick)
+ (murk-display-notice (murk-get-context network) text))
+ (let* ((row (assoc network murk-networks))
+ (channels (if (memq :channels row)
+ (cdr (memq :channels row))
+ nil)))
+ (dolist (channel channels)
+ (murk-command-join (list channel)))))
+
+ ("353" ; NAMEREPLY
+ (let* ((params (murk-msg-params msg))
+ (channel (elt params 2))
+ (names (split-string (elt params 3)))
+ (ctx (murk-get-context network channel)))
+ (if ctx
+ (murk-add-context-users ctx names)
+ (murk-display-notice ctx "Users in " channel
+ ": " (string-join names " ")))))
+
+ ("366" ; ENDOFNAMES
+ (let* ((params (murk-msg-params msg))
+ (channel (elt params 1))
+ (ctx (murk-get-context network channel)))
+ (if ctx
+ (murk-display-notice
+ ctx
+ (murk--as-string (length (murk-get-context-users ctx)))
+ " users in " channel)
+ (murk-display-notice (murk-get-context network)
+ "End of " channel " names list."))))
+
+ ("331" ; RPL_NOTOPIC
+ (let* ((params (murk-msg-params msg))
+ (channel (elt params 1))
+ (ctx (murk-get-context network channel)))
+ (murk-display-notice ctx "No topic set.")))
+
+ ("332" ; RPL_TOPIC
+ (let* ((params (murk-msg-params msg))
+ (channel (elt params 1))
+ (topic (elt params 2))
+ (ctx (murk-get-context network channel)))
+ (murk-display-notice ctx "Topic: " topic)))
+
+ ((rx (= 3 (any digit)))
+ (murk-display-notice (murk-get-context network)
+ (mapconcat 'identity (cdr (murk-msg-params msg)) " ")))
+
+ ((and "JOIN"
+ (guard (equal (murk-connection-nick network)
+ (murk-msg-src msg))))
+ (let* ((channel (car (murk-msg-params msg)))
+ (context (list network channel)))
+ (murk-add-context context)
+ (murk-del-all-context-users context)
+ (murk-display-notice (murk-current-context)
+ "Joining channel " channel " on " network)
+ (murk-highlight-current-context)
+ (murk-render-prompt)))
+
+ ("JOIN"
+ (let* ((channel (car (murk-msg-params msg)))
+ (nick (murk-msg-src msg))
+ (ctx (murk-get-context network channel)))
+ (murk-add-context-users ctx (list nick))
+ (if murk-show-joins
+ (murk-display-notice ctx nick " joined channel " channel
+ " on " network))))
+
+ ((and "PART"
+ (guard (equal (murk-connection-nick network)
+ (murk-msg-src msg))))
+ (let* ((channel (car (murk-msg-params msg)))
+ (context (list network channel)))
+ (murk-display-notice context "Left channel " channel)
+ (murk-remove-context context)
+ (murk-del-all-context-users context)
+ (murk-highlight-current-context)
+ (murk-render-prompt)))
+
+ ("PART"
+ (let* ((channel (car (murk-msg-params msg)))
+ (nick (murk-msg-src msg))
+ (ctx (murk-get-context network channel)))
+ (murk-del-context-user ctx nick)
+ (if murk-show-joins
+ (murk-display-notice ctx nick " left channel " channel
+ " on " network))))
+
+ ((and "NICK"
+ (guard (equal (murk-connection-nick network)
+ (murk-msg-src msg))))
+ (let ((new-nick (car (murk-msg-params msg)))
+ (old-nick (murk-connection-nick network)))
+ (murk-set-connection-nick network new-nick)
+ (murk-rename-network-user network old-nick new-nick)
+ (murk-display-notice (murk-get-context network)
+ "Nick set to " new-nick " on " network)))
+
+ ("NICK"
+ (let ((old-nick (murk-msg-src msg))
+ (new-nick (car (murk-msg-params msg))))
+ (murk-display-notice (murk-get-context network)
+ old-nick " is now known as " new-nick
+ " on " network)
+ (murk-rename-network-user network old-nick new-nick)))
+
+ ("TOPIC"
+ (let ((channel (car (murk-msg-params msg)))
+ (nick (murk-msg-src msg))
+ (topic (cadr (murk-msg-params msg))))
+ (murk-display-notice (murk-get-context network channel)
+ nick " set the topic: " topic)))
+
+ ("QUIT"
+ (let ((nick (murk-msg-src msg))
+ (reason (mapconcat 'identity (murk-msg-params msg) " ")))
+ (murk-del-network-user network nick)
+ (if murk-show-joins
+ (murk-display-notice (murk-get-context network)
+ nick " on " network " has quit: " reason))))
+
+ ("NOTICE"
+ (let ((nick (murk-msg-src msg))
+ (channel (car (murk-msg-params msg)))
+ (text (cadr (murk-msg-params msg))))
+ (pcase text
+ ((rx (: "\01VERSION "
+ (let version (* (not "\01")))
+ "\01"))
+ (murk-display-notice (murk-get-context network)
+ "CTCP version reply from " nick ": " version))
+ (_
+ (murk-display-notice (murk-get-context network channel) text)))))
+
+ ("PRIVMSG"
+ (let* ((from (murk-msg-src msg))
+ (params (murk-msg-params msg))
+ (to (car params))
+ (text (cadr params)))
+ (pcase text
+ ("\01VERSION\01"
+ (let ((version-string (concat murk-version " - running on GNU Emacs " emacs-version)))
+ (murk-send-msg network
+ (murk-msg nil nil "NOTICE"
+ (list from (concat "\01VERSION "
+ version-string
+ "\01")))))
+ (murk-display-notice (murk-get-context network)
+ "CTCP version request received from "
+ from " on " network))
+
+ ((rx (let ping (: "\01PING " (* (not "\01")) "\01")))
+ (murk-send-msg network (murk-msg nil nil "NOTICE" (list from ping)))
+ (murk-display-notice (murk-get-context network)
+ "CTCP ping received from " from " on " network))
+
+ ("\01USERINFO\01"
+ (murk-display-notice (murk-get-context network)
+ "CTCP userinfo request from " from
+ " on " network " (no response sent)"))
+
+ ("\01CLIENTINFO\01"
+ (murk-display-notice (murk-get-context network)
+ "CTCP clientinfo request from " from
+ " on " network " (no response sent)"))
+
+ ((rx (: "\01ACTION " (let action-text (* (not "\01"))) "\01"))
+ (murk-display-action network from to action-text))
+
+ (_
+ (murk-display-message network from to text)))))
+