* riece-twitter.el: New add-on.
authorueno <ueno>
Wed, 18 Apr 2007 04:45:34 +0000 (04:45 +0000)
committerueno <ueno>
Wed, 18 Apr 2007 04:45:34 +0000 (04:45 +0000)
* riece-addon-modules.el (riece-addon-modules): Add riece-twitter.
* Makefile.am (EXTRA_DIST): Add riece-twitter.el.

lisp/ChangeLog
lisp/Makefile.am
lisp/riece-addon-modules.el
lisp/riece-twitter.el [new file with mode: 0644]

index 850dfca..62b83ad 100644 (file)
@@ -1,5 +1,9 @@
 2007-04-18  Daiki Ueno  <ueno@unixuser.org>
 
+       * riece-twitter.el: New add-on.
+       * riece-addon-modules.el (riece-addon-modules): Add riece-twitter.
+       * Makefile.am (EXTRA_DIST): Add riece-twitter.el.
+
        * riece-ctcp.el (riece-ctcp-action-format-message): New function.
        (riece-handle-ctcp-action-request): Use it.
        (riece-command-ctcp-action): Use it.
index c01a6be..c9fa8ca 100644 (file)
@@ -19,7 +19,8 @@ EXTRA_DIST = COMPILE ChangeLog ChangeLog.Liece \
        riece-ctlseq.el riece-ignore.el riece-hangman.el riece-biff.el \
        riece-kakasi.el riece-foolproof.el riece-yank.el riece-toolbar.el \
        riece-eval.el riece-google.el riece-keepalive.el riece-eval-ruby.el \
-       riece-shrink-buffer.el riece-xfaceb.el riece-epg.el url-riece.el \
+       riece-shrink-buffer.el riece-xfaceb.el riece-epg.el riece-twitter.el \
+       url-riece.el \
        riece-command-previous-channel.xpm riece-command-next-channel.xpm \
        riece-submit-bug-report.xpm \
        server.rb aproxy.rb
index 4bd4b3a..103a8fb 100644 (file)
@@ -30,6 +30,7 @@
     (riece-shrink-buffer . "Free old IRC messages to save memory usage.")
     (riece-skk-kakutei . "Remove SKK's preedit mark before sending messages.")
     (riece-toolbar . "Display toolbar icons.")
+    (riece-twitter . "Send your status to Twitter.")
     (riece-unread . "Mark channels where new messages arrived.")
     (riece-url . "Collect URL in IRC buffers.")
     (riece-xface . "Display X-Face in IRC buffers.")
diff --git a/lisp/riece-twitter.el b/lisp/riece-twitter.el
new file mode 100644 (file)
index 0000000..a581ddc
--- /dev/null
@@ -0,0 +1,35 @@
+(defvar riece-twitter-credential nil)
+
+(defun riece-twitter-message-filter (message)
+  (if (and (riece-message-own-p message)
+          (eq 'action (riece-message-type message)))
+      (start-process
+       "curl" nil "curl"
+       "-H" "X-Twitter-Client: Riece"
+       "-H" (concat "X-Twitter-Client-Version: " riece-version-number)
+       "-H" "X-Twitter-Client-URL: http://riece.nongnu.org/twitter.xml"
+       "-u" riece-twitter-credential
+       "-d" (concat "status="
+                   (riece-twitter-escape-string (encode-coding-string (riece-message-text message) 'utf-8)))
+       "-s"
+       "http://twitter.com/statuses/update.json"))
+  message)
+
+(defun riece-twitter-escape-string (string)
+  (let ((index 0))
+    (while (string-match "[^0-9A-Za-z\-\._~:/?@!\$'()*,]" string index)
+      (setq string (replace-match
+                   (format "%%%02X" (aref string (match-beginning 0)))
+                   t t string)
+           index (+ 3 (match-beginning 0))))
+    string))
+
+(defun riece-twitter-insinuate ()
+  (add-hook 'riece-message-filter-functions 'riece-twitter-message-filter))
+
+(defun riece-twitter-uninstall ()
+  (remove-hook 'riece-message-filter-functions 'riece-twitter-message-filter))
+
+(provide 'riece-twitter)
+
+;;; riece-twitter.el ends here