2021-04-19 12:21:01 +02:00
|
|
|
;;; erc-desktop-notifications.el --- Send notification on PRIVMSG or mentions -*- lexical-binding:t -*-
|
2012-07-21 13:08:32 +02:00
|
|
|
|
2022-01-01 02:45:51 -05:00
|
|
|
;; Copyright (C) 2012-2022 Free Software Foundation, Inc.
|
2012-07-21 13:08:32 +02:00
|
|
|
|
|
|
|
;; Author: Julien Danjou <julien@danjou.info>
|
2022-01-24 10:59:05 -05:00
|
|
|
;; Maintainer: Amin Bandali <bandali@gnu.org>, F. Jason Park <jp@neverwas.me>
|
2012-07-21 13:08:32 +02:00
|
|
|
;; Keywords: comm
|
|
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2017-09-13 15:52:52 -07:00
|
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
2012-07-21 13:08:32 +02:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
;; This implements notifications using `notifications-notify' on
|
|
|
|
;; PRIVMSG received and on public nickname mentions.
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
(require 'erc)
|
|
|
|
(require 'xml)
|
|
|
|
(require 'notifications)
|
2020-09-13 16:49:00 +02:00
|
|
|
(require 'erc-goodies)
|
2012-07-21 13:08:32 +02:00
|
|
|
(require 'erc-match)
|
|
|
|
(require 'dbus)
|
|
|
|
|
|
|
|
(defgroup erc-notifications nil
|
|
|
|
"Send notifications on PRIVMSG or mentions."
|
2012-10-06 13:30:26 -07:00
|
|
|
:version "24.3"
|
2012-07-21 13:08:32 +02:00
|
|
|
:group 'erc)
|
|
|
|
|
|
|
|
(defvar erc-notifications-last-notification nil
|
|
|
|
"Last notification id.")
|
|
|
|
|
|
|
|
(defcustom erc-notifications-icon nil
|
|
|
|
"Icon to use for notification."
|
2013-05-08 21:40:20 -04:00
|
|
|
:type '(choice (const :tag "No icon" nil) file))
|
2012-07-21 13:08:32 +02:00
|
|
|
|
2014-11-23 10:00:28 +01:00
|
|
|
(defcustom erc-notifications-bus :session
|
|
|
|
"D-Bus bus to use for notification."
|
2014-11-23 10:07:00 +01:00
|
|
|
:version "25.1"
|
2014-11-23 10:00:28 +01:00
|
|
|
:type '(choice (const :tag "Session bus" :session) string))
|
|
|
|
|
2013-09-13 00:34:15 -07:00
|
|
|
(defvar dbus-debug) ; used in the macroexpansion of dbus-ignore-errors
|
|
|
|
|
2020-01-17 23:38:04 -05:00
|
|
|
(defun erc-notifications-notify (nick msg &optional privp)
|
|
|
|
"Notify that NICK send some MSG, where PRIVP should be non-nil for PRIVMSGs.
|
2012-07-21 13:08:32 +02:00
|
|
|
This will replace the last notification sent with this function."
|
2020-01-17 23:38:04 -05:00
|
|
|
;; TODO: can we do this without PRIVP? (by "fixing" ERC's not
|
|
|
|
;; setting the current buffer to the existing query buffer)
|
2012-07-21 13:08:32 +02:00
|
|
|
(dbus-ignore-errors
|
|
|
|
(setq erc-notifications-last-notification
|
2020-09-13 16:49:00 +02:00
|
|
|
(let* ((channel (if privp (erc-get-buffer nick) (current-buffer)))
|
|
|
|
(title (format "%s in %s" (xml-escape-string nick t) channel))
|
|
|
|
(body (xml-escape-string (erc-controls-strip msg) t)))
|
2019-04-04 16:49:48 +10:30
|
|
|
(notifications-notify :bus erc-notifications-bus
|
2020-09-13 16:49:00 +02:00
|
|
|
:title title
|
|
|
|
:body body
|
2019-04-04 16:49:48 +10:30
|
|
|
:replaces-id erc-notifications-last-notification
|
|
|
|
:app-icon erc-notifications-icon
|
|
|
|
:actions '("default" "Switch to buffer")
|
|
|
|
:on-action (lambda (&rest _)
|
|
|
|
(pop-to-buffer channel)))))))
|
|
|
|
|
|
|
|
(defun erc-notifications-PRIVMSG (_proc parsed)
|
2012-07-21 13:08:32 +02:00
|
|
|
(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)))
|
2020-01-17 23:38:04 -05:00
|
|
|
(erc-notifications-notify nick msg t)))
|
2012-07-21 13:08:32 +02:00
|
|
|
;; Return nil to continue processing by ERC
|
|
|
|
nil)
|
|
|
|
|
|
|
|
(defun erc-notifications-notify-on-match (match-type nickuserhost msg)
|
|
|
|
(when (eq match-type 'current-nick)
|
|
|
|
(let ((nick (nth 0 (erc-parse-user nickuserhost))))
|
|
|
|
(unless (or (string-match-p "^Server:" nick)
|
|
|
|
(when (boundp 'erc-track-exclude)
|
|
|
|
(member nick erc-track-exclude)))
|
|
|
|
(erc-notifications-notify nick msg)))))
|
|
|
|
|
2012-10-04 15:11:49 +02:00
|
|
|
;;;###autoload(autoload 'erc-notifications-mode "erc-desktop-notifications" "" t)
|
2012-07-21 13:08:32 +02:00
|
|
|
(define-erc-module notifications nil
|
|
|
|
"Send notifications on private message reception and mentions."
|
|
|
|
;; Enable
|
2021-03-18 23:14:33 -04:00
|
|
|
((add-hook 'erc-server-PRIVMSG-functions #'erc-notifications-PRIVMSG)
|
|
|
|
(add-hook 'erc-text-matched-hook #'erc-notifications-notify-on-match))
|
2012-07-21 13:08:32 +02:00
|
|
|
;; Disable
|
2021-03-18 23:14:33 -04:00
|
|
|
((remove-hook 'erc-server-PRIVMSG-functions #'erc-notifications-PRIVMSG)
|
|
|
|
(remove-hook 'erc-text-matched-hook #'erc-notifications-notify-on-match)))
|
2012-07-21 13:08:32 +02:00
|
|
|
|
2012-10-04 15:11:49 +02:00
|
|
|
(provide 'erc-desktop-notifications)
|
2012-07-21 13:08:32 +02:00
|
|
|
|
2012-10-04 15:11:49 +02:00
|
|
|
;;; erc-desktop-notifications.el ends here
|
Put most erc autoloads in a dedicated file erc-loaddefs.el
These are features that are only useful after erc.el is loaded.
* lisp/erc/erc.el (top-level): Load erc-loaddefs.
* lisp/erc/erc-autoaway.el, lisp/erc/erc-button.el:
* lisp/erc/erc-capab.el, lisp/erc/erc-compat.el:
* lisp/erc/erc-dcc.el, lisp/erc/erc-desktop-notifications.el:
* lisp/erc/erc-ezbounce.el, lisp/erc/erc-fill.el:
* lisp/erc/erc-identd.el, lisp/erc/erc-imenu.el:
* lisp/erc/erc-join.el, lisp/erc/erc-list.el, lisp/erc/erc-log.el:
* lisp/erc/erc-match.el, lisp/erc/erc-menu.el:
* lisp/erc/erc-netsplit.el, lisp/erc/erc-notify.el:
* lisp/erc/erc-page.el, lisp/erc/erc-pcomplete.el:
* lisp/erc/erc-replace.el, lisp/erc/erc-ring.el:
* lisp/erc/erc-services.el, lisp/erc/erc-sound.el:
* lisp/erc/erc-speedbar.el, lisp/erc/erc-spelling.el:
* lisp/erc/erc-stamp.el, lisp/erc/erc-track.el:
* lisp/erc/erc-truncate.el, lisp/erc/erc-xdcc.el:
Set generated-autoload-file to "erc-loaddefs.el".
2017-11-28 21:16:02 -05:00
|
|
|
|
|
|
|
;; Local Variables:
|
|
|
|
;; generated-autoload-file: "erc-loaddefs.el"
|
|
|
|
;; End:
|