aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Laprade <jesselaprade@gmail.com>2021-03-22 19:47:55 -0400
committerJesse Laprade <jesselaprade@gmail.com>2021-03-22 19:47:55 -0400
commit47078a1c982de755091b985206116317dff87f9e (patch)
tree75a8dd8dff80072427bb29deddeb42af8035f4f7
parente1d5be41073788faf7deb60250773885feea73db (diff)
downloadruth-47078a1c982de755091b985206116317dff87f9e.tar.gz
ruth-47078a1c982de755091b985206116317dff87f9e.tar.bz2
ruth-47078a1c982de755091b985206116317dff87f9e.zip
Rewrite irc message parser!
-rw-r--r--src/config.rkt15
-rw-r--r--src/ruth.rkt109
2 files changed, 65 insertions, 59 deletions
diff --git a/src/config.rkt b/src/config.rkt
index 1857370..314f0ee 100644
--- a/src/config.rkt
+++ b/src/config.rkt
@@ -3,12 +3,19 @@
(provide (all-defined-out))
(define config
- (hash 'host "127.0.0.1"
+ (hash 'host "irc.freenode.net"
'port 6667
'nickname "ruth" ;; This one shows up in chat and can be registered
'username "m455s-bot" ;; This one shows up in join and leave messages
'realname "m455s-bot" ;; This one shows up somewhere?
- 'channels '("#tildetown"
- "#oulipo"
- "#bots")))
+ 'channels '("#m455-dev"
+ "#m455-dev2")))
+ ;(hash 'host "127.0.0.1"
+ ; 'port 6667
+ ; 'nickname "ruth" ;; This one shows up in chat and can be registered
+ ; 'username "m455s-bot" ;; This one shows up in join and leave messages
+ ; 'realname "m455s-bot" ;; This one shows up somewhere?
+ ; 'channels '("#tildetown"
+ ; "#oulipo"
+ ; "#bots")))
diff --git a/src/ruth.rkt b/src/ruth.rkt
index 4d8944c..0e3e22a 100644
--- a/src/ruth.rkt
+++ b/src/ruth.rkt
@@ -58,10 +58,10 @@
(string-append
"I respond to !rollcall, !~a, !cpu, !nicethings, !hug, !crisis, !pluckafuck, !feed ~a, !water ~a."
" For more information, check out http://tilde.town/wiki/socializing/irc/bots/~a.html")
- bot-name
- bot-name
- bot-name
- bot-name))
+ bot-name
+ bot-name
+ bot-name
+ bot-name))
(define (cpu)
(shell-command
@@ -110,12 +110,12 @@
(define (pluckafuck)
(let ([fileof-fucks "/home/archangelic/public_html/unique_fucks.txt"])
(if (file-exists? fileof-fucks)
- (let* ([listof-fucks (file->lines fileof-fucks)]
- [vectorof-fucks (list->vector listof-fucks)]
- [random-number (vector->random-number vectorof-fucks)]
- [random-fuck (vector-ref vectorof-fucks random-number)])
- random-fuck)
- (format "Couldn't find ~a" fileof-fucks))))
+ (let* ([listof-fucks (file->lines fileof-fucks)]
+ [vectorof-fucks (list->vector listof-fucks)]
+ [random-number (vector->random-number vectorof-fucks)]
+ [random-fuck (vector-ref vectorof-fucks random-number)])
+ random-fuck)
+ (format "Couldn't find ~a" fileof-fucks))))
;; ------------------------------------------------------------------------
;; IRC builders
@@ -161,7 +161,7 @@
(define (join-channels)
(for ([channel (config-ref 'channels)])
- (send-bytes/utf-8 (format "JOIN ~a" channel))))
+ (send-bytes/utf-8 (format "JOIN ~a" channel))))
(define (check-for-e channel nickname message)
(let* ([oulipo-channel? (equal? channel "#oulipo")]
@@ -176,69 +176,68 @@
;; Split message should look something like the following:
;; nick username channel message
;; :m455!m455@localhost PRIVMSG #tildetown :hmmm let me open up town's tmux
-(define (get-nickname split-message)
- (let* ([nickname-block (list-ref split-message 0)]
+(define (get-nickname split-server-message)
+ (let* ([nickname-block (list-ref split-server-message 0)]
[colon-removed (substring nickname-block 1)])
(string-trim colon-removed #px"(!.+)$")))
-(define (get-username split-message)
- (let* ([username-block (list-ref split-message 0)]
+(define (get-username split-server-message)
+ (let* ([username-block (list-ref split-server-message 0)]
[username-matches (regexp-match #rx"![~]?(.+)@" username-block)])
(list-ref username-matches 1)))
-(define (get-channel split-message)
- (list-ref split-message 2))
+(define (get-channel split-server-message)
+ (list-ref split-server-message 2))
-;; TODO: Finish this up, and then change how the message matching
-; behaviour works below
-(define (get-message split-message)
- (let* ([message-first-word (list-ref split-message 3)]
- [colon-removed (substring message-first-word 1)])
- (cons colon-removed (list-tail split-message 4))))
+(define (get-message split-server-message)
+ (let* ([first-word (list-ref split-server-message 3)]
+ [colon-removed (substring first-word 1)])
+ (cons colon-removed (list-tail split-server-message 4))))
(define (commands-listen server-data-string)
- (let ([split-message (string-split message)])
- (when (equal? (list-ref split-message 1) "PRIVMSG")
- (let* ([nickname (get-nickname split-message)]
- [username (get-username split-message)]
- [channel (get-channel split-message)]
- [message (get-message split-message)])
- (match message
- ;; 2-item matches
- [(list (== command-water)
- (== bot-name))
- (send-action channel (water))]
+ (let ([split-server-message (string-split server-data-string)])
+ (when (equal? (list-ref split-server-message 1) "PRIVMSG")
+ (let* ([nickname (get-nickname split-server-message)]
+ [username (get-username split-server-message)]
+ [channel (get-channel split-server-message)]
+ [message-split (get-message split-server-message)]
+ [message-joined (string-join message-split)])
+ (match message-split
+ ;; 2-item matches
+ [(list (== command-water)
+ (== bot-name))
+ (send-action channel (water))]
- [(list (== command-feed)
- (== bot-name))
- (send-action channel (feed))]
+ [(list (== command-feed)
+ (== bot-name))
+ (send-action channel (feed))]
- [(list (== command-hug) arg)
- (send-action channel (hug arg))]
+ [(list (== command-hug) arg)
+ (send-action channel (hug arg))]
- ;; 1-items matches
- [(list (== command-hug))
- (send-action channel (hug nickname))]
+ ;; 1-items matches
+ [(list (== command-hug))
+ (send-action channel (hug nickname))]
- [(list (or (== command-rollcall)
- (== command-bot-name)))
- (send-message channel (rollcall))]
+ [(list (or (== command-rollcall)
+ (== command-bot-name)))
+ (send-message channel (rollcall))]
- [(list (== command-cpu))
- (send-message channel (cpu))]
+ [(list (== command-cpu))
+ (send-message channel (cpu))]
- [(list (== command-nicethings))
- (send-message channel (nicethings))]
+ [(list (== command-nicethings))
+ (send-message channel (nicethings))]
- [(list (== command-crisis))
- (send-message channel (crisis))]
+ [(list (== command-crisis))
+ (send-message channel (crisis))]
- [(list (== command-pluckafuck))
- (send-message channel (pluckafuck))]
+ [(list (== command-pluckafuck))
+ (send-message channel (pluckafuck))]
- [_ 'hangout])
+ [_ 'hangout])
- (check-for-e channel nickname message))))
+ (check-for-e channel nickname message-joined)))))
(define (initialize-connection)
(send-nick)