* riece-300.el (riece-353-string): Renamed from riece-353-users.
[riece] / lisp / riece-keepalive.el
1 ;;; riece-keepalive.el --- keep an IRC connection
2 ;; Copyright (C) 1998-2004 Daiki Ueno
3
4 ;; Author: Daiki Ueno <ueno@unixuser.org>
5 ;; Created: 1998-09-28
6 ;; Keywords: IRC, riece
7
8 ;; This file is part of Riece.
9
10 ;; This program is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Commentary:
26
27 ;; To use, add the following line to your ~/.riece/init.el:
28 ;; (add-to-list 'riece-addons 'riece-keepalive)
29
30 ;;; Code:
31
32 (defvar riece-keepalive-ping-repeat 120)
33 (defvar riece-keepalive-timer nil)
34
35 (defun riece-keepalive-after-login-hook ()
36   (make-local-variable 'riece-keepalive-timer)
37   (unless riece-keepalive-timer
38     (setq riece-keepalive-timer
39           (riece-run-at-time
40            riece-keepalive-ping-repeat riece-keepalive-ping-repeat
41            (lambda (buffer)
42              (save-excursion
43                (set-buffer buffer)
44                (riece-send-string "PING riece-keepalive\r\n")))
45            (current-buffer)))))
46
47 (defun riece-keepalive-after-close-hook ()
48   (when riece-keepalive-timer
49     (riece-cancel-timer riece-keepalive-timer)
50     (setq riece-keepalive-timer nil)))
51
52 (defun riece-keepalive-insinuate ()
53   (add-hook 'riece-after-login-hook #'riece-keepalive-after-login-hook)
54   (add-hook 'riece-after-close-hook #'riece-keepalive-after-close-hook))
55
56 (provide 'riece-keepalive)
57
58 ;;; riece-ignore.el ends here