* riece-twitter.el (riece-twitter-set-credential): New command.
authorueno <ueno>
Wed, 6 Jun 2007 09:01:34 +0000 (09:01 +0000)
committerueno <ueno>
Wed, 6 Jun 2007 09:01:34 +0000 (09:01 +0000)
(riece-twitter-update): New command.
(riece-twitter-message-filter): Use it.

lisp/ChangeLog
lisp/riece-twitter.el

index 2e5b0f3..a4ca687 100644 (file)
@@ -1,3 +1,9 @@
+2007-06-06  Daiki Ueno  <ueno@unixuser.org>
+
+       * riece-twitter.el (riece-twitter-set-credential): New command.
+       (riece-twitter-update): New command.
+       (riece-twitter-message-filter): Use it.
+
 2007-06-05  Daiki Ueno  <ueno@unixuser.org>
 
        * riece-twitter.el (riece-twitter-message-filter): Send a "source"
index 214d03f..6212ff0 100644 (file)
   :group 'riece-twitter
   :type 'string)
 
-(defcustom riece-twitter-cache-credential t
-  "If non-nil, cache your credential on Twitter."
-  :group 'riece-twitter
-  :type 'boolean)
-
-(defun riece-twitter-message-filter (message)
-  (if (and (riece-message-own-p message)
-          (eq 'action (riece-message-type message)))
-      (let ((credential
-            (or riece-twitter-credential
-                (concat (read-string "Twitter username: ") ":"
-                        (read-passwd "Twitter password: ")))))
-       (if (and riece-twitter-cache-credential
-                (not (eq credential riece-twitter-credential)))
-           (setq riece-twitter-credential credential))
-       (start-process
+(if (fboundp 'clear-string)
+    (defalias 'riece-twitter-clear-string 'clear-string)
+  (defun riece-twitter-clear-string (string)
+    (fillarray string ?\x0)))
+
+(defun riece-twitter-set-credential (credential)
+  "Set your credential used to login to Twitter."
+  (interactive
+   (let ((username (read-string "Username: "))
+        password)
+     (unwind-protect
+        (setq password (read-passwd "Password: "))
+       (if password
+          (riece-twitter-clear-string password))
+       (setq password nil))
+     (list (concat username ":" password))))
+  (setq riece-twitter-credential credential))
+
+(defun riece-twitter-update (status)
+  "Update your status."
+  (interactive "sStatus: ")
+  (start-process
         "curl" nil "curl"
         "-H" "X-Twitter-Client: Riece"
         "-H" (concat "X-Twitter-Client-Version: " riece-version-number)
         "-d" "source=riece"
         "-d" (concat "status="
                      (riece-twitter-escape-string
-                      (encode-coding-string (riece-message-text message)
-                                            'utf-8)))
+                      (encode-coding-string status 'utf-8)))
         "-s"
-        "http://twitter.com/statuses/update.json")))
+        "http://twitter.com/statuses/update.json"))
+
+(defun riece-twitter-message-filter (message)
+  (if (and (riece-message-own-p message)
+          (eq 'action (riece-message-type message)))
+      (if riece-twitter-credential
+         (riece-twitter-update (riece-message-text message))
+       (message "%s"
+                (substitute-command-keys
+                 "\\[riece-twitter-set-credential] to set your credential"))))
   message)
 
 (defun riece-twitter-escape-string (string)