0

I am trying to configure ERC to give me a desktop notification when any message is sent in particular channels.

I looked through the code of both erc-desktop-notifications.el and erc-notify.el and neither of these packages support this feature.

It seems that I could potentially edit the erc-notifications-PRIVMSG function from erc-desktop-notifications.el to add the desired feature, however I am not able to figure out how to detect the current channel name from this function.

I was wondering if anybody knows of a way that this can be done.

Here is the definition of erc-notifications-PRIVMSG:

(defun erc-notifications-PRIVMSG (_proc parsed)
  (let ((nick (car (erc-parse-user (erc-response.sender parsed))))
        (target (car (erc-response.command-args parsed)))
        (msg (erc-response.contents parsed)))
    (when (and (erc-current-nick-p target)
               (not (and (boundp 'erc-track-exclude)
                         (member nick erc-track-exclude)))
               (not (erc-is-message-ctcp-and-not-action-p msg)))
      (erc-notifications-notify nick msg t)))
  ;; Return nil to continue processing by ERC
  nil)

(please note this is cross-posted from reddit)

1 Answer 1

0

target is exactly what you want. It will be channel-name or username based on whether it's a direct message to you.

You can add the following line (message "%S %S" parsed (car (erc-response.command-args parsed))) to the function define-erc-response-handler (PRIVMSG NOTICE) in erc-backend.el.

(define-erc-response-handler (PRIVMSG NOTICE)
  "Handle private messages, including messages in channels." nil
  (message "%S %S" parsed (car (erc-response.command-args parsed)))
  (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-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 nil 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))))))

You will see from the message area that tgt is exactly what you want. It's exactly target in erc-notifications-PRIVMSG you post.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.