X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;ds=inline;f=8sync%2Fsystems%2Firc.scm;h=aa43624389bd0705acf3827c689e34830fde158c;hb=5df9f19127858a1b32df6ef543b4b10e49f1aa57;hp=495cbca4f968dfe4b4c4b03c7629c78cc2e12110;hpb=382af9f4ada1170faab3efda78ae5e3b5e1d4d42;p=8sync.git diff --git a/8sync/systems/irc.scm b/8sync/systems/irc.scm old mode 100755 new mode 100644 index 495cbca..aa43624 --- a/8sync/systems/irc.scm +++ b/8sync/systems/irc.scm @@ -1,9 +1,6 @@ -#!/usr/bin/guile \ --e main -s -!# - ;;; 8sync --- Asynchronous programming for Guile -;;; Copyright (C) 2015 Christopher Allan Webber +;;; Copyright © 2015, 2016, 2017 Christopher Allan Webber +;;; Copyright © 2023 Janneke Nieuwenhuizen ;;; ;;; This file is part of 8sync. ;;; @@ -35,6 +32,8 @@ #:export ( irc-bot-username irc-bot-server irc-bot-channels irc-bot-port + irc-bot-send-line + handle-line handle-misc-input handle-user-join handle-user-quit @@ -134,13 +133,13 @@ #f))))) ;;; A goofy default -(define (echo-message irc-bot speaker channel-name - line-text emote?) - "Simply echoes the message to the current-output-port." +(define* (echo-message irc-bot speaker channel-name + line-text emote? #:key (port (current-output-port))) + "Simply echoes the message to the PORT." (if emote? - (format #t "~a emoted ~s in channel ~a\n" + (format port "~a emoted ~s in channel ~a\n" speaker line-text channel-name) - (format #t "~a said ~s in channel ~a\n" + (format port "~a said ~s in channel ~a\n" speaker line-text channel-name))) @@ -161,10 +160,12 @@ #:getter irc-bot-port) (socket #:accessor irc-bot-socket) (actions #:allocation #:each-subclass - #:init-value (build-actions - (init irc-bot-init) + #:init-thunk (build-actions + (*init* irc-bot-init) + (*cleanup* irc-bot-cleanup) (main-loop irc-bot-main-loop) - (send-line irc-bot-send-line)))) + (handle-line handle-line) + (send-line irc-bot-send-line-action)))) (define (irc-bot-realname irc-bot) (or (slot-ref irc-bot 'realname) @@ -187,7 +188,10 @@ (format socket "JOIN ~a~a" channel irc-eol)) (irc-bot-channels irc-bot)) - (<- irc-bot (actor-id irc-bot) 'main-loop)) + (<- (actor-id irc-bot) 'main-loop)) + +(define (irc-bot-cleanup irc-bot message) + (close (irc-bot-socket irc-bot))) (define (irc-bot-main-loop irc-bot message) (define socket (irc-bot-socket irc-bot)) @@ -210,14 +214,20 @@ ;; 'done) ;; Otherwise, let's read till the next line! (else - (<- irc-bot (actor-id irc-bot) 'main-loop)))) + (<- (actor-id irc-bot) 'main-loop)))) -(define* (irc-bot-send-line irc-bot message - channel line #:key emote?) +(define* (irc-bot-send-line-action irc-bot message + channel line #:key emote?) + "Action handler for sending lines. Real behavior happens in +irc-bot-send-line." + (irc-bot-send-line irc-bot channel line #:emote? emote?)) + +(define* (irc-bot-send-line irc-bot channel line #:key emote?) ;; TODO: emote? handling (format (irc-bot-socket irc-bot) "PRIVMSG ~a :~a~a" channel line irc-eol)) + ;;; Likely-to-be-overridden generic methods (define-method (dispatch-raw-line (irc-bot ) raw-line) @@ -232,13 +242,15 @@ (receive (channel-name line-text emote?) (condense-privmsg-line line-params) (let ((username (irc-line-username line-prefix))) - (handle-line irc-bot username channel-name - line-text emote?)))) + (<- (actor-id irc-bot) 'handle-line + username channel-name + line-text emote?)))) (_ (handle-misc-input irc-bot raw-line))))) -(define-method (handle-line (irc-bot ) username channel-name - line-text emote?) - (echo-message irc-bot username channel-name line-text emote?)) +(define-method (handle-line (irc-bot ) message + username channel-name line-text emote?) + (echo-message irc-bot username channel-name line-text emote? + #:port (current-error-port))) (define-method (handle-misc-input (irc-bot ) raw-line) (display raw-line)