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/>.
30 (define-class <my-irc-bot> (<irc-bot>))
32 (define-method (handle-line (irc-bot <my-irc-bot>) speaker channel
34 (define my-name (irc-bot-username irc-bot))
35 (define (looks-like-me? str)
36 (or (equal? str my-name)
37 (equal? str (string-concatenate (list my-name ":")))))
38 (match (string-split line #\space)
39 (((? looks-like-me? _) action action-args ...)
41 ;; The classic botsnack!
43 (<- irc-bot (actor-id irc-bot) 'send-line channel
44 "Yippie! *does a dance!*"))
46 ((or "hello" "hello!" "hello." "greetings" "greetings." "greetings!"
47 "hei" "hei." "hei!" "hi" "hi!")
48 (<- irc-bot (actor-id irc-bot) 'send-line channel
49 (format #f "Oh hi ~a!" speaker)))
51 ;; ---> Add yours here <---
55 (<- irc-bot (actor-id irc-bot) 'send-line channel
56 "*stupid puppy look*"))))
57 ;; Otherwise... just spit the output to current-output-port or whatever
60 (format #t "~a emoted ~s in channel ~a\n"
62 (format #t "~a said ~s in channel ~a\n"
63 speaker line channel)))))
66 (define (display-help scriptname)
67 (format #t "Usage: ~a [OPTION] username" scriptname)
69 -h, --help display this text
70 --server=SERVER-NAME connect to SERVER-NAME
71 defaults to \"irc.freenode.net\"
72 --channels=CHANNEL1,CHANNEL2
73 join comma-separated list of channels on connect
74 defaults to \"##botchat\"")
77 (define (parse-args scriptname args)
79 (list (option '(#\h "help") #f #f
81 (display-help scriptname)
83 (option '("server") #t #f
84 (lambda (opt name arg result)
85 `(#:server ,arg ,@result)))
86 (option '("channels") #t #f
87 (lambda (opt name arg result)
88 `(#:channels ,(string-split arg #\,)
90 (lambda (opt name arg result)
91 (format #t "Unrecognized option `~a'\n" name)
93 (lambda (option result)
94 `(#:username ,option ,@result))
97 (define* (run-bot #:key (username "examplebot")
98 (server "irc.freenode.net")
99 (channels '("##botchat"))
101 (define hive (make-hive))
103 (hive-create-actor* hive <my-irc-bot> "irc-bot"
106 #:channels channels))
108 (ez-run-hive hive (list (bootstrap-message hive irc-bot 'init))))
111 (define parsed-args (parse-args "ircbot.scm" args))
112 (apply (lambda* (#:key username #:allow-other-keys)
114 (display "Error: username not specified!")
116 (display-help "ircbot.scm")
119 (apply run-bot parsed-args))