Update of /project/net-nittin-irc/cvsroot/net-nittin-irc/example In directory common-lisp.net:/tmp/cvs-serv21141
Modified Files: cliki.lisp Log Message: Add NickServ authentication
Date: Mon Dec 15 14:48:19 2003 Author: bmastenbrook
Index: net-nittin-irc/example/cliki.lisp diff -u net-nittin-irc/example/cliki.lisp:1.5 net-nittin-irc/example/cliki.lisp:1.6 --- net-nittin-irc/example/cliki.lisp:1.5 Sat Dec 13 18:44:33 2003 +++ net-nittin-irc/example/cliki.lisp Mon Dec 15 14:48:19 2003 @@ -1,4 +1,4 @@ -;;;; $Id: cliki.lisp,v 1.5 2003/12/13 23:44:33 bmastenbrook Exp $ +;;;; $Id: cliki.lisp,v 1.6 2003/12/15 19:48:19 bmastenbrook Exp $ ;;;; $Source: /project/net-nittin-irc/cvsroot/net-nittin-irc/example/cliki.lisp,v $
;;;; cliki.lisp - CLiki as an infobot; only works on SBCL. @@ -131,9 +131,9 @@ (symbol-macrolet ((it ,test)) ,else))))
-(defparameter *cliki-attention-prefix* "cliki: ") +(defparameter *cliki-attention-prefix* "minion: ")
-(defparameter *cliki-bot-help* "The CLiki bot supplies small definitions and performs lookups on CLiki. To use it, try ``cliki: term?''. To add a term for IRC, try saying ``cliki: add "term" as: definition''; otherwise, edit the corresponding CLiki page.") +(defparameter *cliki-bot-help* "The minion bot supplies small definitions and performs lookups on CLiki. To use it, try ``minion: term?''. To add a term for IRC, try saying ``minion: add "term" as: definition''; otherwise, edit the corresponding CLiki page.")
(defun cliki-lookup (term-with-question) (let ((first-pass (regex-replace-all "^(\s*)([^?]+)(\?*)$" term-with-question "\2"))) @@ -144,11 +144,18 @@ (defn (regex-replace "^add "[^"]+" as: (.+)$" first-pass "\1"))) (add-small-definition term defn) "OK, done.") - (concatenate 'string first-pass ": " - (or - (if (string-equal first-pass "help") *cliki-bot-help*) - (cdr (assoc first-pass *small-definitions* :test #'string-equal)) - (cliki-first-sentence first-pass)))))) + (if (scan "^alias "([^"]+)" as: (.+)$" first-pass) + (let ((term (regex-replace "^alias "([^"]+)" .*$" first-pass "\1")) + (defn (regex-replace "^alias "[^"]+" as: (.+)$" first-pass "\1"))) + (add-small-definition term (list defn)) + "OK, done.") + (or + (if (string-equal first-pass "help") *cliki-bot-help*) + (if (scan "^(?i)do my bidding!*$" first-pass) "Yes, my master.") + (concatenate 'string first-pass ": " + (or (let ((term (cdr (assoc first-pass *small-definitions* :test #'string-equal)))) + (if term (if (stringp term) term (cliki-lookup (car term))))) + (cliki-first-sentence first-pass))))))))
(defun valid-cliki-message (message) (eql (search *cliki-attention-prefix* (trailing-argument message) :test #'char-equal) 0)) @@ -161,14 +168,22 @@ (if (valid-cliki-message message) (privmsg *cliki-connection* (first (arguments message)) (cliki-lookup (subseq (trailing-argument message) (length *cliki-attention-prefix*)))))))
+(defvar *cliki-nickserv-password* "") + +(defun notice-hook (message) + (if (and (string-equal (source message) "NickServ") + (scan "owned by someone else" (trailing-argument message))) + (privmsg *cliki-connection* (source message) (format nil "IDENTIFY ~A" *cliki-nickserv-password*)))) + (defun start-cliki-bot (nick server &rest channels) (setf *cliki-nickname* nick) (setf *cliki-connection* (connect :nickname *cliki-nickname* :server server)) (mapcar #'(lambda (channel) (join *cliki-connection* channel)) channels) - (add-hook *cliki-connection* 'irc::irc-privmsg-message #'msg-hook) + (add-hook *cliki-connection* 'irc::irc-privmsg-message 'msg-hook) + (add-hook *cliki-connection* 'irc::irc-notice-message 'notice-hook) #+sbcl (add-asynchronous-message-handler *cliki-connection*) #-sbcl (read-message-loop *cliki-connection*))
(defun shuffle-hooks () (irc::remove-hooks *cliki-connection* 'irc::irc-privmsg-message) - (add-hook *cliki-connection* 'irc::irc-privmsg-message #'msg-hook)) + (add-hook *cliki-connection* 'irc::irc-privmsg-message 'msg-hook))
net-nittin-irc-cvs@common-lisp.net