tvl-depot/web/panettone/src/irc.lisp
Griffin Smith db62866d82 feat(web/panettone): Noping issue authors' usernames
When sending irc notifications, insert a zero-width space after the
first character of the username of the author of issues, to prevent that
user from receiving a ping.

Fixes: b/95
Change-Id: Ibcacb45129b2cb99b587744eb61f4f1dbc0060d6
Reviewed-on: https://cl.tvl.fyi/c/depot/+/2693
Tested-by: BuildkiteCI
Reviewed-by: tazjin <mail@tazj.in>
2021-03-28 17:07:01 +00:00

35 lines
1.2 KiB
Common Lisp

;;;; Using irccat to send IRC notifications
(in-package :panettone.irc)
(defun noping (s)
(format nil "~A~A~A"
(char s 0)
#\ZERO_WIDTH_SPACE
(subseq s 1)))
(defun get-irccat-config ()
"Reads the IRCCATHOST and IRCCATPORT environment variables, and returns them
as two values"
(destructuring-bind (host port)
(mapcar #'uiop:getenvp '("IRCCATHOST" "IRCCATPORT"))
(if (and host port)
(values host (parse-integer port))
(values "localhost" 4722))))
(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).
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~A~%"
channel
#\ZERO_WIDTH_SPACE
body)
(finish-output (socket-stream socket)))
(ignore-errors (socket-close socket)))))))