erc-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Erc-discuss] patch for rudybot @ #emacs


From: Pascal J. Bourguignon
Subject: [Erc-discuss] patch for rudybot @ #emacs
Date: Sun, 20 May 2012 14:44:06 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux)

Hi!

I want to ignore certain users only in certain channels.  Yes, it's
specifically targetting rudybot in #emacs.  (rudybot is useful in
#scheme, but it's a PITA in #emacs).

So here is a "patch":

------------------------------------------------------------------------
(defcustom erc-ignore-per-channel-alist nil
  "*A-List of regexps matching user identifiers to ignore, for each channel.

Some users are obnoxious only in some channels (eg. rudybot on #emacs).

A user identifier has the form \"address@hidden".  If an
identifier matches, the message from the person will not be
processed."
  :group 'erc-ignore
  :type '(repeat (cons string regexp)))

(defcustom erc-ignore-per-channel-reply-alist nil
  "*A-List of regexps matching user identifiers to ignore completely, for each 
channel.

Some users are obnoxious only in some channels (eg. rudybot on #emacs).


This differs from `erc-ignore-list' in that it also ignores any
messages directed at the user.

A user identifier has the form \"address@hidden".

If an identifier matches, or a message is addressed to a nick
whose identifier matches, the message will not be processed.

CAVEAT: ERC doesn't know about the user and host of anyone who
was already in the channel when you joined, but never said
anything, so it won't be able to match the user and host of those
people.  You can update the ERC internal info using /WHO *."
  :group 'erc-ignore
  :type '(repeat (cons string regexp)))

;; ;; Note: it would be better to have  per-server-per-channel variables…
;; (make-variable-buffer-local 'erc-ignore-per-channel-list) ; in server 
buffers.
;; (make-variable-buffer-local 'erc-ignore-per-channel-reply-list) ; in server 
buffers.


(defun erc-ignored-user-in-channel-p (msg tgt spec)
  "Return non-nil if SPEC matches something in `erc-ignore-list'.

Takes a full SPEC of a user in the form \"address@hidden", and
matches against all the regexp's in `erc-ignore-list'.  If any
match, returns that regexp."
  (loop
     for (channel . regexp) in (erc-with-server-buffer 
erc-ignore-per-channel-alist)
     thereis (and (string= channel tgt)
                  (string-match regexp spec))))


(defun erc-ignored-reply-p (msg tgt proc)
  ;; FIXME: this docstring needs fixing -- Lawrence 2004-01-08
  "Return non-nil if MSG matches something in `erc-ignore-reply-list'.

Takes a message MSG to a channel and returns non-nil if the addressed
user matches any regexp in `erc-ignore-reply-list'."
  (let ((target-nick (erc-message-target msg)))
    (if (not target-nick)
        nil
        (erc-with-buffer (tgt proc)
          (let ((user (erc-get-server-user target-nick)))
            (when user
              (let ((spec (erc-user-spec user)))
                (or (erc-list-match erc-ignore-reply-list spec)
                    (loop
                       for (channel . regexp) in (erc-with-server-buffer 
erc-ignore-per-channel-reply-alist)
                         do (message "channel = %S; tgt = %S; regexp = %S; spec 
= %S" channel tgt regexp spec)
                       thereis (and (string= channel tgt)
                                    (string-match regexp spec)))))))))))


(define-erc-response-handler (PRIVMSG NOTICE)
    "Handle private messages, including messages in channels." nil
    (let ((sender-spec (erc-response.sender parsed))
          (cmd (erc-response.command parsed))
          (tgt (car (erc-response.command-args parsed)))
          (msg (erc-response.contents parsed)))
      (if (or (erc-ignored-user-p                    sender-spec)
              (erc-ignored-user-in-channel-p msg tgt sender-spec)
              (erc-ignored-reply-p           msg tgt proc))
          (when erc-minibuffer-ignored
            (message "Ignored %s from %s to %s" cmd sender-spec tgt))
          (let* ((sndr (erc-parse-user sender-spec))
                 (nick (nth 0 sndr))
                 (login (nth 1 sndr))
                 (host (nth 2 sndr))
                 (msgp (string= cmd "PRIVMSG"))
                 (noticep (string= cmd "NOTICE"))
                 ;; S.B. downcase *both* tgt and current nick
                 (privp (erc-current-nick-p tgt))
                 s buffer
                 fnick)
            (setf (erc-response.contents parsed) msg)
            (setq buffer (erc-get-buffer (if privp nick tgt) proc))
            (when buffer
              (with-current-buffer buffer
                ;; update the chat partner info.  Add to the list if private
                ;; message.  We will accumulate private identities indefinitely
                ;; at this point.
                (erc-update-channel-member (if privp nick tgt) nick nick
                                           privp nil nil host login nil nil t)
                (let ((cdata (erc-get-channel-user nick)))
                  (setq fnick (funcall erc-format-nick-function
                                       (car cdata) (cdr cdata))))))
            (cond
              ((erc-is-message-ctcp-p msg)
               (setq s (if msgp
                           (erc-process-ctcp-query proc parsed nick login host)
                           (erc-process-ctcp-reply proc parsed nick login host
                                                   (match-string 1 msg)))))
              (t
               (setcar erc-server-last-peers nick)
               (setq s (erc-format-privmessage
                        (or fnick nick) msg
                        ;; If buffer is a query buffer,
                        ;; format the nick as for a channel.
                        (and (not (and buffer
                                       (erc-query-buffer-p buffer)
                                       erc-format-query-as-channel-p))
                             privp)
                        msgp))))
            (when s
              (if (and noticep privp)
                  (progn
                    (run-hook-with-args 'erc-echo-notice-always-hook
                                        s parsed buffer nick)
                    (run-hook-with-args-until-success
                     'erc-echo-notice-hook s parsed buffer nick))
                  (erc-display-message parsed nil buffer s)))
            (when (string= cmd "PRIVMSG")
              (erc-auto-query proc parsed))))))
------------------------------------------------------------------------

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
A bad day in () is better than a good day in {}.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]