Skip to content

Commit

Permalink
Add sauron event for @-mention in twittering mode
Browse files Browse the repository at this point in the history
If `twittering-username` is set, events will be added when new tweets
come with with `@<username>`. `sauron-prio-twittering-mention` can be
customized to change the priority of @-mention messages.

Resolves #43
  • Loading branch information
dakrone committed Jan 1, 2016
1 parent 23dc733 commit ca10d1f
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 12 deletions.
12 changes: 10 additions & 2 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
case of IRC (ERC), it will switch you to the buffer (channel) it originated
from. It's a bit of a generalization of what /tracking mode/ does in ERC (the
emacs IRC client), and that is in fact how it started.

There's an increasing number of hooks and tunables in sauron, which allows
you to fine-tune the behavior. However, I strive for it to be useful with
minimal configuration.
Expand Down Expand Up @@ -228,7 +228,7 @@
- *identica* - for =identica-mode=, the social-network site
- *twittering* - for =twittering-mode=, the emacs twitter client
- *jabber* - for =jabber=, the IM protocol (XMPP)
- *elfeed* - for =elfeed=, an emacs Atom/RSS feed reader
- *elfeed* - for =elfeed=, an emacs Atom/RSS feed reader

By default, =sauron= tries to load all of them; this should work, even if
you don't have some of these packages (they simply won't be activated).
Expand Down Expand Up @@ -356,6 +356,14 @@ DBUS_SESSION_BUS_ADDRESS="`cat ~/.sauron-dbus`" dbus-send ....
=sauron-identica= shows the number of new dents found by =identica-mode= whenever
there is at least one new dent.

*** twittering

=sauron-twittering= shows the number of new tweets found by
=twittering-mode= whenever there is at least one new tweet.

If =twittering-username= is set, it will also show @-mentions when new
tweets arrive.

*** jabber

=sauron-jabber= shows events from =jabber.el=, this includes new messages, info
Expand Down
51 changes: 41 additions & 10 deletions sauron-twittering.el
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
(defvar sauron-prio-twittering-new-tweets 3
"Twittering new tweets event priority.")

(defvar sauron-prio-twittering-mention 4
"Twittering @-mention event priority.")

(defvar sauron-twittering-running nil
"when non-nil, sauron-twittering is running")

Expand All @@ -40,7 +43,9 @@
(error "sauron-twittering is already running. Call
sauron-twittering-stop first."))

(add-hook 'twittering-new-tweets-hook 'sauron-twittering-new-tweets-func)
(add-hook 'twittering-new-tweets-hook #'sauron-twittering-new-tweets-func)
(add-hook 'twittering-new-tweets-hook
#'sauron-twittering-check-tweet-mention-func)
(setq sauron-twittering-running t))
(message "No twittering, so sauron-twittering could not
start")))
Expand All @@ -50,21 +55,47 @@
"Stops and cleans up sauron-twittering."
(when sauron-twittering-running
(remove-hook 'twittering-new-tweets-hook 'sauron-twittering-new-tweets-func)
(remove-hook 'twittering-new-tweets-hook
#'sauron-twittering-check-tweet-mention-func)
(setq sauron-twittering-running nil)))


(defun sauron-twittering-check-tweet-mention-func ()
"Hook which takes newly incoming tweets and adds sauron events
for any mentioning `twittering-username'. Events will be added
using `sauron-prio-twittering-mention' priority."
(when (and twittering-username
(boundp 'twittering-new-tweets-statuses))
(dolist (tweet twittering-new-tweets-statuses)
(when (string-match-p
(format "@%s" twittering-username)
(alist-get 'text tweet))
(sr-twit-add-event
sauron-prio-twittering-mention
(format "%s: %s"
(alist-get 'user-screen-name tweet)
(alist-get 'text tweet))
(lexical-let
((tweets-spec twittering-new-tweets-spec)
(tweets-data twittering-new-tweets-statuses)
(tweets-count twittering-new-tweets-count))
(lambda ()
(sr-twit-activate-event
tweets-data tweets-count tweets-spec))))))))


(defun sauron-twittering-new-tweets-func ()
"Hook which handles the arrival of new tweets. Main entry point and interface
to twittering."
(sr-twit-add-event sauron-prio-twittering-new-tweets
(format "%d new tweets" twittering-new-tweets-count)
(lexical-let
((tweets-spec twittering-new-tweets-spec)
(tweets-data twittering-new-tweets-statuses)
(tweets-count twittering-new-tweets-count))
(lambda ()
(sr-twit-activate-event tweets-data tweets-count tweets-spec)
))))
(sr-twit-add-event
sauron-prio-twittering-new-tweets
(format "%d new tweets" twittering-new-tweets-count)
(lexical-let
((tweets-spec twittering-new-tweets-spec)
(tweets-data twittering-new-tweets-statuses)
(tweets-count twittering-new-tweets-count))
(lambda ()
(sr-twit-activate-event tweets-data tweets-count tweets-spec)))))

(defun sr-twit-add-event (priority message callback)
(sauron-add-event 'twittering priority message callback))
Expand Down

0 comments on commit ca10d1f

Please sign in to comment.