|
From: Mario L. <ml...@de...> - 2003-11-03 23:02:28
|
lawrence mitchell <we...@gm...> writes: > I notice that most of ERC's CTCP handlers are defined almost > identically, so I wondered if it might be useful to create a > define-ctcp-handler. Here's a first stab at it. It only > handles simple cases at the moment, if people think it's worth > persuing I might make it try and handle complicated cases too. The current implementation does not look very useful for erc-dcc.el and erc-xdcc.el. > (defmacro define-erc-ctcp-handler (command format-string &rest format-args) > "Define an ERC CTCP handler for COMMAND. > > This creates functions and variables for dealing with CTCP requests > and responses. <nitpicking>We should at least say which variables...</nitpicking> > FORMAT-STRING should be a string containing the response to be sent, > it should contain as many format directives as there are FORMAT-ARGS." > (let* ((command-name (upcase (symbol-name command))) > (query-hook (intern (format "erc-ctcp-query-%s-hook" > command-name))) > (query (intern (format "erc-ctcp-query-%s" > command-name))) > (reply-hook (intern (format "erc-ctcp-reply-%s-hook" > command-name))) > (reply (intern (format "erc-ctcp-reply-%s" > command-name))) > (reply-msg (intern (format "CTCP-%s" command-name))) > (query-msg (format "%s %s" command format-string))) > `(progn > (defvar ,query-hook (list ,query)) > (defun ,query (proc nick login host to msg) > (unless erc-disable-ctcp-replies > (erc-send-ctcp-notice > nick (format ,query-msg ,@format-args))) > nil) > (defvar ,reply-hook (list ,reply)) > (defun ,reply (proc nick login host to msg) > (erc-display-message > nil 'notice nil > ',reply-msg > ?n nick ?m msg) > nil)))) > > Sample usage: > > (define-erc-ctcp-handler FNORD > "%s is a member of the FNORD society" (erc-current-nick)) > > This expands into: > > (progn > (defvar erc-ctcp-query-FNORD-hook > (list erc-ctcp-query-FNORD)) > (defun erc-ctcp-query-FNORD > (proc nick login host to msg) > (unless erc-disable-ctcp-replies > (erc-send-ctcp-notice nick > (format "FNORD %s is a member of the FNORD society" > (erc-current-nick)))) > nil) > (defvar erc-ctcp-reply-FNORD-hook > (list erc-ctcp-reply-FNORD)) > (defun erc-ctcp-reply-FNORD > (proc nick login host to msg) > (erc-display-message nil 'notice nil 'CTCP-FNORD 110 nick 109 msg) > nil)) I think it should at least allow for a FORMAT-STRING to be a conscell and be used for a BODY to be useful. On the other hand, if someone wants to work on ctcp, I think it would be much more desireable to split CTCP out of erc.el into erc-ctcp.el. This would be `require'ed at almost all times, but it would be great to have CTCP in one place, especially since it is just an extention to IRC. -- CYa, Mario | Debian Developer <URL:http://debian.org/> | Get my public key via finger ml...@db... | 1024D/7FC1A0854909BCCDBE6C102DDFFC022A6B113E44 |