1 ;;; MURK --- Multiserver Unibuffer iRc Klient -*- lexical-binding:t -*-
3 ;; Copyright (C) 2024 plugd
5 ;; Author: plugd <plugd@thelambdalab.xyz>
6 ;; Created: 11 May 2024
9 ;; Homepage: http://thelambdalab.xyz/metalurk
10 ;; Package-Requires: ((emacs "26"))
12 ;; This file is not part of GNU Emacs.
14 ;; This program is free software: you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation, either version 3 of the License, or
17 ;; (at your option) any later version.
19 ;; This program is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with this file. If not, see <http://www.gnu.org/licenses/>.
37 "Multiserver Unibuffer iRc Klient"
40 (defcustom murk-nick "plugd"
43 (defcustom murk-default-quit-msg "Bye"
44 "Default quit message when none supplied.")
46 (defcustom murk-networks
47 '(("libera" "irc.libera.chat" 6697)
48 ("tilde" "tilde.chat" 6697))
59 (defvar murk-version "Murk v0.0"
60 "Value of this string is used in response to CTCP version queries.")
62 (defvar murk-notice-prefix "-!-")
63 (defvar murk-error-prefix "!!!")
64 (defvar murk-prompt-string ">")
66 ;;; Utility procedures
69 (defun murk--filtered-join (&rest args)
70 (string-join (seq-filter (lambda (el) el) args) " "))
72 (defun murk--as-string (obj)
74 (with-output-to-string (princ obj))
80 (defvar murk-connection-table nil
81 "An alist associating servers to connection information.
82 This includes the process and the response string.")
84 (defun murk-connection-process (server)
85 (elt (assoc server murk-connection-table) 1))
87 (defun murk-connection-response (server)
88 (elt (assoc server murk-connection-table) 2))
90 (defun murk-set-connection-response (server string)
91 (setf (elt (assoc server murk-connection-table) 3) string))
93 (defun murk-connection-close (server)
94 (setq murk-connection-table (assoc-delete-all server murk-connection-table)))
96 (defun murk-make-server-filter (server)
98 (dolist (line (split-string (concat (murk-connection-response server) string)
100 (if (string-suffix-p "\r" line)
101 (murk-eval-msg-string server (string-trim line))
102 (murk-set-connection-response line)))))
104 (defun murk-make-server-sentinel (server)
105 (lambda (proc string)
106 (unless (equal "open" (string-trim string))
107 (murk-display-error "Disconnected from server.")
108 (murk-remove-contexts-for-server server)
110 (murk-connection-close server))))
112 (defun murk-start-process (server)
113 (let* ((row (assoc server murk-networks))
116 (flags (seq-drop row 3)))
117 (make-network-process :name (concat "lurk" server)
121 :filter (murk-make-server-filter server)
122 :sentinel (murk-make-server-sentinel server)
124 :tls-parameters (if (memq :notls flags)
126 (cons 'gnutls-x509pki
127 (gnutls-boot-parameters
128 :type 'gnutls-x509pki
132 (defvar murk-ping-period 60)
134 ;; IDEA: Have a single ping timer which pings all connected hosts
136 (defun murk-connect (server)
137 (if (assoc server murk-connection-table)
138 (murk-display-error "Already connected to this network.")
139 (if (not (assoc server murk-networks))
140 (murk-display-error "Network '" server "' is unknown.")
141 (murk-start-process server)
142 (murk-send-msg (murk-msg nil nil "USER" murk-nick 0 "*" murk-nick))
143 (murk-send-msg (murk-msg nil nil "NICK" murk-nick)))))
145 ;;; Contexts and Servers
148 ;; A context is a list (server name ...) where name is a string
149 ;; representing either a channel name or nick, and server is a symbol
150 ;; identifying the server.
152 ;; Each server has a special context (server) used for messages
153 ;; to/from the server itself.
155 (defvar murk-current-context nil)
156 (defvar murk-context-members nil)
158 ;;; Main start procedure
163 ;;; metalurk.el ends here