* riece-debug.el: Don't bind unused variable; prepend time to
[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 (require 'riece-options)
33
34 (defgroup riece-keepalive nil
35   "Keep an IRC connection."
36   :prefix "riece-"
37   :group 'riece)
38
39 (defcustom riece-keepalive-ping-repeat 120
40   "Interval for sending PING to server."
41   :type 'integer
42   :group 'riece-keepalive)
43
44 (defvar riece-keepalive-timer nil)
45
46 (defconst riece-keepalive-description
47   "Keep an IRC connection.")
48
49 (defun riece-keepalive-after-login-hook ()
50   (make-local-variable 'riece-keepalive-timer)
51   (unless riece-keepalive-timer
52     (setq riece-keepalive-timer
53           (riece-run-at-time
54            riece-keepalive-ping-repeat riece-keepalive-ping-repeat
55            (lambda (buffer)
56              (save-excursion
57                (set-buffer buffer)
58                (riece-send-string "PING riece-keepalive\r\n")))
59            (current-buffer)))))
60
61 (defun riece-keepalive-after-close-hook ()
62   (when riece-keepalive-timer
63     (riece-cancel-timer riece-keepalive-timer)
64     (setq riece-keepalive-timer nil)))
65
66 (defun riece-keepalive-insinuate ()
67   (add-hook 'riece-after-login-hook #'riece-keepalive-after-login-hook)
68   (add-hook 'riece-after-close-hook #'riece-keepalive-after-close-hook))
69
70 (provide 'riece-keepalive)
71
72 ;;; riece-ignore.el ends here