Browse Source

Added SSL and password support!

main
Jesse Laprade 1 year ago committed by Jesse Laprade
parent
commit
2c97d0dcf4
  1. 3
      README.md
  2. 2
      src/config.rkt
  3. 21
      src/ruth.rkt

3
README.md

@ -1,5 +1,4 @@ @@ -1,5 +1,4 @@
# ruth
An IRC bot in Racket. For more information about Ruth's commands, check
out
An IRC bot in Racket. For more information about Ruth's commands, check out
[Ruth's wiki page on tilde.town](http://tilde.town/wiki/socializing/irc/bots/ruth.html).

2
src/config.rkt

@ -5,6 +5,8 @@ @@ -5,6 +5,8 @@
(define config
(hash 'host "127.0.0.1"
'port 6667
'ssl #f
'pass #f
'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?

21
src/ruth.rkt

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
#lang racket/base
(require racket/tcp
(require openssl
racket/tcp
racket/list
racket/string
racket/file
@ -124,8 +125,11 @@ @@ -124,8 +125,11 @@
;; returns two values: an input-port (from-server) and an output port
;; (to-server)
(define-values (from-server to-server)
(tcp-connect (config-ref 'host)
(config-ref 'port)))
(let ([host (config-ref 'host)]
[port (config-ref 'port)])
(if (config-ref 'ssl)
(ssl-connect host port 'secure)
(tcp-connect host port))))
;; The (flush-output ...) here is required because we are using TCP ports,
;; and according to the Racket docs on (flush-output ...), TCP ports use
@ -148,6 +152,10 @@ @@ -148,6 +152,10 @@
(define (send-action channel action)
(send-bytes/utf-8 (format "PRIVMSG ~a :\x01ACTION ~a\x01" channel action)))
(define (send-pass)
(send-bytes/utf-8
(format "PASS ~a" (config-ref 'pass))))
(define (send-nick)
(send-bytes/utf-8
(format "NICK ~a" (config-ref 'nickname))))
@ -200,8 +208,7 @@ @@ -200,8 +208,7 @@
(let* ([nickname (get-nickname split-server-data)]
[username (get-username split-server-data)]
[channel (get-channel split-server-data)]
[message-split (get-message split-server-data)]
[message-joined (string-join message-split)])
[message-split (get-message split-server-data)])
(match message-split
;; 2-item matches
[(list (== command-water)
@ -237,9 +244,11 @@ @@ -237,9 +244,11 @@
[_ 'hangout])
(check-for-e channel nickname message-joined)))))
(check-for-e channel nickname (string-join message-split))))))
(define (initialize-connection)
(when (config-ref 'pass)
(send-pass))
(send-nick)
(send-user)
(join-channels)

Loading…
Cancel
Save