|
28 | 28 | (defvar sauron-prio-twittering-new-tweets 3
|
29 | 29 | "Twittering new tweets event priority.")
|
30 | 30 |
|
| 31 | +(defvar sauron-prio-twittering-mention 4 |
| 32 | + "Twittering @-mention event priority.") |
| 33 | + |
31 | 34 | (defvar sauron-twittering-running nil
|
32 | 35 | "when non-nil, sauron-twittering is running")
|
33 | 36 |
|
|
40 | 43 | (error "sauron-twittering is already running. Call
|
41 | 44 | sauron-twittering-stop first."))
|
42 | 45 |
|
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) |
44 | 49 | (setq sauron-twittering-running t))
|
45 | 50 | (message "No twittering, so sauron-twittering could not
|
46 | 51 | start")))
|
|
50 | 55 | "Stops and cleans up sauron-twittering."
|
51 | 56 | (when sauron-twittering-running
|
52 | 57 | (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) |
53 | 60 | (setq sauron-twittering-running nil)))
|
54 | 61 |
|
55 | 62 |
|
| 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 | + |
56 | 87 | (defun sauron-twittering-new-tweets-func ()
|
57 | 88 | "Hook which handles the arrival of new tweets. Main entry point and interface
|
58 | 89 | 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))))) |
68 | 99 |
|
69 | 100 | (defun sr-twit-add-event (priority message callback)
|
70 | 101 | (sauron-add-event 'twittering priority message callback))
|
|
0 commit comments