diff --git a/enotify.el b/enotify.el new file mode 100644 index 0000000..956ddda --- /dev/null +++ b/enotify.el @@ -0,0 +1,65 @@ +;;; enotify.el --- send a message to an IRC channel from Emacs -*- lexical-binding:t -*- + +;; Copyright (C) 2024 Jeremy Baxter + +;; Author: Jeremy Baxter +;; Created: March 2024 +;; Keywords: irc, internet + +;; This file is not part of GNU Emacs. + +;; enotify.el is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. +;; +;; enotify.el is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. +;; +;; You should have received a copy of the GNU General Public License +;; along with enotify.el. If not, see . + +;;; Code: + +(defvar enotify-buffer "*enotify*" + "Name of the enotify process buffer") +(defvar enotify-proc "enotify-process" + "Name of the enotify socket process") +(defvar enotify-realname "enotify-client" + "enotify's IRC realname that shows up in /whois") + +(defun enotify-send-string (proc string) + (process-send-string proc (concat string "\r\n"))) + +(defun enotify-wait-for-response (proc) + (while (accept-process-output proc 3))) + +(defun enotify (addr port nick chan mesg) + "Send a message to an IRC channel. + + Log in to the IRC network ADDR:PORT with the nickname NICK, + join the channel CHAN and send the string MESG." + (interactive + "MServer address: \nnServer port: \nMNickname: \nMChannel: \nMMessage: ") + (let ((proc (open-network-stream + enotify-proc + enotify-buffer + addr port + :type 'plain + :nowait t))) + (enotify-wait-for-response proc) + ;; authenticate + (enotify-send-string proc + (concat "USER " nick " 0 * :" enotify-realname)) + (enotify-send-string proc (concat "NICK " nick)) + (enotify-wait-for-response proc) + ;; join and send message + (enotify-send-string proc (concat "JOIN " chan)) + (enotify-send-string proc + (concat "PRIVMSG " chan " :" mesg)) + ;; quit and close connection + (enotify-send-string proc "QUIT") + (process-send-eof proc) + (delete-process proc)))