1 ;;; riece-twitter.el --- post your status to Twitter
2 ;; Copyright (C) 2007 Daiki Ueno
4 ;; Author: Daiki Ueno <ueno@unixuser.org>
5 ;; Keywords: IRC, riece
7 ;; This file is part of Riece.
9 ;; This program is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; This program is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 ;; Boston, MA 02110-1301, USA.
26 ;; NOTE: This is an add-on module for Riece.
30 (require 'riece-message)
32 (defgroup riece-twitter nil
33 "Post your status to Twitter"
36 (defcustom riece-twitter-credential nil
37 "Your credential used to login to Twitter."
41 (defcustom riece-twitter-cache-credential nil
42 "If non-nil, cache your credential on Twitter."
46 (defun riece-twitter-message-filter (message)
48 (or riece-twitter-credential
49 (concat (read-string "Twitter username: ") ":"
50 (read-passwd "Twitter password: ")))))
51 (if (and riece-twitter-cache-credential
52 (not (eq credential riece-twitter-credential)))
53 (setq riece-twitter-credential credential))
54 (if (and (riece-message-own-p message)
55 (eq 'action (riece-message-type message)))
58 "-H" "X-Twitter-Client: Riece"
59 "-H" (concat "X-Twitter-Client-Version: " riece-version-number)
60 "-H" "X-Twitter-Client-URL: http://riece.nongnu.org/twitter.xml"
62 "-d" (concat "status="
63 (riece-twitter-escape-string
64 (encode-coding-string (riece-message-text message)
67 "http://twitter.com/statuses/update.json")))
70 (defun riece-twitter-escape-string (string)
72 (while (string-match "[^0-9A-Za-z\-\._~:/?@!\$'()*,]" string index)
73 (setq string (replace-match
74 (format "%%%02X" (aref string (match-beginning 0)))
76 index (+ 3 (match-beginning 0))))
79 (defun riece-twitter-insinuate ()
80 (add-hook 'riece-message-filter-functions 'riece-twitter-message-filter))
82 (defun riece-twitter-uninstall ()
83 (remove-hook 'riece-message-filter-functions 'riece-twitter-message-filter))
85 (provide 'riece-twitter)
87 ;;; riece-twitter.el ends here