75 lines
2.5 KiB
EmacsLisp
75 lines
2.5 KiB
EmacsLisp
;;; enotify.el --- send a message to an IRC channel -*- lexical-binding:t -*-
|
|
|
|
;; Copyright (C) 2024 Jeremy Baxter
|
|
|
|
;; Author: Jeremy Baxter <jeremy@baxters.nz>
|
|
;; Maintainer: Jeremy Baxter <jeremy@baxters.nz>
|
|
;; 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 <https://www.gnu.org/licenses/>.
|
|
|
|
;;; Commentary:
|
|
|
|
;; enotify.el provides `enotify', a command for connecting to an IRC
|
|
;; server, joining a channel, sending a message, and then leaving.
|
|
|
|
;;; 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"
|
|
"IRC realname for `enotify' 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)))
|
|
|
|
(provide 'enotify)
|
|
|
|
;;; enotify.el ends here
|