I'm new to lisp and even newer to cl-irc.
I wanted my bot to take a command to send a message to another user/channel. This works great.
(defun msg-hook (message) (let* ((connection (connection message)) (channel (find-channel connection (first (arguments message)))) (source (source message)) (text (trailing-argument message))) (unless (self-message-p message)
Then I was thinking, that should be a lot more generic. Why not give it _any_ irc command; join, kick, action, etc.
First problem was that there is no action command. *bot wimpers
(defmethod action ((connection connection) (target string) (message string)) (send-irc-message connection :privmsg (make-ctcp-message (concatenate 'string "ACTION " message)) target))
(defmethod action ((connection connection) (user user) (message string)) (action connection (nickname user) message))
(defmethod action ((connection connection) (channel channel) (message string)) (action connection (name channel) message))
That works well too. But how to give the bot a generic command and execute it?
It looks like
(cl-ppcre:register-groups-bind (target string) ("^!(.*)" command) (create-irc-message command))
but how do I send a message? Maybe something like:
(defmethod send-irc-message ((connection connection) (message message)) ...
Btw, I was surprized to find that the read-message method doesn't just read a string, parse it, and return a message; it also dispatches events.
Again, I'm just a noob but I thought I would through in some feedback anyway. I'm hoping I was just clueless and all of this is already in there.
*zik waits to be beaten with a stick
On 7/15/05, Ed Symanzik zik@msu.edu wrote:
Btw, I was surprized to find that the read-message method doesn't just read a string, parse it, and return a message; it also dispatches events.
I struggled with this aspect of cl-irc as well. I wanted a way to handle arbitrary messages in one place without needing to define two dozen hooks, and settled on the following solution:
1) Define no hooks. 2) Define a subclass of connection for your app with its own method on read-message, as follows:
(defclass weird-connection (connection) ())
(defmethod read-message ((connection weird-connection)) (let ((message (call-next-method))) ;; ** Do something with the message here ** message))