From 07ec9e00d0b673276c04cc72d0d712c6103cf54a Mon Sep 17 00:00:00 2001 From: Janneke Nieuwenhuizen Date: Thu, 17 Aug 2023 09:58:08 +0200 Subject: [PATCH] DRAFT irc: Remove 0.4.2 interface. -- after 0.5.0 release. * 8sync/systems/irc.scm (default-irc-port, irc-eol): Remove variables. ()[actions]: Remove handle-line message handler. (handle-line, handle-misc-input): Remove old handler methods. (handle-message): Remove fall-backs for them. (irc-bot-send-line, startswith-colon?, parse-line, strip-colon-if-necessary, irc-line-username, condense-privmsg-line): Remove old helper procedures. --- 8sync/systems/irc.scm | 114 ++---------------------------------------- 1 file changed, 3 insertions(+), 111 deletions(-) diff --git a/8sync/systems/irc.scm b/8sync/systems/irc.scm index d13294c..2a7f138 100644 --- a/8sync/systems/irc.scm +++ b/8sync/systems/irc.scm @@ -35,11 +35,7 @@ irc-bot-username irc-bot-server irc-bot-channels irc-bot-port irc-bot-init irc-bot-cleanup - dispatch-message handle-message - - default-irc-port ;REMOVEME compat - irc-bot-send-line ;REMOVEME compat - handle-line handle-misc-input)) ;REMOVEME compat + dispatch-message handle-message)) ;;; A goofy default handler. (define* (echo-message irc-bot speaker channel-name @@ -74,7 +70,6 @@ (*cleanup* irc-bot-cleanup) (main-loop irc-bot-main-loop) (dispatch-message dispatch-message) - (handle-line handle-line) ;REMOVEME compat (send-line irc-bot-send-line-action)))) (define (irc-bot-realname irc-bot) @@ -156,108 +151,5 @@ irc:send-line." (= irc:message-channel channel) (= irc:message-message message) (= irc:message-emote? emote?)) - (or - (case command - ((PRIVMSG) - (handle-line irc-bot #f speaker channel message emote?)) ;REMOVEME compat - (else - (handle-misc-input irc-bot line))) ;REMOVEME compat - (echo-message irc-bot speaker channel message #f - #:port (current-error-port)))))) - - -;;; -;;; Compatibility with 0.4.2. -;;; -(define default-irc-port %irc:default-port) -(define irc-eol %irc:eol) - -(define* (irc-bot-send-line irc-bot channel line #:key emote?) - (define socket (irc-bot-socket irc-bot)) - (irc:send-line socket channel line)) - -(define-method (handle-line (irc-bot ) ;REMOVEME compat - 8sync-message - username channel-name line-text emote?) - "Keep compatibility with previous release." - #f) - -(define-method (handle-misc-input (irc-bot ) ;REMOVEME compat - (line )) - "Keep compatibility with previous release." - #f) - -(define (startswith-colon? str) - (and (> (string-length str) 0) - (eq? (string-ref str 0) - #\:))) - -;; TODO: This needs a cleanup. Maybe even just using a regex is fine. -(define (parse-line line) ;REMOVEME compat - (define (parse-params pre-params) - ;; This is stupid and imperative but I can't wrap my brain around - ;; the right way to do it in a functional way :\ - (let ((param-list '()) - (currently-building '())) - (for-each - (lambda (param-item) - (cond - ((startswith-colon? param-item) - (if (not (eq? currently-building '())) - (set! param-list - (cons - (reverse currently-building) - param-list))) - (set! currently-building (list param-item))) - (else - (set! currently-building (cons param-item currently-building))))) - pre-params) - ;; We're still building something, so tack that on there - (if (not (eq? currently-building '())) - (set! param-list - (cons (reverse currently-building) param-list))) - ;; return the reverse of the param list - (reverse param-list))) - - (match (string-split line #\space) - (((? startswith-colon? prefix) - command - pre-params ...) - (values prefix command - (parse-params pre-params))) - ((command pre-params ...) - (values #f command - (parse-params pre-params))))) - -(define (strip-colon-if-necessary string) ;REMOVME compat - (if (and (> (string-length string) 0) - (string-ref string 0)) - (substring/copy string 1) - string)) - -;; @@: Not sure if this works in all cases, like what about in a non-privmsg one? -(define (irc-line-username irc-line-prefix) ;REMOVME compat - (let* ((prefix-name (strip-colon-if-necessary irc-line-prefix)) - (exclaim-index (string-index prefix-name #\!))) - (if exclaim-index - (substring/copy prefix-name 0 exclaim-index) - prefix-name))) - -(define (condense-privmsg-line line) ;REMOVME compat - "Condense message line and do multiple value return of - (channel message emote?)" - (define (strip-last-char string) - (substring/copy string 0 (- (string-length string) 1))) - (let* ((channel-name (caar line)) - (rest-params (apply append (cdr line)))) - (match rest-params - (((or "\x01ACTION" ":\x01ACTION") middle-words ... (= strip-last-char last-word)) - (values channel-name - (string-join - (append middle-words (list last-word)) - " ") - #t)) - (((= strip-colon-if-necessary first-word) rest-message ...) - (values channel-name - (string-join (cons first-word rest-message) " ") - #f))))) + (echo-message irc-bot speaker channel message #f + #:port (current-error-port))))) -- 2.31.1