1 ;;; zenirc-doto.el --- do things to who, list, links replies
3 ;; Copyright (C) 1993, 1994 Ben A. Mesander
4 ;; Copyright (C) 1998 Per Persson
6 ;; Author: Ben A. Mesander <ben@gnu.ai.mit.edu>
7 ;; Maintainer: pp@sno.pp.se
8 ;; Keywords: extensions
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)
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.
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.
31 (require 'zenirc-command-queue)
33 (defun zenirc-doto-install-message-catalogs ()
34 (zenirc-lang-define-catalog 'english
35 '((doto-lame-args . "[info] %s: lame argument(s)."))))
39 ;; example: send everyone on IRC a DCC chat request from the
40 ;; telnet port of a pentagon computer.
41 ;; /dotowho 0 (process-send-string proc (concat "PRIVMSG " (aref whoreply 7)
42 ;; " :\C-aDCC CHAT chat 2261613455 23\C-a\n"))
44 ;; 315 (end of who) handler
45 (defun zenirc-do-to-who-end (proc parsedmsg)
46 (zenirc-delete-hook 'zenirc-server-352-hook 'zenirc-do-to-who)
47 (zenirc-delete-hook 'zenirc-server-315-hook 'zenirc-do-to-who-end)
48 (setq zenirc-run-next-hook nil))
50 ;; 352 (who reply) handler
51 ;; proc is the zenirc process.
52 ;; whoreply is the parsed server message array.
53 (defun zenirc-do-to-who (proc whoreply)
54 (zenirc-do-to-who-function proc whoreply)
55 (setq zenirc-run-next-hook nil))
58 ;; /dotowho #victims (lisp-form)
59 ;; lisp-form can use "proc", which will be set to the zenirc process
60 ;; and "whoreply" which will be a parsed servermessage array containing
62 (defvar zenirc-command-dotowho-hook '(zenirc-command-dotowho))
64 (defun zenirc-command-dotowho (proc parsedcmd)
65 (let* ((arg (zenirc-parse-firstword (cdr parsedcmd)))
68 (if (or (string= "" victim)
70 (zenirc-message proc 'doto-lame-args "/dotowho"))
71 (zenirc-dotowho victim (read command))))
73 ;; programmatic interface
74 (defun zenirc-dotowho (victim command)
75 (fset 'zenirc-do-to-who-function (list 'lambda '(proc whoreply) command))
76 (zenirc-add-hook 'zenirc-server-315-hook 'zenirc-do-to-who-end)
77 (zenirc-add-hook 'zenirc-server-352-hook 'zenirc-do-to-who)
78 (process-send-string proc (concat "WHO " victim "\n")))
81 ;; example of using who
82 ;; /op channel - op everyone on a channel
83 (defvar zenirc-op-list nil)
85 (defvar zenirc-command-op-hook '(zenirc-command-op))
87 (defun zenirc-command-op (proc parsedcmd)
88 (let ((victim (cdr parsedcmd)))
89 (if (string= victim "")
90 (zenirc-message proc 'doto-lame-args "/op")
91 (setq zenirc-op-list nil)
94 '(if (not (string-match "@" (aref whoreply 8)))
95 (setq zenirc-op-list (cons (aref whoreply 7) zenirc-op-list))))
96 (zenirc-add-hook 'zenirc-server-315-hook 'zenirc-doto-op-end))))
98 (defun zenirc-doto-op-end (proc parsedmsg)
99 (let* ((channel (aref parsedmsg 3))
100 (oplen (length zenirc-op-list))
101 (triples (* 3 (/ oplen 3)))
102 (remainder (% oplen 3))
106 (setq nicks (concat (nth i zenirc-op-list) " "
107 (nth (1+ i) zenirc-op-list) " "
108 (nth (+ 2 i) zenirc-op-list) "\n"))
109 (process-send-string proc (concat "mode " channel " +ooo " nicks))
113 (setq nicks (concat (nth (- oplen 2) zenirc-op-list) " "
114 (nth (1- oplen) zenirc-op-list) "\n"))
115 (process-send-string proc (concat "mode " channel " +oo " nicks)))
118 proc (concat "mode " channel " +o "
119 (nth (1- oplen) zenirc-op-list) "\n"))))
120 (zenirc-delete-hook 'zenirc-server-315-hook 'zenirc-op-end)))
125 ;; 365 (end of links) handler
126 (defun zenirc-do-to-links-end (proc parsedmsg)
127 (zenirc-delete-hook 'zenirc-server-364-hook 'zenirc-do-to-links)
128 (zenirc-delete-hook 'zenirc-server-365-hook 'zenirc-do-to-links-end)
129 (setq zenirc-run-next-hook nil))
131 ;; 364 (links reply) handler
132 ;; proc is the zenirc process.
133 ;; linksreply is the parsed server message array.
134 (defun zenirc-do-to-links (proc linksreply)
135 (zenirc-do-to-links-function proc linksreply)
136 (setq zenirc-run-next-hook nil))
139 ;; /dotolinks (lisp-form)
140 ;; lisp-form can use "proc", which will be set to the zenirc process
141 ;; and "linksreply" which will be a parsed servermessage array containing
143 (defvar zenirc-command-dotolinks-hook '(zenirc-command-dotolinks))
145 (defun zenirc-command-dotolinks (proc parsedcmd)
146 (let ((arg (cdr parsedcmd)))
148 (zenirc-message proc 'doto-lame-args "/dotolinks")
149 (zenirc-dotolinks (read arg)))))
151 ;; programmatic interface
152 (defun zenirc-dotolinks (command)
153 (fset 'zenirc-do-to-links-function (list 'lambda '(proc linksreply) command))
154 (zenirc-add-hook 'zenirc-server-365-hook 'zenirc-do-to-links-end)
155 (zenirc-add-hook 'zenirc-server-364-hook 'zenirc-do-to-links)
156 (process-send-string proc "LINKS\n"))
158 (defvar zenirc-command-serverversions-hook '(zenirc-server-versions))
159 (defun zenirc-server-versions (proc parsedcmd)
160 (zenirc-dotolinks '(zenirc-queue-command (concat "VERSION "
165 ;; Do things to /list reply
169 ;; Example: set the topic of every channel on irc to be AT&T YOU WILL
170 ;; while talking on #twilight_zone
171 ;; /dotolist (if (not (string= (aref listreply 3) "*")) (progn
172 ;; (zenirc-queue-command (concat "JOIN " (aref listreply 3) "\n"))
173 ;; (zenirc-queue-command '(setq zenirc-current-victim "#twilight_zone"))
174 ;; (zenirc-queue-command (concat "TOPIC " (aref listreply 3)
175 ;; " :AT&T YOU WILL!!!!\n")) (zenirc-queue-command (concat "PART "
176 ;; (aref listreply 3) "\n"))))
178 ;; 323 (end of list) handler
179 (defun zenirc-do-to-list-end (proc parsedmsg)
180 (zenirc-delete-hook 'zenirc-server-322-hook 'zenirc-do-to-list)
181 (zenirc-delete-hook 'zenirc-server-323-hook 'zenirc-do-to-list-end)
182 (setq zenirc-run-next-hook nil))
184 ;; 322 (list reply) handler
185 ;; proc is the zenirc process.
186 ;; listreply is the parsed server message array.
187 (defun zenirc-do-to-list (proc listreply)
188 (zenirc-do-to-list-function proc listreply)
189 (setq zenirc-run-next-hook nil))
191 ;; 321 (list start) handler
192 (defun zenirc-do-to-list-start (proc parsedmsg)
193 (zenirc-delete-hook 'zenirc-server-321-hook 'zenirc-do-to-list-start)
194 (setq zenirc-run-next-hook nil))
197 ;; /dotolist (lisp-form)
198 ;; lisp-form can use "proc", which will be set to the zenirc process
199 ;; and "listreply" which will be a parsed servermessage array containing
201 (defvar zenirc-command-dotolist-hook '(zenirc-command-dotolist))
203 (defun zenirc-command-dotolist (proc parsedcmd)
204 (let* ((arg (cdr parsedcmd)))
206 (zenirc-message proc 'doto-lame-args "/dotolist"))
207 (zenirc-dotolist (read arg))))
209 ;; programmatic interface
210 (defun zenirc-dotolist (command)
211 (fset 'zenirc-do-to-list-function (list 'lambda '(proc listreply) command))
212 (zenirc-add-hook 'zenirc-server-323-hook 'zenirc-do-to-list-end)
213 (zenirc-add-hook 'zenirc-server-322-hook 'zenirc-do-to-list)
214 (zenirc-add-hook 'zenirc-server-321-hook 'zenirc-do-to-list-start)
215 (process-send-string proc "LIST\n"))
217 (provide 'zenirc-doto)
219 (zenirc-doto-install-message-catalogs)
221 ;;; End of zenirc-doto.el