1 ;;; riece-user.el --- a user object
2 ;; Copyright (C) 1998-2003 Daiki Ueno
4 ;; Author: Daiki Ueno <ueno@unixuser.org>
5 ;; Keywords: IRC, riece
7 ;; This file is 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., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
26 (eval-when-compile (require 'riece-inlines)) ;string-assoc-ignore-case, etc.
28 (require 'riece-identity)
30 (defconst riece-user-regexp
31 "[][\\\\`_^{|}A-Za-z][][\\\\`_^{|}A-Za-z0-9-]\\{0,8\\}")
34 (defun riece-find-user (name)
35 "Get a user object named NAME from the server buffer."
36 (riece-with-server-buffer
37 (let ((symbol (intern-soft (downcase (riece-identity-prefix name))
40 (symbol-value symbol)))))
42 (defun riece-forget-user (name)
43 (riece-with-server-buffer
44 (let ((symbol (intern-soft (downcase (riece-identity-prefix name)))))
47 (unintern (symbol-name symbol) riece-obarray)))))
49 (defun riece-rename-user (old-name new-name)
50 (riece-with-server-buffer
51 (let ((symbol (intern-soft (downcase (riece-identity-prefix old-name))
54 (set (intern (downcase (riece-identity-prefix new-name))
56 (symbol-value symbol))
58 (unintern (symbol-name symbol) riece-obarray)))))
60 (defun riece-make-user (&optional channels user-at-host modes away)
61 "Make an instance of user object.
62 Arguments are appropriate to joined channels, user-at-host, mode, and
63 away status, respectively."
64 (vector channels user-at-host modes away))
66 (defun riece-get-user (name)
67 (riece-with-server-buffer
68 (let ((symbol (intern-soft (downcase (riece-identity-prefix name))
72 (set (intern (downcase (riece-identity-prefix name)) riece-obarray)
73 (riece-make-user))))))
75 (defun riece-user-channels (user)
76 "Return joined channels of USER."
79 (defun riece-user-user-at-host (user)
80 "Return the user-at-host of USER."
83 (defun riece-user-modes (user)
84 "Return the modes of USER."
87 (defun riece-user-away (user)
88 "Return t, if USER has been marked as away."
91 (defun riece-user-set-channels (user value)
92 "Set the joined channels of USER to VALUE."
95 (defun riece-user-set-user-at-host (user value)
96 "Set the user-at-host of USER to VALUE."
99 (defun riece-user-set-modes (user value)
100 "Set the modes of USER to VALUE."
103 (defun riece-user-set-away (user value)
104 "Set the away status of USER to VALUE."
107 (defun riece-user-get-channels (&optional name)
109 (riece-get-user (or name riece-real-nickname))))
111 (defun riece-user-get-user-at-host (&optional name)
112 (riece-user-user-at-host
113 (riece-get-user (or name riece-real-nickname))))
115 (defun riece-user-get-modes (&optional name)
117 (riece-get-user (or name riece-real-nickname))))
119 (defun riece-user-get-away (&optional name)
121 (riece-get-user (or name riece-real-nickname))))
123 (defun riece-user-toggle-channel (name channel flag)
124 "Add or remove the joined channel of user."
125 (let* ((user (riece-get-user (or name (riece-current-nickname))))
126 (channels (riece-user-channels user)))
128 (unless (member channel channels)
129 (riece-user-set-channels user (cons channel channels)))
130 (if (setq channel (car (member channel channels)))
131 (riece-user-set-channels user (delq channel channels))))))
133 (defun riece-user-toggle-mode (name mode flag)
134 "Add or remove user MODE of user."
135 (let* ((user (riece-get-user (or name (riece-current-nickname))))
136 (modes (riece-user-modes user)))
138 (unless (memq mode modes)
139 (riece-user-set-modes user (cons mode modes)))
140 (if (memq mode modes)
141 (riece-user-set-modes user (delq mode modes))))))
143 (provide 'riece-user)
145 ;;; riece-user.el ends here