Skip to content

Instantly share code, notes, and snippets.

@humberto-ortiz
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save humberto-ortiz/65efa27cf827d96a732f to your computer and use it in GitHub Desktop.
Save humberto-ortiz/65efa27cf827d96a732f to your computer and use it in GitHub Desktop.
;;;; chatbot.lisp - hook a random sentence generator to a jabber client
;;;; Copyright 2014 - Humberto Ortiz-Zuazaga - humberto.ortiz@upr.edu
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;; If you don't have lisp in a box, get quicklisp and load it
;; See instructions http://www.quicklisp.org/beta/
;; (load "~/quicklisp/setup.lisp")
;; If you are running lisp in a box you can install new packages like so
(ql:quickload "cl-xmpp-tls")
;; cl-xmpp is a jabber client (can talk to google talk and facebook)
;; http://common-lisp.net/project/cl-xmpp/
;; Get the source code for the textbook from the site:
;; http://norvig.com/paip/README.html
(load "/PATH/TO/paip/auxfns.lisp")
(requires "simple")
;; use the big grammar
(setf *grammar* *bigger-grammar*)
;; connect to google talk
(defvar connection (xmpp:connect-tls :hostname "talk.google.com"
:jid-domain-part "gmail.com"))
;; authenticate the connection
(xmpp:auth connection "myusername" "notmypassword" "paip-generate" :mechanism :sasl-plain)
;; you can send a message
(xmpp:message connection "alice@example.com" "testing cl-xmpp")
;; or plug the generator into the function that handles all incoming
;; messages
(defmethod xmpp:handle ((connection xmpp:connection) (message xmpp:message))
(xmpp:message connection (xmpp:from message)
(format nil "~a" (generate 'sentence))))
;; now call the event loop
(xmpp:receive-stanza-loop connection)
;;; unfortunately, this crashes after replying to the first message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment