X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=blobdiff_plain;f=murk.el;h=e67d8e61fa361b53a4551e85d946848c192f5ecc;hb=0a919f36d688bb2495321b46705e5ad39a0a9175;hp=2b21449e24f50e950a914976e8262d62c929c4de;hpb=ab967a9257e9b1bd41cc97bf03f6eaba8507bee8;p=lurk.git diff --git a/murk.el b/murk.el index 2b21449..e67d8e6 100644 --- a/murk.el +++ b/murk.el @@ -66,6 +66,24 @@ "If non-nil, use buffer header to display current host and channel." :type '(boolean)) +(defcustom murk-autoreply-table nil + "Table of autoreply messages. + +Each autoreply is a list of two elements: (matcher reply) + +Here matcher is a list: + +(network src cmd params ...) + +and reply is another list: + + (cmd params ...) + +Each entry in the matcher list is a regular expression tested against the +corresponding values in the incomming message. Entries can be nil, +in which case they match anything." + :type '(list (list) (list))) + ;;; Faces ;; @@ -583,7 +601,9 @@ The head of this list is always the current context.") (murk-get-context server)))) (murk-display-string context - (concat (murk-context->string context) " *") + (propertize + (concat (murk-context->string context) " *") + 'face (murk-get-context-facelist context)) from " " action-text))) (defun murk-display-notice (context &rest notices) @@ -723,6 +743,7 @@ The head of this list is always the current context.") (if murk-debug (murk-display-string nil nil string)) (let* ((msg (murk-string->msg string))) + (murk-process-autoreplies server msg) (pcase (murk-msg-cmd msg) ("PING" (murk-send-msg server @@ -899,6 +920,38 @@ The head of this list is always the current context.") (murk-display-notice (murk-get-context server) (murk-msg->string msg)))))) + +;;; User-defined responses +;; + +(defun murk--lists-equal (l1 l2) + (if (and l1 l2) + (if (or (not (and (car l1) (car l2))) + (string-match (car l1) (car l2))) + (murk--lists-equal (cdr l1) (cdr l2)) + nil) + t)) + +(defun murk-process-autoreply (server msg autoreply) + (let ((matcher (car autoreply)) + (reply (cadr autoreply))) + (let ((target-server (car matcher))) + (when (and (or (not target-server) + (and (equal server target-server))) + (murk--lists-equal (cdr matcher) + (append (list (murk-msg-src msg) + (murk-msg-cmd msg)) + (murk-msg-params msg)))) + (murk-send-msg server + (murk-msg nil nil (car reply) (cdr reply))))))) + +(defun murk-process-autoreplies (server msg) + (mapc + (lambda (autoreply) + (murk-process-autoreply server msg autoreply)) + murk-autoreply-table)) + + ;;; Commands ;; @@ -991,7 +1044,7 @@ The head of this list is always the current context.") (defun murk-command-quit (params) (let ((ctx (murk-current-context))) (if (not ctx) - (murk-display-error "No current context") + (murk-display-error "No current server") (let ((quit-msg (if params (string-join params " ") murk-default-quit-msg))) (murk-send-msg (murk-context-server ctx) @@ -1082,7 +1135,7 @@ The head of this list is always the current context.") (let ((server (murk-context-server ctx)) (nick (car params))) (murk-send-msg server - (lurk-msg nil nil "PRIVMSG" + (murk-msg nil nil "PRIVMSG" (list nick "\01VERSION\01"))) (murk-display-notice ctx "CTCP version request sent to " nick " on " server))