1 ;;; riece-mixi.el --- Riece integration for mixi
2 ;; Copyright (C) 2007, 2008 OHASHI Akira
4 ;; Author: OHASHI Akira <bg66@koka-in.org>
5 ;; Keywords: IRC, riece
7 ;; This file is *NOT* 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.
28 ;; If you have bug reports and/or suggestions for improvement, please
29 ;; send them via <URL:http://mixi.jp/view_community.pl?id=1596390>.
36 (require 'riece-message)
38 (defgroup riece-mixi nil
39 "Riece integration for mixi."
43 (defcustom riece-mixi-regexp "\\(https?://\\([^.]+.\\)?mixi.jp[^ ]+\\)"
44 "*Pattern of string to retrieving to mixi."
48 (defcustom riece-mixi-reply-to-only-me nil
49 "*If non-nil, reply to only my messages."
53 (defcustom riece-mixi-check-alist nil
54 "*An alist for checking to detect new articles.
55 Each element looks like (CHANNEL . URL) or (CHANNEL . FUNCTION).
56 CHANNEL is a channel name.
57 URL is the URL for mixi access point of the channel. If URL is friend's, get
58 his/her diaries as article. If community's, get its BBSes. If diary's or
59 BBS's, get its comments.
60 FUNCTION is the function which has one `range' argument and returns the list
62 :type '(repeat (cons :format "%v"
63 (string :tag "Channel")
64 (radio (string :tag "URL")
65 (function :tag "Other function"))))
68 (defcustom riece-mixi-check-range 1
69 "*The number of ranges that should be checked to detect new articles."
73 (defcustom riece-mixi-timer-step 3600
74 "*Seconds for checking to detect new articles."
78 (defvar riece-mixi-timer nil)
79 (defvar riece-mixi-last-check nil)
81 (defconst riece-mixi-description
82 "Riece integration for mixi.")
84 (defun riece-mixi-send-notice (target string)
86 (format "NOTICE %s :%s\r\n" (riece-identity-prefix target) string))
87 (riece-display-message
88 (riece-make-message (riece-current-nickname) target string 'notice)))
90 (defun riece-mixi-send-object (target object)
92 (let ((string (concat (mixi-make-title object t) " [AR]")))
93 (riece-mixi-send-notice target string))
96 (defun riece-mixi-display-message-function (message)
97 (when (and (get 'riece-mixi 'riece-addon-enabled)
98 (or (riece-message-own-p message)
99 (not riece-mixi-reply-to-only-me))
100 (string-match riece-mixi-regexp (riece-message-text message)))
101 (let* ((url (match-string 1 (riece-message-text message)))
102 (object (mixi-make-object-from-url url)))
103 (when (mixi-object-p object)
104 (let ((target (riece-message-target message)))
105 (riece-mixi-send-object target object))))))
107 (defun riece-mixi-send-object-with-url (target object)
109 (let ((url (mixi-make-url object)))
110 (riece-mixi-send-notice target url))
113 (defun riece-mixi-check ()
114 "Check to detect new articles.
115 If they exist, send them as notice to the corresponding channel."
116 (when (get 'riece-mixi 'riece-addon-enabled)
118 (let ((target (riece-parse-identity (car list)))
119 (url-or-function (cdr list)))
120 (when (member target riece-current-channels)
121 (let ((objects (mixi-make-objects url-or-function
122 riece-mixi-check-range)))
124 (let ((object (car objects)))
125 (when (mixi-parent-p object)
126 (let ((comments (mixi-get-comments
127 object riece-mixi-check-range)))
129 (let ((time (mixi-object-time (car comments))))
130 (when (mixi-time-less-p riece-mixi-last-check
132 (riece-mixi-send-object-with-url
133 target (car comments))))
134 (setq comments (cdr comments)))))
135 (let ((time (mixi-object-time object)))
136 (when (mixi-time-less-p riece-mixi-last-check time)
137 (riece-mixi-send-object-with-url target object))))
138 (setq objects (cdr objects)))))))
139 riece-mixi-check-alist)
140 (setq riece-mixi-last-check (current-time))))
142 (defun riece-mixi-message-filter (message)
143 (when (and (get 'riece-mixi 'riece-addon-enabled)
144 (riece-message-own-p message)
145 (eq 'action (riece-message-type message)))
146 (mixi-post-echo (riece-message-text message)))
149 (defun riece-mixi-insinuate ()
150 (add-hook 'riece-after-display-message-functions
151 'riece-mixi-display-message-function)
152 (add-hook 'riece-message-filter-functions
153 'riece-mixi-message-filter))
155 (defun riece-mixi-uninstall ()
156 (remove-hook 'riece-after-display-message-functions
157 'riece-mixi-display-message-function)
158 (remove-hook 'riece-message-filter-functions
159 'riece-mixi-message-filter))
161 (defun riece-mixi-enable ()
162 (when riece-mixi-check-alist
163 (setq riece-mixi-timer
164 (run-at-time riece-mixi-timer-step riece-mixi-timer-step
166 (setq riece-mixi-last-check (current-time))))
168 (defun riece-mixi-disable ()
169 (when (timerp riece-mixi-timer)
170 (cancel-timer riece-mixi-timer)
171 (setq riece-mixi-timer nil)))
173 (provide 'riece-mixi)
175 ;;; riece-mixi.el ends here