1 ;;; riece-mixi.el --- Riece integration for mixi
2 ;; Copyright (C) 2007 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>.
37 ;; Functions and variables which should be defined in the other module
40 (defvar riece-current-channels)
41 (autoload 'riece-send-string "riece-server")
42 (autoload 'riece-identity-prefix "riece-identity")
43 (autoload 'riece-display-message "riece-message")
44 (autoload 'riece-make-message "riece-message")
45 (autoload 'riece-current-nickname "riece-misc")
46 (autoload 'riece-message-own-p "riece-message")
47 (autoload 'riece-message-text "riece-message")
48 (autoload 'riece-message-target "riece-message")
49 (autoload 'riece-parse-identity "riece-identity"))
51 (defgroup riece-mixi nil
52 "Riece integration for mixi."
56 (defcustom riece-mixi-regexp "\\(https?://\\([^.]+.\\)?mixi.jp[^ ]+\\)"
57 "*Pattern of string to retrieving to mixi."
61 (defcustom riece-mixi-reply-to-only-me nil
62 "*If non-nil, reply to only my messages."
66 (defcustom riece-mixi-check-alist nil
67 "*An alist for checking to detect new articles.
68 Each element looks like (CHANNEL . URL) or (CHANNEL . FUNCTION).
69 CHANNEL is a channel name.
70 URL is the URL for mixi access point of the channel. If URL is friend's, get
71 his/her diaries as article. If community's, get its BBSes. If diary's or
72 BBS's, get its comments.
73 FUNCTION is the function which has one `range' argument and returns the list
75 :type '(repeat (cons :format "%v"
76 (string :tag "Channel")
77 (radio (string :tag "URL")
78 (function :tag "Other function"))))
81 (defcustom riece-mixi-check-range 1
82 "*The number of ranges that should be checked to detect new articles."
86 (defcustom riece-mixi-timer-step 3600
87 "*Seconds for checking to detect new articles."
91 (defvar riece-mixi-timer nil)
92 (defvar riece-mixi-last-check nil)
94 (defconst riece-mixi-description
95 "Riece integration for mixi.")
97 (defun riece-mixi-send-notice (target string)
99 (format "NOTICE %s :%s\r\n" (riece-identity-prefix target) string))
100 (riece-display-message
101 (riece-make-message (riece-current-nickname) target string 'notice)))
103 (defun riece-mixi-send-object (target object)
105 (let ((string (concat (mixi-make-title object t) " [AR]")))
106 (riece-mixi-send-notice target string))
109 (defun riece-mixi-display-message-function (message)
110 (when (and (get 'riece-mixi 'riece-addon-enabled)
111 (or (riece-message-own-p message)
112 (not riece-mixi-reply-to-only-me))
113 (string-match riece-mixi-regexp (riece-message-text message)))
114 (let* ((url (match-string 1 (riece-message-text message)))
115 (object (mixi-make-object-from-url url)))
116 (when (mixi-object-p object)
117 (let ((target (riece-message-target message)))
118 (riece-mixi-send-object target object))))))
120 (defun riece-mixi-send-object-with-url (target object)
122 (let ((string (mixi-make-title object t))
123 (url (mixi-make-url object)))
124 (riece-mixi-send-notice target string)
125 (riece-mixi-send-notice target url))
128 (defun riece-mixi-check ()
129 "Check to detect new articles.
130 If they exist, send them as notice to the corresponding channel."
131 (when (get 'riece-mixi 'riece-addon-enabled)
133 (let ((target (riece-parse-identity (car list)))
134 (url-or-function (cdr list)))
135 (when (member target riece-current-channels)
136 (let ((objects (mixi-make-objects url-or-function
137 riece-mixi-check-range)))
139 (let ((object (car objects)))
140 (when (mixi-parent-p object)
141 (let ((comments (mixi-get-comments
142 object riece-mixi-check-range)))
144 (let ((time (mixi-object-time (car comments))))
145 (when (mixi-time-less-p riece-mixi-last-check
147 (riece-mixi-send-object-with-url
148 target (car comments))))
149 (setq comments (cdr comments)))))
150 (let ((time (mixi-object-time object)))
151 (when (mixi-time-less-p riece-mixi-last-check time)
152 (riece-mixi-send-object-with-url target object))))
153 (setq objects (cdr objects)))))))
154 riece-mixi-check-alist)
155 (setq riece-mixi-last-check (current-time))))
157 (defun riece-mixi-insinuate ()
158 (add-hook 'riece-after-display-message-functions
159 'riece-mixi-display-message-function))
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