5 ;;; 8sync --- Asynchronous programming for Guile
6 ;;; Copyright © 2015, 2016, 2017 Christopher Allan Webber <cwebber@dustycloud.org>
8 ;;; This file is part of 8sync.
10 ;;; 8sync is free software: you can redistribute it and/or modify it
11 ;;; under the terms of the GNU Lesser General Public License as
12 ;;; published by the Free Software Foundation, either version 3 of the
13 ;;; License, or (at your option) any later version.
15 ;;; 8sync is distributed in the hope that it will be useful,
16 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;;; GNU Lesser General Public License for more details.
20 ;;; You should have received a copy of the GNU Lesser General Public
21 ;;; License along with 8sync. If not, see <http://www.gnu.org/licenses/>.
32 (define-class <my-irc-bot> (<irc-bot>))
34 (define-method (handle-line (irc-bot <my-irc-bot>) message
35 speaker channel line emote?)
36 (define my-name (irc-bot-username irc-bot))
37 (define (looks-like-me? str)
38 (or (equal? str my-name)
39 (equal? str (string-concatenate (list my-name ":")))))
40 (match (string-split line #\space)
41 (((? looks-like-me? _) action action-args ...)
43 ;; The classic botsnack!
45 (<- (actor-id irc-bot) 'send-line channel
46 "Yippie! *does a dance!*"))
48 ((or "hello" "hello!" "hello." "greetings" "greetings." "greetings!"
49 "hei" "hei." "hei!" "hi" "hi!")
50 (<- (actor-id irc-bot) 'send-line channel
51 (format #f "Oh hi ~a!" speaker)))
53 ;; ---> Add yours here <---
57 (<- (actor-id irc-bot) 'send-line channel
58 "*stupid puppy look*"))))
59 ;; Otherwise... just spit the output to current-output-port or whatever
62 (format #t "~a emoted ~s in channel ~a\n"
64 (format #t "~a said ~s in channel ~a\n"
65 speaker line channel)))))
68 (define (display-help scriptname)
69 (format #t "Usage: ~a [OPTION] username" scriptname)
71 -h, --help display this text
72 --server=SERVER-NAME connect to SERVER-NAME
73 defaults to \"irc.freenode.net\"
74 --channels=CHANNEL1,CHANNEL2
75 join comma-separated list of channels on connect
76 defaults to \"##botchat\"")
79 (define (parse-args scriptname args)
81 (list (option '(#\h "help") #f #f
83 (display-help scriptname)
85 (option '("server") #t #f
86 (lambda (opt name arg result)
87 `(#:server ,arg ,@result)))
88 (option '("channels") #t #f
89 (lambda (opt name arg result)
90 `(#:channels ,(string-split arg #\,)
92 (option '("repl") #f #t
93 (lambda (opt name arg result)
94 `(#:repl ,(or arg #t) ,@result))))
95 (lambda (opt name arg result)
96 (format #t "Unrecognized option `~a'\n" name)
98 (lambda (option result)
99 `(#:username ,option ,@result))
102 (define* (run-bot #:key (username "examplebot")
103 (server "irc.freenode.net")
104 (channels '("##botchat"))
109 (create-actor* <my-irc-bot> "irc-bot"
112 #:channels channels))
116 (create-actor* <repl-manager> "repl"
119 (create-actor* <repl-manager> "repl"))))
121 (wait (make-condition)))))
124 (define parsed-args (parse-args "ircbot.scm" args))
125 (apply (lambda* (#:key username #:allow-other-keys)
127 (display "Error: username not specified!")
129 (display-help "ircbot.scm")
132 (apply run-bot parsed-args))