From: bg66 Date: Tue, 6 Mar 2007 01:55:28 +0000 (+0000) Subject: * riece-mixi.el: New file. X-Git-Tag: mixi-el-1_0_0~61 X-Git-Url: http://git.chise.org/gitweb/?p=elisp%2Fmixi.git;a=commitdiff_plain;h=75004e3e5a004e68b7ff78e12a1856b057a46f5c * riece-mixi.el: New file. * configure.ac: Add AC_CHECK_RIECE and HAVE_RIECE. * acinclude.m4 Add AC_CHECK_RIECE. * Makefile.am (MODULES_ALL): Abolish. (MODULES_SHIMBUN): New variable. (MODULES_RIECE): Ditto. (EXTRA_DIST): Follow the change above. (MODULES): Ditto. * mixi-utils.el (mixi-make-title): Support a suffix of news. --- diff --git a/ChangeLog b/ChangeLog index 3c47a9c..d2b1e48 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2007-03-06 OHASHI Akira + + * riece-mixi.el: New file. + * configure.ac: Add AC_CHECK_RIECE and HAVE_RIECE. + * acinclude.m4 Add AC_CHECK_RIECE. + * Makefile.am (MODULES_ALL): Abolish. + (MODULES_SHIMBUN): New variable. + (MODULES_RIECE): Ditto. + (EXTRA_DIST): Follow the change above. + (MODULES): Ditto. + + * mixi-utils.el (mixi-make-title): Support a suffix of news. + 2007-03-01 OHASHI Akira * mixi.el (mixi-favorite-list-id-regexp): Abolish. @@ -13,7 +26,7 @@ * mixi-utils.el (mixi-make-content): Support mixi-log object. * mixi.el (mixi-url-encode-string): New function. - (mixi-url-encode-and-quote-percent-string) Use it. + (mixi-url-encode-and-quote-percent-string): Use it. * mixi-utils.el: (mixi-make-encoded-url): New function. (mixi-make-objects): Ditto. diff --git a/Makefile.am b/Makefile.am index ab5d91a..b3a36dc 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,15 +1,21 @@ MODULES_MIXI = mixi.el mixi-utils.el mixi-atom.el -MODULES_ALL = $(MODULES_MIXI) sb-mixi.el mixi-gnus.el mixi-wl.el -EXTRA_DIST = COMPILE ChangeLog $(MODULES_ALL) +MODULES_SHIMBUN = sb-mixi.el mixi-gnus.el mixi-wl.el +MODULES_RIECE = riece-mixi.el +EXTRA_DIST = COMPILE ChangeLog $(MODULES_MIXI) $(MODULES_SHIMBUN) \ + $(MODULES_RIECE) CLEANFILES = auto-autoloads.el custom-load.el *.elc AUTOMAKE_OPTIONS = no-dependencies FLAGS ?= -batch -q -no-site-file -if HAVE_SHIMBUN -MODULES = $(MODULES_ALL) -else MODULES = $(MODULES_MIXI) + +if HAVE_SHIMBUN +MODULES += $(MODULES_SHIMBUN) +endif + +if HAVE_RIECE +MODULES += $(MODULES_RIECE) endif all: elc diff --git a/acinclude.m4 b/acinclude.m4 index f1fd3b2..f1fa521 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -114,7 +114,7 @@ dnl dnl Perform sanity checking and try to locate the Shimbun package dnl AC_DEFUN([AC_CHECK_SHIMBUN], [ - AC_MSG_CHECKING(for shimbun) + AC_MSG_CHECKING(have shimbun) dnl Ignore cache. unset EMACS_cv_SYS_shimbun_dir; @@ -142,6 +142,38 @@ AC_DEFUN([AC_CHECK_SHIMBUN], [ fi ]) +dnl +dnl Perform sanity checking and try to locate the Riece package +dnl +AC_DEFUN([AC_CHECK_RIECE], [ + AC_MSG_CHECKING(have riece) + + dnl Ignore cache. + unset EMACS_cv_SYS_riece_dir; + + AC_ARG_WITH(riece,[ --with-riece[[=ARG]] Use riece [[ARG=yes]]], + [if test "$withval" = yes -o -z "$withval"; then + HAVE_RIECE=yes + else + HAVE_RIECE=$withval + fi], HAVE_RIECE=yes) + AC_SUBST(HAVE_RIECE) + + if test "${HAVE_RIECE}" = yes; then + AC_EMACS_LISP(riece_dir,(file-name-directory (locate-library \"riece\")),"noecho") + RIECE_DIR=$EMACS_cv_SYS_riece_dir + fi + + if test "${HAVE_RIECE}" != yes; then + AC_MSG_RESULT(no) + elif test -z "${RIECE_DIR}"; then + HAVE_RIECE=no + AC_MSG_RESULT(not found) + else + AC_MSG_RESULT(${HAVE_RIECE}) + fi +]) + AC_DEFUN([AC_EXAMINE_PACKAGEDIR], [dnl Examine PACKAGEDIR. AC_EMACS_LISP(PACKAGEDIR, diff --git a/configure.ac b/configure.ac index 61ce495..49b4caa 100644 --- a/configure.ac +++ b/configure.ac @@ -8,8 +8,10 @@ AC_PATH_LISPDIR AC_PATH_PACKAGEDIR AC_CHECK_SHIMBUN +AC_CHECK_RIECE AM_CONDITIONAL(HAVE_SHIMBUN, test "${HAVE_SHIMBUN}" = yes) +AM_CONDITIONAL(HAVE_RIECE, test "${HAVE_RIECE}" = yes) AC_CONFIG_FILES([Makefile]) AC_OUTPUT diff --git a/mixi-utils.el b/mixi-utils.el index 58f76d7..c8be8b7 100644 --- a/mixi-utils.el +++ b/mixi-utils.el @@ -67,11 +67,14 @@ (subject (mixi-object-title object)) (suffix (when add-parent (concat " (" - (if (eq class 'mixi-diary) - (mixi-friend-nick - (mixi-diary-owner object)) - (mixi-community-name - (mixi-bbs-community object))) + (cond ((eq class 'mixi-diary) + (mixi-friend-nick + (mixi-diary-owner object))) + ((eq class 'mixi-news) + (mixi-news-media object)) + (t + (mixi-community-name + (mixi-bbs-community object)))) ")")))) (concat prefix subject suffix)))))) diff --git a/riece-mixi.el b/riece-mixi.el new file mode 100644 index 0000000..a5002fb --- /dev/null +++ b/riece-mixi.el @@ -0,0 +1,169 @@ +;;; riece-mixi.el --- Riece integration for mixi +;; Copyright (C) 2007 OHASHI Akira + +;; Author: OHASHI Akira +;; Keywords: IRC, riece + +;; This file is *NOT* part of Riece. + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 2, or (at your option) +;; any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs; see the file COPYING. If not, write to the +;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +;; Boston, MA 02110-1301, USA. + +;;; Commentary: + +;; NOTE: This is an add-on module for Riece. + +;;; Code: + +(require 'mixi) +(require 'mixi-utils) +(require 'timer) + +;; Functions and variables which should be defined in the other module +;; at run-time. +(eval-when-compile + (defvar riece-current-channels) + (autoload 'riece-send-string "riece-server") + (autoload 'riece-identity-prefix "riece-identity") + (autoload 'riece-display-message "riece-message") + (autoload 'riece-make-message "riece-message") + (autoload 'riece-current-nickname "riece-misc") + (autoload 'riece-message-text "riece-message") + (autoload 'riece-message-target "riece-message") + (autoload 'riece-parse-identity "riece-identity")) + +(defgroup riece-mixi nil + "Riece integration for mixi." + :prefix "riece-" + :group 'riece) + +(defcustom riece-mixi-regexp "\\(https?://\\([^.]+.\\)?mixi.jp[^ ]+\\)" + "*Pattern of string to retrieving to mixi." + :type 'string + :group 'riece-mixi) + +(defcustom riece-mixi-check-alist nil + "*An alist for checking to detect new articles. +Each element looks like (CHANNEL . URL) or (CHANNEL . FUNCTION). +CHANNEL is a channel name. +URL is the URL for mixi access point of the channel. If URL is friend's, get +his/her diaries as article. If community's, get its BBSes. If diary's or +BBS's, get its comments. +FUNCTION is the function which has one `range' argument and returns the list +of mixi object." + :type '(repeat (cons :format "%v" + (string :tag "Channel") + (radio (string :tag "URL") + (function :tag "Other function")))) + :group 'riece-mixi) + +(defcustom riece-mixi-check-range 1 + "*The number of ranges that should be checked to detect new articles." + :type 'integer + :group 'riece-mixi) + +(defcustom riece-mixi-timer-step 3600 + "*Seconds for checking to detect new articles." + :type 'integer + :group 'riece-mixi) + +(defvar riece-mixi-timer nil) +(defvar riece-mixi-last-check nil) + +(defvar riece-mixi-enabled nil) + +(defconst riece-mixi-description + "Riece integration for mixi.") + +(defun riece-mixi-send-notice (target string) + (riece-send-string + (format "NOTICE %s :%s\r\n" (riece-identity-prefix target) string)) + (riece-display-message + (riece-make-message (riece-current-nickname) target string 'notice))) + +(defun riece-mixi-send-object (target object) + (condition-case nil + (let ((string (concat (mixi-make-title object t) " [AR]"))) + (riece-mixi-send-notice target string)) + (error nil))) + +(defun riece-mixi-display-message-function (message) + (when (and riece-mixi-enabled + (string-match riece-mixi-regexp (riece-message-text message))) + (let* ((url (match-string 1 (riece-message-text message))) + (object (mixi-make-object-from-url url))) + (when (mixi-object-p object) + (let ((target (riece-message-target message))) + (riece-mixi-send-object target object)))))) + +(defun riece-mixi-send-object-with-url (target object) + (condition-case nil + (let ((string (mixi-make-title object t)) + (url (mixi-make-url object))) + (riece-mixi-send-notice target string) + (riece-mixi-send-notice target url)) + (error nil))) + +(defun riece-mixi-check () + "Check to detect new articles. +If they exist, send them as notice to the corresponding channel." + (when riece-mixi-enabled + (mapc (lambda (list) + (let ((target (riece-parse-identity (car list))) + (url-or-function (cdr list))) + (when (member target riece-current-channels) + (let ((objects (mixi-make-objects url-or-function + riece-mixi-check-range))) + (mapc (lambda (object) + (when (mixi-parent-p object) + (let ((comments (mixi-get-comments + object riece-mixi-check-range))) + (mapc (lambda (comment) + (let ((time (mixi-object-time comment))) + (when (mixi-time-less-p + riece-mixi-last-check time) + (riece-mixi-send-object-with-url + target comment)))) + comments))) + (let ((time (mixi-object-time object))) + (when (mixi-time-less-p riece-mixi-last-check + time) + (riece-mixi-send-object-with-url target + object)))) + objects))))) + riece-mixi-check-alist) + (setq riece-mixi-last-check (current-time)))) + +(defun riece-mixi-insinuate () + (add-hook 'riece-after-display-message-functions + 'riece-mixi-display-message-function)) + +(defun riece-mixi-enable () + (setq riece-mixi-enabled t) + (when riece-mixi-check-alist + (setq riece-mixi-timer + (run-at-time riece-mixi-timer-step riece-mixi-timer-step + 'riece-mixi-check)) + (setq riece-mixi-last-check (current-time)))) + +(defun riece-mixi-disable () + (setq riece-mixi-enabled nil) + (when (timerp riece-mixi-timer) + (cancel-timer riece-mixi-timer) + (setq riece-mixi-timer nil))) + +(provide 'riece-mixi) + +;;; riece-mixi.el ends here