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
(*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)
(= 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))))))
-
-\f
-;;;
-;;; 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 <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 <irc-bot>) ;REMOVEME compat
- (line <string>))
- "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)))))