snix/web/panettone/src/irc.lisp
eta 2e2bdf9c6c feat(panettone): announce newly created issues using irccat
- The new PANETTONE.IRC package contains the SEND-IRC-NOTIFICATION function,
  which opens a new TCP socket to irccat (if it's running and configured) in
  order to announce the creation of new issues.
- The IRCCATHOST and IRCCATPORT environment variables must be set for this to
  work.
- Additionally, the ISSUECHANNEL environment variable may be used to direct
  announcements at a given channel (otherwise it'll just use the first one).

Change-Id: I429a66f24d0f80ed10db173d6af7105fb1d3d023
Reviewed-on: https://cl.tvl.fyi/c/depot/+/2077
Tested-by: BuildkiteCI
Reviewed-by: glittershark <grfn@gws.fyi>
2020-11-08 19:02:46 +00:00

24 lines
1.1 KiB
Common Lisp

;;;; Using irccat to send IRC notifications
(in-package :panettone.irc)
(defun get-irccat-config ()
"Reads the IRCCATHOST and IRCCATPORT environment variables, and returns them as two values if they both exist (otherwise, returns NIL)."
(destructuring-bind (host port)
(mapcar #'uiop:getenvp '("IRCCATHOST" "IRCCATPORT"))
(when (and host port)
(values host (parse-integer port)))))
(defun send-irc-notification (body &key channel)
"Sends BODY to the IRC channel CHANNEL (starting with #), if an IRCCat server is configured (using the IRCCATHOST and IRCCATPORT environment variables)
If CHANNEL is NIL, sends the BODY to the first channel configured in the IRCCat configuration.
May signal a condition if sending fails."
(multiple-value-bind (irchost ircport)
(get-irccat-config)
(when irchost
(let ((socket (socket-connect irchost ircport)))
(unwind-protect
(progn
(format (socket-stream socket) "~@[~A ~]~A~%" channel body)
(finish-output (socket-stream socket)))
(ignore-errors (socket-close socket)))))))