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/>.
29 (define-class <my-irc-bot> (<irc-bot>))
31 (define-method (handle-line (irc-bot <my-irc-bot>) speaker channel
33 (define my-name (irc-bot-username irc-bot))
34 (define (looks-like-me? str)
35 (or (equal? str my-name)
36 (equal? str (string-concatenate (list my-name ":")))))
37 (match (string-split line #\space)
38 (((? looks-like-me? _) action action-args ...)
40 ;; The classic botsnack!
42 (<- irc-bot (actor-id irc-bot) 'send-line channel
43 "Yippie! *does a dance!*"))
45 ((or "hello" "hello!" "hello." "greetings" "greetings." "greetings!"
46 "hei" "hei." "hei!" "hi" "hi!")
47 (<- irc-bot (actor-id irc-bot) 'send-line channel
48 (format #f "Oh hi ~a!" speaker)))
50 ;; ---> Add yours here <---
54 (<- irc-bot (actor-id irc-bot) 'send-line channel
55 "*stupid puppy look*"))))
56 ;; Otherwise... just spit the output to current-output-port or whatever
59 (format #t "~a emoted ~s in channel ~a\n"
61 (format #t "~a said ~s in channel ~a\n"
62 speaker line channel)))))
65 (define (display-help scriptname)
66 (format #t "Usage: ~a [OPTION] username" scriptname)
68 -h, --help display this text
69 --server=SERVER-NAME connect to SERVER-NAME
70 defaults to \"irc.freenode.net\"
71 --channels=CHANNEL1,CHANNEL2
72 join comma-separated list of channels on connect
73 defaults to \"##botchat\"")
76 (define (parse-args scriptname args)
78 (list (option '(#\h "help") #f #f
80 (display-help scriptname)
82 (option '("server") #t #f
83 (lambda (opt name arg result)
84 `(#:server ,arg ,@result)))
85 (option '("channels") #t #f
86 (lambda (opt name arg result)
87 `(#:channels ,(string-split arg #\,)
89 (lambda (opt name arg result)
90 (format #t "Unrecognized option `~a'\n" name)
92 (lambda (option result)
93 `(#:username ,option ,@result))
96 (define* (run-bot #:key (username "examplebot")
97 (server "irc.freenode.net")
98 (channels '("##botchat"))
100 (define hive (make-hive))
102 (hive-create-actor* hive <my-irc-bot> "irc-bot"
105 #:channels channels))
107 (ez-run-hive hive (list (bootstrap-message hive irc-bot 'init))))
110 (define parsed-args (parse-args "ircbot.scm" args))
111 (apply (lambda* (#:key username #:allow-other-keys)
113 (display "Error: username not specified!")
115 (display-help "ircbot.scm")
118 (apply run-bot parsed-args))