Skip to content

Commit ca10d1f

Browse files
committedJan 1, 2016
Add sauron event for @-mention in twittering mode
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
1 parent 23dc733 commit ca10d1f

File tree

2 files changed

+51
-12
lines changed

2 files changed

+51
-12
lines changed
 

‎README.org

+10-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
case of IRC (ERC), it will switch you to the buffer (channel) it originated
1414
from. It's a bit of a generalization of what /tracking mode/ does in ERC (the
1515
emacs IRC client), and that is in fact how it started.
16-
16+
1717
There's an increasing number of hooks and tunables in sauron, which allows
1818
you to fine-tune the behavior. However, I strive for it to be useful with
1919
minimal configuration.
@@ -228,7 +228,7 @@
228228
- *identica* - for =identica-mode=, the social-network site
229229
- *twittering* - for =twittering-mode=, the emacs twitter client
230230
- *jabber* - for =jabber=, the IM protocol (XMPP)
231-
- *elfeed* - for =elfeed=, an emacs Atom/RSS feed reader
231+
- *elfeed* - for =elfeed=, an emacs Atom/RSS feed reader
232232

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

359+
*** twittering
360+
361+
=sauron-twittering= shows the number of new tweets found by
362+
=twittering-mode= whenever there is at least one new tweet.
363+
364+
If =twittering-username= is set, it will also show @-mentions when new
365+
tweets arrive.
366+
359367
*** jabber
360368

361369
=sauron-jabber= shows events from =jabber.el=, this includes new messages, info

‎sauron-twittering.el

+41-10
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
(defvar sauron-prio-twittering-new-tweets 3
2929
"Twittering new tweets event priority.")
3030

31+
(defvar sauron-prio-twittering-mention 4
32+
"Twittering @-mention event priority.")
33+
3134
(defvar sauron-twittering-running nil
3235
"when non-nil, sauron-twittering is running")
3336

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

43-
(add-hook 'twittering-new-tweets-hook 'sauron-twittering-new-tweets-func)
46+
(add-hook 'twittering-new-tweets-hook #'sauron-twittering-new-tweets-func)
47+
(add-hook 'twittering-new-tweets-hook
48+
#'sauron-twittering-check-tweet-mention-func)
4449
(setq sauron-twittering-running t))
4550
(message "No twittering, so sauron-twittering could not
4651
start")))
@@ -50,21 +55,47 @@
5055
"Stops and cleans up sauron-twittering."
5156
(when sauron-twittering-running
5257
(remove-hook 'twittering-new-tweets-hook 'sauron-twittering-new-tweets-func)
58+
(remove-hook 'twittering-new-tweets-hook
59+
#'sauron-twittering-check-tweet-mention-func)
5360
(setq sauron-twittering-running nil)))
5461

5562

63+
(defun sauron-twittering-check-tweet-mention-func ()
64+
"Hook which takes newly incoming tweets and adds sauron events
65+
for any mentioning `twittering-username'. Events will be added
66+
using `sauron-prio-twittering-mention' priority."
67+
(when (and twittering-username
68+
(boundp 'twittering-new-tweets-statuses))
69+
(dolist (tweet twittering-new-tweets-statuses)
70+
(when (string-match-p
71+
(format "@%s" twittering-username)
72+
(alist-get 'text tweet))
73+
(sr-twit-add-event
74+
sauron-prio-twittering-mention
75+
(format "%s: %s"
76+
(alist-get 'user-screen-name tweet)
77+
(alist-get 'text tweet))
78+
(lexical-let
79+
((tweets-spec twittering-new-tweets-spec)
80+
(tweets-data twittering-new-tweets-statuses)
81+
(tweets-count twittering-new-tweets-count))
82+
(lambda ()
83+
(sr-twit-activate-event
84+
tweets-data tweets-count tweets-spec))))))))
85+
86+
5687
(defun sauron-twittering-new-tweets-func ()
5788
"Hook which handles the arrival of new tweets. Main entry point and interface
5889
to twittering."
59-
(sr-twit-add-event sauron-prio-twittering-new-tweets
60-
(format "%d new tweets" twittering-new-tweets-count)
61-
(lexical-let
62-
((tweets-spec twittering-new-tweets-spec)
63-
(tweets-data twittering-new-tweets-statuses)
64-
(tweets-count twittering-new-tweets-count))
65-
(lambda ()
66-
(sr-twit-activate-event tweets-data tweets-count tweets-spec)
67-
))))
90+
(sr-twit-add-event
91+
sauron-prio-twittering-new-tweets
92+
(format "%d new tweets" twittering-new-tweets-count)
93+
(lexical-let
94+
((tweets-spec twittering-new-tweets-spec)
95+
(tweets-data twittering-new-tweets-statuses)
96+
(tweets-count twittering-new-tweets-count))
97+
(lambda ()
98+
(sr-twit-activate-event tweets-data tweets-count tweets-spec)))))
6899

69100
(defun sr-twit-add-event (priority message callback)
70101
(sauron-add-event 'twittering priority message callback))

0 commit comments

Comments
 (0)
Please sign in to comment.