5 ;;; 8sync --- Asynchronous programming for Guile
6 ;;; Copyright (C) 2015 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/>.
31 (define-class <my-irc-bot> (<irc-bot>))
33 (define-method (handle-line (irc-bot <my-irc-bot>) message
34 speaker channel line emote?)
35 (define my-name (irc-bot-username irc-bot))
36 (define (looks-like-me? str)
37 (or (equal? str my-name)
38 (equal? str (string-concatenate (list my-name ":")))))
39 (match (string-split line #\space)
40 (((? looks-like-me? _) action action-args ...)
42 ;; The classic botsnack!
44 (<- (actor-id irc-bot) 'send-line channel
45 "Yippie! *does a dance!*"))
47 ((or "hello" "hello!" "hello." "greetings" "greetings." "greetings!"
48 "hei" "hei." "hei!" "hi" "hi!")
49 (<- (actor-id irc-bot) 'send-line channel
50 (format #f "Oh hi ~a!" speaker)))
52 ;; ---> Add yours here <---
56 (<- (actor-id irc-bot) 'send-line channel
57 "*stupid puppy look*"))))
58 ;; Otherwise... just spit the output to current-output-port or whatever
61 (format #t "~a emoted ~s in channel ~a\n"
63 (format #t "~a said ~s in channel ~a\n"
64 speaker line channel)))))
67 (define (display-help scriptname)
68 (format #t "Usage: ~a [OPTION] username" scriptname)
70 -h, --help display this text
71 --server=SERVER-NAME connect to SERVER-NAME
72 defaults to \"irc.freenode.net\"
73 --channels=CHANNEL1,CHANNEL2
74 join comma-separated list of channels on connect
75 defaults to \"##botchat\"")
78 (define (parse-args scriptname args)
80 (list (option '(#\h "help") #f #f
82 (display-help scriptname)
84 (option '("server") #t #f
85 (lambda (opt name arg result)
86 `(#:server ,arg ,@result)))
87 (option '("channels") #t #f
88 (lambda (opt name arg result)
89 `(#:channels ,(string-split arg #\,)
91 (option '("repl") #f #t
92 (lambda (opt name arg result)
93 `(#:repl ,(or arg #t) ,@result))))
94 (lambda (opt name arg result)
95 (format #t "Unrecognized option `~a'\n" name)
97 (lambda (option result)
98 `(#:username ,option ,@result))
101 (define* (run-bot #:key (username "examplebot")
102 (server "irc.freenode.net")
103 (channels '("##botchat"))
105 (define hive (make-hive))
107 (bootstrap-actor* hive <my-irc-bot> "irc-bot"
110 #:channels channels))
114 (bootstrap-actor* hive <repl-manager> "repl"
117 (bootstrap-actor* hive <repl-manager> "repl"))))
123 (define parsed-args (parse-args "ircbot.scm" args))
124 (apply (lambda* (#:key username #:allow-other-keys)
126 (display "Error: username not specified!")
128 (display-help "ircbot.scm")
131 (apply run-bot parsed-args))