;;; zenirc-iwantop.el --- IWANTOP ctcp for granting channel operator bits

;; Copyright (C) 1995 Eric Prestemon
;; Copyright (C) 1998 Noah Friedman

;; Author: Eric Prestemon <ecp@io.com>
;;         Noah Friedman <friedman@splode.com>
;; Maintainer: friedman@splode.com
;; Keywords: zenirc, extensions
;; Created: 1995-03-31

;; $Id: zenirc-iwantop.el,v 1.5 1998/09/04 03:08:10 friedman Exp $

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program; if not, you can either send email to this
;; program's maintainer or write to: The Free Software Foundation,
;; Inc.; 675 Massachusetts Avenue; Cambridge, MA 02139, USA.

;;; Commentary:
;;; Code:

(defvar zenirc-iwantop-alist nil
  "*Association list of channel names and users allowed to be channel-opped.
That is, when someone sends you an IWANTOP ctcp, they are checked against
this alist to see if your client should automatically op them.

Each channel name and user is treated as a regular expression.
More than one user can be listed for each channel.

Here is an example:

    (setq zenirc-iwantop-alist
          ((\"#twilight_zone\" \"pjg@.*.buffalo.edu\"
                             \"trillian!.*kei.com\")
           (\"#bondage\"       \".*\")))

This will allow anyone to be opped, anywhere:

    (setq zenirc-iwantop-alist '((\".*\" \".*\")))")

(defvar zenirc-ctcp-query-IWANTOP-hook '(zenirc-ctcp-query-IWANTOP))

(defun zenirc-ctcp-query-IWANTOP (proc parsedctcp from to)
  (zenirc-ctcp-acl-query proc parsedctcp from to
                         zenirc-iwantop-alist
                         'zenirc-iwantop-do-op
                         'zenirc-iwantop-reject))


(defun zenirc-iwantop-do-op (proc parsedctcp from to)
  (process-send-string proc
                       (format "MODE %s +o %s\n"
                               (zenirc-ctcp-acl-get-channel parsedctcp)
                               (zenirc-extract-nick from))))

(defun zenirc-iwantop-reject (proc parsedctcp from to)
  (process-send-string proc (format "NOTICE %s :Oink!\n"
                                    (zenirc-extract-nick from))))

(provide 'zenirc-iwantop)

;;; zenirc-iwantop.el ends here
