Update of /project/cl-irc/cvsroot/cl-irc/example
In directory common-lisp.net:/home/bmastenbrook/cl-irc/example
Modified Files:
cliki.lisp specbot.lisp
Log Message:
apropos searching; new module for specbot?
Date: Tue Nov 23 03:54:08 2004
Author: bmastenbrook
Index: cl-irc/example/cliki.lisp
diff -u cl-irc/example/cliki.lisp:1.27 cl-irc/example/cliki.lisp:1.28
--- cl-irc/example/cliki.lisp:1.27 Wed Oct 20 22:21:33 2004
+++ cl-irc/example/cliki.lisp Tue Nov 23 03:54:08 2004
@@ -1,4 +1,4 @@
- ;;;; $Id: cliki.lisp,v 1.27 2004/10/20 20:21:33 bmastenbrook Exp $
+;;;; $Id: cliki.lisp,v 1.28 2004/11/23 02:54:08 bmastenbrook Exp $
;;;; $Source: /project/cl-irc/cvsroot/cl-irc/example/cliki.lisp,v $
;;;; cliki.lisp - CLiki as an infobot; only works on SBCL.
@@ -70,6 +70,14 @@
(push (cons term defn) *aliases*)
(write-top-definition :of *aliases* :type :alias))
+(defun cliki-apropos (search-string)
+ (let ((found (remove-duplicates
+ (loop for (term . defn) in *small-definitions*
+ if (search search-string defn :test #'string-equal)
+ collect term) :test #'string-equal)))
+ (if found (format nil "Matches: ~{~S~^ ~}" found)
+ "No Matches")))
+
(defvar *lookup-depth* 0)
(defvar *followed-aliases* nil)
@@ -416,7 +424,10 @@
(format nil "If you say multiple words to me which I don't recognize and it's not found as a lookup, you might get a sarcastic reply. Don't abuse this too much.")))
("advice" .
,(lambda (nick)
- (format nil "Try saying something like ``~A: advice #11904'' to get some advice." nick)))))
+ (format nil "Try saying something like ``~A: advice #11904'' to get some advice." nick)))
+ ("apropos" .
+ ,(lambda (nick)
+ (format nil "Try ``~A: apropos foo'' to search for all small definitions containing ''foo''." nick)))))
(defun cliki-bot-help (nick)
(format nil "There are multiple help modules. Try ``/msg ~A help kind'', where kind is one of: ~{\"~A\"~^, ~}."
@@ -650,6 +661,9 @@
(if (scan "^(?i)(?i)do my bidding!*$" first-pass) "Yes, my master.")
(if (scan "^(?i)chant(\\s|!|\\?|\\.|$)*" first-pass)
(format nil "MORE ~A" *more*))
+ (let ((str (nth-value 1 (scan-to-strings "^(?i)apropos\\s+(.+\\S)\\s*$" first-pass))))
+ (and str
+ (cliki-apropos (elt str 0))))
(if (scan "^(?i)advice$" first-pass)
(random-advice))
(let ((str (nth-value 1 (scan-to-strings "^(?i)advise\\s+(for\\s+|)(\\S+)$" first-pass))))
Index: cl-irc/example/specbot.lisp
diff -u cl-irc/example/specbot.lisp:1.11 cl-irc/example/specbot.lisp:1.12
--- cl-irc/example/specbot.lisp:1.11 Tue Nov 16 23:45:27 2004
+++ cl-irc/example/specbot.lisp Tue Nov 23 03:54:08 2004
@@ -1,4 +1,4 @@
-;;;; $Id: specbot.lisp,v 1.11 2004/11/16 22:45:27 bmastenbrook Exp $
+;;;; $Id: specbot.lisp,v 1.12 2004/11/23 02:54:08 bmastenbrook Exp $
;;;; $Source: /project/cl-irc/cvsroot/cl-irc/example/specbot.lisp,v $
;;;; specbot.lisp - an example IRC bot for cl-irc
@@ -112,9 +112,15 @@
(format nil "To use the ~A bot, say something like \"database term\", where database is one of (~{~S~^, ~}) and term is the desired lookup. The available databases are:"
*nickname*
(mapcar #'second *spec-providers*)))
- (loop for (a b c d) on *spec-providers* by #'cddddr
- do (privmsg *connection* destination
- "~@{~{~*~S, ~A~}~}~}" a b c d))
+ (loop for i from 1 for j in *spec-providers*
+ with elts = nil
+ do (push j elts)
+ if (zerop (mod i 4))
+ do (progn
+ (privmsg *connection* destination
+ (format nil "~{~{~*~S, ~A~}~^; ~}"
+ (nreverse elts)))
+ (setf elts nil)))
)
(loop for type in *spec-providers*
for actual-fun = (if (typep (first type) 'symbol)