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."
42 (if (fboundp 'clear-string)
43 (defalias 'riece-twitter-clear-string 'clear-string)
44 (defun riece-twitter-clear-string (string)
45 (fillarray string ?\0))))
47 (defun riece-twitter-set-credential (credential)
48 "Set your credential used to login to Twitter."
50 (let ((username (read-string "Username: "))
53 (list (concat username ":"
54 (setq password (read-passwd "Password: "))))
56 (riece-twitter-clear-string password))
57 (setq password nil))))
58 (setq riece-twitter-credential credential))
60 (defun riece-twitter-update (status)
64 (unless riece-twitter-credential
66 (substitute-command-keys
67 "\\[riece-twitter-set-credential] to set your credential")))
68 (list (read-string "Status: "))))
69 (message "Sending to Twitter...")
71 (list "-u" riece-twitter-credential
72 "-d" (concat "status="
73 (riece-twitter-escape-string
74 (encode-coding-string status 'utf-8)))
76 "http://twitter.com/statuses/update.json"))
78 (apply #'start-process
83 (list "-H" "X-Twitter-Client: Riece"
84 "-H" (concat "X-Twitter-Client-Version: "
86 "-H" "X-Twitter-Client-URL: http://riece.nongnu.org/twitter.xml"
87 "-d" "source=riece"))))))
88 (set-process-sentinel process #'riece-twitter-sentinel)))
90 (defun riece-twitter-sentinel (process status)
91 (if (equal status "finished\n")
92 (message "Sending to Twitter...done")
93 (message "Sending to Twitter...failed: %s"
94 (substring status 0 (1- (length status))))))
96 (defun riece-twitter-message-filter (message)
97 (if (and (riece-message-own-p message)
98 (eq 'action (riece-message-type message)))
99 (if riece-twitter-credential
100 (riece-twitter-update (riece-message-text message))
102 (substitute-command-keys
103 "\\[riece-twitter-set-credential] to set your credential"))))
106 (defun riece-twitter-escape-string (string)
108 (while (string-match "[^0-9A-Za-z\-\._~:/?@!\$'()*,]" string index)
109 (setq string (replace-match
110 (format "%%%02X" (aref string (match-beginning 0)))
112 index (+ 3 (match-beginning 0))))
115 (defun riece-twitter-insinuate ()
116 (add-hook 'riece-message-filter-functions 'riece-twitter-message-filter))
118 (defun riece-twitter-uninstall ()
119 (remove-hook 'riece-message-filter-functions 'riece-twitter-message-filter))
121 (provide 'riece-twitter)
123 ;;; riece-twitter.el ends here