From 8af9d9d4c177e30d34310985418a3ffd8386e3fd Mon Sep 17 00:00:00 2001 From: plugd Date: Tue, 22 Jul 2025 10:37:01 +0200 Subject: [PATCH] Command procedures now take a context argument. Allows their application to specific contexts which differ from the current context, e.g. /join during connection. --- lurk.el | 159 +++++++++++++++++++++++++++----------------------------- 1 file changed, 76 insertions(+), 83 deletions(-) diff --git a/lurk.el b/lurk.el index e74334d..106af91 100644 --- a/lurk.el +++ b/lurk.el @@ -797,7 +797,7 @@ The head of this list is always the current context.") (cdr (memq :channels row)) nil))) (dolist (channel channels) - (lurk-command-join (list channel))))) + (lurk-command-join (lurk-get-context network) (list channel))))) ("353" ; NAMEREPLY (let* ((params (lurk-msg-params msg)) @@ -1047,7 +1047,7 @@ The head of this list is always the current context.") (mapcar (lambda (u) (car (split-string u "@" t))) users))) -(defun lurk-command-help (params) +(defun lurk-command-help (_ctx params) (if params (let* ((cmd-str (upcase (car params))) (row (assoc cmd-str lurk-command-table #'equal))) @@ -1061,7 +1061,7 @@ The head of this list is always the current context.") (lurk-display-notice nil " \x02" (elt row 0) "\x02: " (elt row 1))) (lurk-display-notice nil "Use /HELP COMMAND to display information about a specific command."))) -(defun lurk-command-debug (params) +(defun lurk-command-debug (_ctx params) (setq lurk-debug (if params (if (equal (upcase (car params)) "ON") @@ -1070,7 +1070,7 @@ The head of this list is always the current context.") (not lurk-debug))) (lurk-display-notice nil "Debug mode now " (if lurk-debug "on" "off") ".")) -(defun lurk-command-header (params) +(defun lurk-command-header (_ctx params) (if (if params (equal (upcase (car params)) "ON") @@ -1081,7 +1081,7 @@ The head of this list is always the current context.") (setq-local header-line-format nil) (lurk-display-notice nil "Header disabled."))) -(defun lurk-command-showjoins (params) +(defun lurk-command-showjoins (_ctx params) (setq lurk-show-joins (if params (if (equal (upcase (car params)) "ON") @@ -1091,14 +1091,14 @@ The head of this list is always the current context.") (lurk-display-notice nil "Joins/parts will now be " (if lurk-show-joins "shown" "hidden") ".")) -(defun lurk-command-connect (params) +(defun lurk-command-connect (_ctx params) (if params (let ((network (car params))) (lurk-display-notice nil "Attempting to connect to " network "...") (lurk-connect network)) (lurk-display-notice nil "Usage: /connect "))) -(defun lurk-command-networks (_params) +(defun lurk-command-networks (_ctx _params) (lurk-display-notice nil "Currently-known networks:") (dolist (row lurk-networks) (seq-let (network network port &rest _others) row @@ -1107,82 +1107,78 @@ The head of this list is always the current context.") " " (number-to-string port) "]"))) (lurk-display-notice nil "(Modify the `lurk-networks' variable to add more.)")) -(defun lurk-command-quit (params) - (let ((ctx (lurk-current-context))) - (if (not ctx) - (lurk-display-error "No current network") - (let ((quit-msg (if params (string-join params " ") lurk-default-quit-msg))) - (lurk-send-msg - (lurk-context-network ctx) - (lurk-msg nil nil "QUIT" quit-msg)))))) +(defun lurk-command-quit (ctx params) + (if (not ctx) + (lurk-display-error "No current network") + (let ((quit-msg (if params (string-join params " ") lurk-default-quit-msg))) + (lurk-send-msg + (lurk-context-network ctx) + (lurk-msg nil nil "QUIT" quit-msg))))) -(defun lurk-command-join (params) +(defun lurk-command-join (ctx params) (if params - (let ((network (lurk-context-network (lurk-current-context)))) + (let ((network (lurk-context-network ctx))) (dolist (channel params) (lurk-send-msg network (lurk-msg nil nil "JOIN" channel)))) (lurk-display-notice nil "Usage: /join channel [channel2 ...]"))) -(defun lurk-command-part (params) - (let ((ctx (cond - ((not params) (lurk-current-context)) +(defun lurk-command-part (ctx params) + (let ((part-ctx (cond + ((not params) ctx) ((seq-contains (car params) "@") (lurk-string->context (car params))) (t (list (lurk-context-network (lurk-current-context)) (car params)))))) - (let ((network (lurk-context-network ctx)) - (channel (lurk-context-channel ctx))) + (let ((network (lurk-context-network part-ctx)) + (channel (lurk-context-channel part-ctx))) (if channel (lurk-send-msg network (lurk-msg nil nil "PART" channel)) (lurk-display-error "Specify which channel to leave"))))) -(defun lurk-command-switch-context (params) +(defun lurk-command-switch-context (_ctx params) (if (not params) (lurk-display-notice nil "Usage: /switchcontext #channel@network") - (let ((ctx (lurk-string->context (car params)))) - (lurk-switch-to-context ctx) + (let ((new-ctx (lurk-string->context (car params)))) + (lurk-switch-to-context new-ctx) (lurk-highlight-current-context) (lurk-render-prompt) (if lurk-zoomed (lurk-zoom-in (lurk-current-context)))))) -(defun lurk-command-nick (params) +(defun lurk-command-nick (ctx params) (if params - (let ((new-nick (string-join params " ")) - (ctx (lurk-current-context))) + (let ((new-nick (string-join params " "))) (if ctx (lurk-send-msg (lurk-context-network ctx) (lurk-msg nil nil "NICK" new-nick)) (lurk-display-error "No current connection"))) (lurk-display-notice nil "Usage: /nick "))) -(defun lurk-command-list (params) - (let ((ctx (lurk-current-context))) - (if ctx - (if (not params) - (lurk-display-notice nil "This command can generate lots of output." - " Use `/LIST -yes' if you really want this," - " or `/LIST ' to reduce the output.") - (let ((network (lurk-context-network ctx))) - (if (equal (upcase (car params)) "-YES") - (lurk-send-msg network (lurk-msg nil nil "LIST")) - (lurk-send-msg network (lurk-msg nil nil "LIST" - (car params)))))) - (lurk-display-error "No current connection")))) - -(defun lurk-command-topic (params) - (let ((ctx (lurk-current-context))) - (if (and ctx (not (lurk-network-context-p ctx))) - (let ((network (lurk-context-network ctx)) - (channel (lurk-context-channel ctx))) - (if params - (lurk-send-msg network - (lurk-msg nil nil "TOPIC" channel - (string-join params " "))) +(defun lurk-command-list (ctx params) + (if ctx + (if (not params) + (lurk-display-notice nil "This command can generate lots of output." + " Use `/LIST -yes' if you really want this," + " or `/LIST ' to reduce the output.") + (let ((network (lurk-context-network ctx))) + (if (equal (upcase (car params)) "-YES") + (lurk-send-msg network (lurk-msg nil nil "LIST")) + (lurk-send-msg network (lurk-msg nil nil "LIST" + (car params)))))) + (lurk-display-error "No current connection"))) + +(defun lurk-command-topic (ctx params) + (if (and ctx (not (lurk-network-context-p ctx))) + (let ((network (lurk-context-network ctx)) + (channel (lurk-context-channel ctx))) + (if params (lurk-send-msg network - (lurk-msg nil nil "TOPIC" channel)))) - (lurk-display-notice nil "No current channel.")))) - -(defun lurk-command-msg (params) - (let ((network (lurk-context-network (lurk-current-context)))) + (lurk-msg nil nil "TOPIC" channel + (string-join params " "))) + (lurk-send-msg network + (lurk-msg nil nil "TOPIC" channel)))) + (lurk-display-notice nil "No current channel."))) + +(defun lurk-command-msg (ctx params) + (let ((network (lurk-context-network ctx))) (if (and params (>= (length params) 2)) (let ((to (car params)) (text (string-join (cdr params) " "))) @@ -1192,9 +1188,8 @@ The head of this list is always the current context.") to text)) (lurk-display-notice nil "Usage: /msg ")))) -(defun lurk-command-me (params) - (let* ((ctx (lurk-current-context)) - (network (lurk-context-network ctx))) +(defun lurk-command-me (ctx params) + (let* ((network (lurk-context-network ctx))) (if (and ctx (not (lurk-network-context-p ctx))) (if params (let* ((channel (lurk-context-channel ctx)) @@ -1208,29 +1203,27 @@ The head of this list is always the current context.") (lurk-display-notice nil "Usage: /me ")) (lurk-display-notice nil "No current channel.")))) -(defun lurk-command-version (params) - (let ((ctx (lurk-current-context))) - (if ctx - (if params - (let ((network (lurk-context-network ctx)) - (nick (car params))) - (lurk-send-msg network - (lurk-msg nil nil "PRIVMSG" - (list nick "\01VERSION\01"))) - (lurk-display-notice ctx "CTCP version request sent to " - nick " on " network)) - (lurk-display-notice ctx "Usage: /version ")) - (lurk-display-notice nil "No current channel.")))) - -(defun lurk-command-users (_params) - (let ((ctx (lurk-current-context))) - (if (and ctx (not (lurk-network-context-p ctx))) - (let ((channel (lurk-context-channel ctx)) - (network (lurk-context-network ctx)) - (users (lurk-get-context-users ctx))) - (lurk-display-notice ctx "Users in " channel " on " network ":") - (lurk-display-notice ctx (string-join users " "))) - (lurk-display-notice nil "No current channel.")))) +(defun lurk-command-version (ctx params) + (if ctx + (if params + (let ((network (lurk-context-network ctx)) + (nick (car params))) + (lurk-send-msg network + (lurk-msg nil nil "PRIVMSG" + (list nick "\01VERSION\01"))) + (lurk-display-notice ctx "CTCP version request sent to " + nick " on " network)) + (lurk-display-notice ctx "Usage: /version ")) + (lurk-display-notice nil "No current channel."))) + +(defun lurk-command-users (ctx _params) + (if (and ctx (not (lurk-network-context-p ctx))) + (let ((channel (lurk-context-channel ctx)) + (network (lurk-context-network ctx)) + (users (lurk-get-context-users ctx))) + (lurk-display-notice ctx "Users in " channel " on " network ":") + (lurk-display-notice ctx (string-join users " "))) + (lurk-display-notice nil "No current channel."))) ;;; Command entering @@ -1248,7 +1241,7 @@ The head of this list is always the current context.") (split-string params-str nil t) nil))) (if (and command-row (elt command-row 2)) - (funcall (elt command-row 2) params) + (funcall (elt command-row 2) (lurk-current-context) params) (lurk-send-msg (lurk-context-network (lurk-current-context)) (lurk-msg nil nil (upcase cmd-str) params))))) -- 2.20.1