From: Tim Vaughan Date: Mon, 21 Jun 2021 13:01:53 +0000 (+0200) Subject: Added /connect and included filling. X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;h=6cee2fa822e2861b99872372a0c1cc234ca21383;p=lurk.git Added /connect and included filling. --- diff --git a/lirc.el b/lirc.el index 5244c2f..a5a0500 100644 --- a/lirc.el +++ b/lirc.el @@ -43,10 +43,12 @@ "Default full name.") (defcustom lirc-user-name "plugd" "Default user name.") -(defcustom lirc-host "irc.libera.chat" - "Default server.") -(defcustom lirc-port 6697 - "Default port.") + +(defcustom lirc-networks + '(("libera" "irc.libera.chat" 6697) + ("freenode" "chat.freenode.net" 6697) + ("local" "localhost" 6697)) + "IRC networks.") (defcustom lirc-prompt-string "> " "Prompt.") @@ -99,7 +101,6 @@ (defvar lirc-error-prompt (propertize "!!!" 'face 'lirc-error)) - ;;; Network process ;; @@ -111,23 +112,38 @@ (lirc-eval-msg-string (string-trim line)) (setq lirc-response line)))) -(defun lirc-get-process (&optional connect) +(defun lirc-sentinel (proc string) + (message string)) + +(defun lirc-start-process (network) + (let* ((row (assoc network lirc-networks)) + (host (elt row 1)) + (port (elt row 2))) + (make-network-process :name "lirc" + :host host + :service port + :filter #'lirc-filter + :nowait nil + :tls-parameters (cons 'gnutls-x509pki + (gnutls-boot-parameters + :type 'gnutls-x509pki + :hostname host)) + :buffer "*lirc*"))) + + +(defun lirc-connect (network) + (setq lirc-channel-list nil) + (setq lirc-current-channel nil) + (lirc-start-process network) + (lirc-send-msg (lirc-msg nil nil "USER" lirc-user-name 0 "*" lirc-full-name)) + (lirc-send-msg (lirc-msg nil nil "NICK" lirc-nick))) + +(defun lirc-send-msg (msg) (let ((proc (get-process "lirc"))) (if (and proc (eq (process-status proc) 'open)) - proc - (if connect - (make-network-process :name "lirc" - :host lirc-host - :service lirc-port - :filter #'lirc-filter - :nowait nil - :tls-parameters (cons 'gnutls-x509pki - (gnutls-boot-parameters - :type 'gnutls-x509pki - :hostname lirc-host)) - :buffer "*lirc*") - (lirc-display-error "No server connection established.") - (error "No server connection established"))))) + (process-send-string proc (concat (lirc-msg->string msg) "\r\n")) + (lirc-display-error "No server connection established.") + (error "No server connection established")))) ;;; Messages ;; @@ -254,22 +270,16 @@ portion of the source component of the message, as LIRC doesn't use this.") (with-current-buffer (get-buffer-create "*lirc*") (save-excursion (goto-char lirc-prompt-marker) - (let ((inhibit-read-only t)) + (let ((inhibit-read-only t) + (old-pos (marker-position lirc-prompt-marker)) + (adaptive-fill-regexp (rx (= 6 anychar)))) (insert-before-markers (propertize (concat (format-time-string "%H:%M") " ") 'face 'lirc-text 'read-only t) (propertize (concat (apply #'concat strings) "\n") - 'read-only t)))))) - -(defun lirc-connect () - (lirc-get-process t) - (lirc-send-msg (lirc-msg nil nil "USER" lirc-user-name 0 "*" lirc-full-name)) - (lirc-send-msg (lirc-msg nil nil "NICK" lirc-nick))) - -(defun lirc-send-msg (msg) - (let ((proc (lirc-get-process))) - (process-send-string proc (concat (lirc-msg->string msg) "\r\n")))) + 'read-only t)) + (fill-region old-pos lirc-prompt-marker))))) (defun lirc-render-prompt () (with-current-buffer "*lirc*" @@ -347,7 +357,8 @@ portion of the source component of the message, as LIRC doesn't use this.") (pcase (lirc-msg-cmd msg) ("PING" (lirc-send-msg - (lirc-msg nil nil "PONG" (lirc-msg-params msg)))) + (lirc-msg nil nil "PONG" (lirc-msg-params msg))) + (lirc-display-notice "ping-pong")) ("353" ; NAMEREPLY (let* ((params (lirc-msg-params msg)) @@ -458,10 +469,14 @@ portion of the source component of the message, as LIRC doesn't use this.") (defun lirc-enter-string (string) (if (string-prefix-p "/" string) (pcase (substring string 1) - ((rx (: "TOPIC" " " (let new-topic (* not-newline)))) + ((rx (: "CONNECT " (let network (* not-newline)))) + (lirc-display-notice "Connecting to " network "...") + (lirc-connect network)) + + ((rx (: "TOPIC " (let new-topic (* not-newline)))) (lirc-send-msg (lirc-msg nil nil "TOPIC" lirc-current-channel new-topic))) - ((rx (: "me" " " (let action (* not-newline)))) + ((rx (: "ME " (let action (* not-newline)))) (lirc-send-msg (lirc-msg nil nil "PRIVMSG" (list lirc-current-channel (concat "\01ACTION " action "\01")))) @@ -536,7 +551,6 @@ portion of the source component of the message, as LIRC doesn't use this.") (switch-to-buffer "*lirc*")) (lirc-mode) (lirc-setup-buffer) - (lirc-connect) "Started LIRC.")