Initial Commit
[packages] / xemacs-packages / zenirc / src / zenirc-away.el
1 ;;; zenirc-away.el --- fancy away processing for ZenIRC
2
3 ;;; Copyright (C) 1994 Noah S. Friedman
4 ;;; Copyright (C) 1998 Per Persson
5
6 ;;; Author: Noah Friedman <friedman@prep.ai.mit.edu>
7 ;;; Maintainer: pp@sno.pp.se
8 ;;; Keywords: zenirc, extensions, oink
9 ;;; Created: 1994-06-26
10
11 ;;; This program is free software; you can redistribute it and/or modify
12 ;;; it under the terms of the GNU General Public License as published by
13 ;;; the Free Software Foundation; either version 2, or (at your option)
14 ;;; any later version.
15 ;;;
16 ;;; This program is distributed in the hope that it will be useful,
17 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;;; GNU General Public License for more details.
20 ;;;
21 ;;; You should have received a copy of the GNU General Public License
22 ;;; along with this program; if not, you can either send email to this
23 ;;; program's maintainer or write to: The Free Software Foundation,
24 ;;; Inc.; 675 Massachusetts Avenue; Cambridge, MA 02139, USA.
25
26 ;;; Commentary:
27
28 ;;; This package reduces the number of times you see a user's /away message.
29 ;;; The first time you see that user's /away, the usual thing happens.
30 ;;; Subsequent /away messages are suppressed until the user changes it.
31
32 ;;; Code:
33
34 (require 'zenirc)
35
36 ;; 101 buckets should be a reasonable size for most people (remember to use
37 ;; a prime number to get good hashing characteristics).
38 ;; This is not the total number of nicks you can cache, but just the number
39 ;; of "buckets" in which nicks can be stored.  If you talk to thousands
40 ;; and thousands of people it might help to increase the size of this
41 ;; table, but even then it isn't necessary.
42 (defvar zenirc-away-table (make-vector 101 0)
43   "Association list of nicknames and their /away messages.
44 zenirc-server-301-fancy suppresses the display of /away messages if
45 you've already seen them.")
46
47 (defun zenirc-server-301-fancy (proc parsedmsg)
48   "Display /away message if you haven't seen it already."
49   (let* ((from (zenirc-extract-nick (aref parsedmsg 3)))
50          (text (aref parsedmsg 4))
51          (nicksym (intern (zenirc-downcase-name from) zenirc-away-table))
52          (cached (and (boundp nicksym) (symbol-value nicksym))))
53     (cond ((and cached (string= text cached)))
54           (t
55            (set nicksym text)
56            (zenirc-message proc 's301 from text)))))
57
58 (defun zenirc-server-301-signal-p (proc parsedmsg)
59   "Allow signals on /away message if you haven't seen it already."
60   (if (string= (aref parsedmsg 0) "301")
61       (let* ((from (zenirc-extract-nick (aref parsedmsg 3)))
62              (text (aref parsedmsg 4))
63              (nicksym (intern (zenirc-downcase-name from) zenirc-away-table))
64              (cached (and (boundp nicksym) (symbol-value nicksym))))
65         (if (and cached (string= text cached))
66             (setq zenirc-run-next-hook nil)))))
67
68 (provide 'zenirc-away)
69
70 (zenirc-remove-hook 'zenirc-server-301-hook 'zenirc-server-301)
71 (zenirc-add-hook 'zenirc-server-301-hook 'zenirc-server-301-fancy)
72 (zenirc-add-hook 'zenirc-signal-hook 'zenirc-server-301-signal-p)
73
74 ;;; zenirc-away.el ends here