From 67b73c8c16e81c95c4492682e4afa6b7d5ed4129 Mon Sep 17 00:00:00 2001 From: Jaidyn Levesque <10477760+JadedCtrl@users.noreply.github.com> Date: Mon, 13 Feb 2023 11:15:38 -0600 Subject: [PATCH] Sending messages through text-files in .in/ dirs --- irc-chatd.scm | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/irc-chatd.scm b/irc-chatd.scm index d6cfcd5..cf198b5 100644 --- a/irc-chatd.scm +++ b/irc-chatd.scm @@ -175,6 +175,14 @@ (make-channel connection channel)) +;; Send message to an IRC channel +(define (send-message connection channel message) + (irc:write-cmd connection "PRIVMSG" channel message) + (make-message-file connection channel + (hash-table-ref connection 'nick) + message)) + + ;; Hook function for irc:loop; handles all IRC commands (define (on-command conn cmd params #!optional sender) (cond @@ -342,14 +350,19 @@ ;; Handles an inotify event that pertains to a channel's .in/ directory (define (handle-channel-dir-event connection event) (let* ([event-dir (pathname-directory (event->pathname event))] - [dirname (pathname-file (pathname-directory event-dir))] - [parent-dirname (pathname-file (pathname-directory (pathname-directory event-dir)))]) + [dirname (pathname-file event-dir)] + [parent-dirname (pathname-file (pathname-directory event-dir))]) (cond ;; If input is given to an `.in` dir, and its channel is still valid… - ;; well, send that darn message! What're you waiting for?! + ;; well, send that darn message(s)! What're you waiting for?! [(and (string=? dirname ".in") (member parent-dirname (irc:channels connection))) - (print "INPUT FROM, to channel " event-dir)] + (print "Sending message(s) [" (event->pathname event) "] to " parent-dirname "…") + (map (lambda (message) + (send-message connection parent-dirname message)) + (with-input-from-file (event->pathname event) + read-lines)) + (delete-file* (event->pathname event))] ;; If input is given to `.in`, but its channel is invalid… let's give up. [(string=? dirname ".in")