diff options
| author | winter Sparkles | 2026-03-04 19:27:35 +0000 |
|---|---|---|
| committer | winter Sparkles | 2026-06-12 17:20:17 +0100 |
| commit | d2e5d2505c59387e9d1710bb13fba84e5f287963 (patch) | |
| tree | 95d5103f9845585b0ab63fc609fc04a36a53b8b4 /wrapper.scm | |
| parent | 5aa3ab24f536bef5e36b784e95c998b5ac34b96a (diff) | |
Diffstat (limited to 'wrapper.scm')
| -rwxr-xr-x | wrapper.scm | 48 |
1 files changed, 41 insertions, 7 deletions
diff --git a/wrapper.scm b/wrapper.scm index 07fb5c2..0818553 100755 --- a/wrapper.scm +++ b/wrapper.scm @@ -13,6 +13,44 @@ (include-relative "config.scm") +(define (relayed-privmsg conn recipient spoofnick message) + (case irc-relay-mode + [(relaymsg) + (irc:command conn (sprintf "RELAYMSG ~a ~a/~a :~a" + recipient (irc:connection-nick conn) + spoofnick message))] + [(roleplay) + (irc:command conn (sprintf "NPC ~a ~a :~a" + recipient spoofnick message))] + [else + (irc:say conn (sprintf "<~a> ~a" spoofnick message) recipient)])) + +(define (relayed-action conn recipient spoofnick message) + (case irc-relay-mode + [(relaymsg) + (irc:command conn (sprintf "RELAYMSG ~a ~a/~a :\001ACTION ~a\001" + recipient (irc:connection-nick conn) + spoofnick message))] + [(roleplay) + (irc:command conn (sprintf "NPCA ~a ~a :~a" + recipient spoofnick message))] + [else + (irc:say conn (sprintf "* ~a ~a" spoofnick message) recipient)])) + +(define (message-from-self? conn message) + (or (equal? (irc:message-sender message) (irc:connection-nick conn)) + (case irc-relay-mode + [(relaymsg) + (let ([prefix (string-append (irc:connection-nick conn) "/")] + [sender (irc:message-sender message)]) + (and (>= (string-length sender) (string-length prefix)) + (equal? (substring sender 0 (string-length prefix)) prefix)))] + [(roleplay) + (equal? (caddr (irc:message-prefix message)) + "npc.fakeuser.invalid")] + [else #f]))) + + (define (process-log-line tag message timestamp log-port control-port) (when verbose-log-relay? (irc:say irc-conn (sprintf "[~a] ~a" tag message) irc-channel)) @@ -21,16 +59,14 @@ (when (and (equal? tag "INFO") match) (let ([username (irregex-match-substring match 1)] [message (irregex-match-substring match 2)]) - (irc:command irc-conn - (sprintf "NPC ~a ~a :~a" irc-channel username message)) + (relayed-privmsg irc-conn irc-channel username message) #;(printf "<~a> ~a~n" username message)))) ;; check for /me message (let ([match (irregex-search chat-action-format message)]) (when (and (equal? tag "INFO") match) (let ([username (irregex-match-substring match 1)] [message (irregex-match-substring match 2)]) - (irc:command irc-conn - (sprintf "NPCA ~a ~a :~a" irc-channel username message)) + (relayed-action irc-conn irc-channel username message) #;(printf "* ~a ~a~n" username message)))) ;; check for joins and parts (let ([match (irregex-search player-join-format message)]) @@ -92,9 +128,7 @@ (substring (cadr (irc:message-parameters msg)) 2))] ;; accept messages; ignore RPs (to avoid duplicating our own stuff) [(and (equal? (irc:message-command msg) "PRIVMSG") - (not (member (caddr (irc:message-prefix msg)) - (list "npc.fakeuser.invalid" - (irc:connection-nick irc-conn))))) + (not (message-from-self? irc-conn msg))) (if (irc:extended-data? (cadr (irc:message-parameters msg))) ;; CTCP (let ([extdata (cadr (irc:message-parameters msg))]) |
