Skip to content

eqyiel/circe-notifications

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 

Repository files navigation

circe-notifications

./screenshot.png

Inspired by tomterl on #emacs-circe who posted this configuration snippet, and Julien Danjou’s erc-desktop-notifications. Requires Circe >= 2.0.

Features

  • Adds desktop notifications to Circe.
  • Won’t send a notification unless the channel is in tracking-buffers, i.e. not currently visible.
  • Avoids getting spammed by one nickname if they are messaging you a lot. After the first notification from some-user you will not get another notification from them until circe-notifications-wait-for seconds have elapsed.
  • Optional list of strings which can trigger a notification.
  • Optionally detects whether Emacs is focused by the window manager. For example, if you’re reading some documentation in Firefox and Emacs is hidden you may wish to receive notifications even for buffers that would be visible in Emacs. This feature requires Emacs >= 24.4.
  • Works out of the box with any alert styles that alert supports, and it’s easy to write new ones for different platforms.

Configuration

GNU/Linux

(autoload 'enable-circe-notifications "circe-notifications" nil t)

(eval-after-load "circe-notifications"
  '(setq circe-notifications-watch-strings
      '("people" "you" "like" "to" "hear" "from")))

(add-hook 'circe-server-connected-hook 'enable-circe-notifications)

Uses dbus to connect to your DE/WM’s particular notification system.

OSX

(autoload 'enable-circe-notifications "circe-notifications" nil t)

(eval-after-load "circe-notifications"
  '(setq circe-notifications-watch-strings
         '("people" "you" "like" "to" "hear" "from")
         circe-notifications-alert-style 'osx-notifier)) ;; see alert-styles for more!

(add-hook 'circe-server-connected-hook 'enable-circe-notifications)

Caveats

If you use the configuration above with something like ZNC you will endure a deluge of notifications upon buffer playback.

Short of patching a new RPL code into both ZNC and Circe specifically for this, the only way to deal with it is to compare the number of notices received from ZNC so far to the number of notices you expect to receive from ZNC.

The number of notices depends on how many networks you are connecting to and how many lines are in ZNC’s MOTD. It’s a massive kludge but here’s how I do it. Replace the line (add-hook 'circe-server-connected-hook 'enable-circe-notifications) from the configuration snippet above with something like this:

;; Warning: this is very dumb
;;
;; ZNC's MOTD is 25 lines.
;; I have two networks defined in `circe-network-options'.
;; So wait to see 50 notices from ZNC before enabling notifications.

(defvar eqyiel-circe-znc-notices 0
  "How many notices have we received from ZNC?")

(defvar eqyiel-circe-znc-motd-length 25
  "How many lines are in ZNC's MOTD?")

(defun eqyiel-circe-znc-count-networks ()
  "Return the number of networks in `circe-network-options' multiplied by
`eqyiel-circe-znc-motd-length', so we can know how many notices to expect before
enabling notifications."
  (* eqyiel-circe-znc-motd-length (length circe-network-options)))

(defun eqyiel-circe-wait-for-znc (nick userhost _command target text)
  "If this TEXT from NICK and USERHOST looks like a line of ZNC's MOTD,
increment `eqyiel-circe-znc-notices', and enable notifications if there have
been at least `eqyiel-circe-znc-count-networks' `eqyiel-circe-znc-notices'."
  (when (and (string-equal nick "*status")
             (string-equal userhost "[email protected]"))
    (setq eqyiel-circe-znc-notices (+ 1 eqyiel-circe-znc-notices))
    (message "That's %d ..." eqyiel-circe-znc-notices)
    (when (<= (eqyiel-circe-znc-count-networks) eqyiel-circe-znc-notices)
      (message "OK.")
      (advice-remove 'circe-display-NOTICE 'eqyiel-circe-wait-for-znc)
      (enable-circe-notifications))))

(defun eqyiel-enable-circe-notifications ()
  (interactive)
  (advice-add 'circe-display-NOTICE :after 'eqyiel-circe-wait-for-znc)
  (advice-add 'circe-reconnect-all :before
              'eqyiel-disable-circe-notifications))

(eval-after-load 'circe
  '(eqyiel-enable-circe-notifications))

(defun eqyiel-disable-circe-notifications ()
  (interactive)
  (disable-circe-notifications)
  (setq eqyiel-circe-znc-notices 0)
  (advice-add 'circe-display-NOTICE :after 'eqyiel-circe-wait-for-znc))

Alternatively, you can M-x enable-circe-notifications after the buffer playback is done.

About

Add desktop notifications to Circe.

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •