add diceware support
parent
46844f7735
commit
0a952a173c
42
anna.scm
42
anna.scm
|
@ -10,8 +10,8 @@
|
|||
(ice-9 regex)
|
||||
(rnrs exceptions))
|
||||
|
||||
;; (define +channels+ '("#tildetown" "#bots"))
|
||||
(define +channels+ '("#bots"))
|
||||
(define +channels+ '("#tildetown" "#lisp" "#bots"))
|
||||
;; (define +channels+ '("#bots"))
|
||||
|
||||
(load "greets.scm")
|
||||
|
||||
|
@ -221,6 +221,35 @@
|
|||
(string-append (slist-ref strings index)
|
||||
(concat-messages strings (+ 1 index) length))))
|
||||
|
||||
(define (n-func-results n f)
|
||||
(if (zero? n)
|
||||
'()
|
||||
(cons (f) (n-func-results (- n 1) f))))
|
||||
|
||||
(define (fold-right f base lst)
|
||||
(if (null? lst)
|
||||
base
|
||||
(f (car lst)
|
||||
(fold-right f base (cdr lst)))))
|
||||
|
||||
(define (diceware-one-word file)
|
||||
(define (generate-dice n sides)
|
||||
(n-func-results n (lambda () (random sides))))
|
||||
(let* ((entry (fold-right string-append "" (map number->string
|
||||
(map (lambda (x) (+ x 1))
|
||||
(generate-dice 5 6)))))
|
||||
;; yes, shell scripting in scheme
|
||||
(port (open-input-pipe (string-append "grep \"^" entry "\" " file " | awk '{print $2}'")))
|
||||
(out (read-line port)))
|
||||
(close-pipe port)
|
||||
out))
|
||||
|
||||
(define (diceware file)
|
||||
(fold-right (lambda (x y) (string-append x " " y))
|
||||
""
|
||||
(n-func-results 5 (lambda () (diceware-one-word (if (equal? file "eff")
|
||||
"diceware_eff.txt"
|
||||
"diceware_words.txt"))))))
|
||||
|
||||
(define (main-loop stream)
|
||||
(let* ((inl (read-line stream))
|
||||
|
@ -234,7 +263,7 @@
|
|||
(pong stream))
|
||||
((or (equal? ":!rollcall" (slist-ref data 3))
|
||||
(equal? ":!anna" (slist-ref data 3)))
|
||||
(send-message stream chn "Hello! I respond to !rollcall, !anna, !tz <optionally user>, !greets, !lgreets <optionally user>, !rgreets <optionally user>, and !eval <s-expr>. My source code is available at https://git.tilde.town/opfez/anna"))
|
||||
(send-message stream chn "Hello! I respond to !anna, !tz <optionally user>, !greets, !lgreets <optionally user>, !rgreets <optionally user>, !dw <optionally \"eff\"> and !eval <s-expr>. My source code is available at https://git.tilde.town/opfez/anna"))
|
||||
((equal? ":!eval" (slist-ref data 3))
|
||||
(let ((expr (string-concatenate (intersperse " " (cdr (member ":!eval" filtered-data))))))
|
||||
(send-message stream chn (evaluate expr))))
|
||||
|
@ -261,12 +290,19 @@
|
|||
(number->string (all-greets *right-greets*))
|
||||
" vs \\o - "
|
||||
(number->string (all-greets *left-greets*)))))
|
||||
((string-contains (empty-list->string (concat-messages data 3 (length data))) "\\o/")
|
||||
#f)
|
||||
((string-contains (empty-list->string (concat-messages data 3 (length data))) "\\o")
|
||||
|
||||
(inc-left-greets (get-username (car data)))
|
||||
(write-greets))
|
||||
((string-contains (empty-list->string (concat-messages data 3 (length data))) "o/")
|
||||
(inc-right-greets (get-username (car data)))
|
||||
(write-greets))
|
||||
((equal? ":!kirby" (slist-ref data 3))
|
||||
(send-message stream chn "13●0ミ8☆"))
|
||||
((equal? ":!dw" (slist-ref data 3))
|
||||
(send-message stream chn (diceware (slist-ref data 4))))
|
||||
((and (= 7 (length data))
|
||||
(equal? (list-tail data 4) '("ACTION" "shoots" "anna")))
|
||||
(send-action stream chn "dies")
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue