From: plugd Date: Sun, 19 May 2024 19:10:39 +0000 (+0200) Subject: Messages kinda working. X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;h=b91c95a6e7a26c70e794ea0acd862cc43e5b8a52;p=lurk.git Messages kinda working. --- diff --git a/murk.el b/murk.el index fb79061..e89df65 100644 --- a/murk.el +++ b/murk.el @@ -323,6 +323,13 @@ The head of this list is always the current context.") (concat (murk-context-name ctx) "@" (murk-context-server ctx)))) +(defun murk-get-context (server &optional name) + (if name + (assoc server murk-contexts) + (let ((test-ctx (list server name))) + (seq-find (lambda (ctx) + (equal (seq-take ctx 2) test-ctx)) + murk-contexts)))) ;;; Buffer ;; @@ -450,6 +457,17 @@ The head of this list is always the current context.") 'invisible context-atom))))))) (murk-scroll-windows-to-last-line)) +(defun murk-display-message (server from to text) + (let ((context (if (string-prefix-p "#" to) + (murk-get-context server to) + (murk-get-context server)))) + (murk-display-string + context + (if (murk-server-context-p context) + (concat "[" from " -> " to "]") + (concat (murk-context->string context) " <" from ">")) + text))) + (defun murk-display-notice (context &rest notices) (murk-display-string context @@ -594,6 +612,40 @@ The head of this list is always the current context.") (if murk-show-joins (murk-display-notice nil nick " quit: " reason)))) + ("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 server + (murk-msg nil nil "NOTICE" + (list from (concat "\01VERSION " + version-string + "\01"))))) + (murk-display-notice nil "CTCP version request received from " + from " on " server)) + + ((rx (let ping (: "\01PING " (* (not "\01")) "\01"))) + (murk-send-msg server (lurk-msg nil nil "NOTICE" (list from ping))) + (murk-display-notice nil "CTCP ping received from " from " on " server)) + + ("\01USERINFO\01" + (murk-display-notice nil "CTCP userinfo request from " from + " on " server " (no response sent)")) + + ("\01CLIENTINFO\01" + (murk-display-notice nil "CTCP clientinfo request from " from + " on " server " (no response sent)")) + + ((rx (: "\01ACTION " (let action-text (* (not "\01"))) "\01")) + (murk-display-action from to action-text)) + + (_ + (murk-display-message server from to text))))) + (_ (murk-display-notice nil (murk-msg->string msg)))))) @@ -701,6 +753,16 @@ The head of this list is always the current context.") (murk-send-msg server (murk-msg nil nil "PART" channel)) (murk-display-error "No current channel to leave.")))) +(defun murk-command-msg (params) + (let ((server (murk-context-server (murk-current-context)))) + (if (and params (>= (length params) 2)) + (let ((to (car params)) + (text (string-join (cdr params) " "))) + (murk-send-msg server (lurk-msg nil nil "PRIVMSG" to text)) + (murk-display-message server + (murk-connection-nick server) + to text)) + (murk-display-notice nil "Usage: /msg ")))) ;;; Command entering ;; @@ -725,12 +787,15 @@ The head of this list is always the current context.") (murk-display-error "Badly formed command."))) (unless (string-empty-p string) (if (murk-current-context) - (progn + (let ((server (murk-context-server (murk-current-context)))) (murk-send-msg server (murk-msg nil nil "PRIVMSG" - (murk-context-name murk-current-context) + (murk-context-name (murk-current-context)) string)) - (murk-display-message murk-nick (murk-context->string (murk-current-context)) string)) + (murk-display-message server + murk-nick + (murk-context->string (murk-current-context)) + string)) (murk-display-error "No current context.")))))