;;; doc-bot.el --- The M-x doctor bot on irc ;; Copyright (C) 1998, 2001 Stéphane Levant ;; Author: Stéphane Levant ;; Created: 1998 ;; Keywords: games ;; Version: 1.1 ;; URL: http://arsunik.free.fr/emacs ;; This file 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 file 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 GNU Emacs; see the file COPYING. If not, write to ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, ;; Boston, MA 02111-1307, USA. ;;; Commentary: ;; The M-x doctor bot on irc ! ;; You can change user options: ;; `doc-server' `doc-port' `doc-nick' `doc-chan' ;; The default is a bot "doc-RANDOM" which will connect on irc.webbernet.net ;; on port 6667 and join #doc ;; Add this line to the .emacs: ;; (autoload 'doc "doc-bot.el" "" t) ;; then tape M-x `doc' ;;; Code: (defvar doc-serveur "The irc server" "irc.webbernet.net") (defvar doc-port "The irc port" 6667) (defvar doc-nick "The nick for the bot. If the nick is taken, the bot will never come :)" (concat "doc-" (int-to-string (random 9999)))) (defvar doc-chan "A list of chan to join" '("#doc")) (defvar doc-name "¤") (defvar doc-domain "toto") (defvar doc-host "toto") (defvar doc-proc nil) (defun doc () (interactive) (save-excursion (switch-to-buffer "*doc*") (doctor) (setq doc-proc (open-network-stream "bot" (current-buffer) doc-serveur doc-port)) (process-kill-without-query doc-proc) (set-process-filter doc-proc 'doc-filter) (doc-send (format "USER %s %s %s %s" doc-nick doc-domain doc-host doc-name)) (doc-send (concat "NICK " doc-nick)) (let ((l doc-chan)) (while l (doc-send (concat "JOIN " (car l))) (setq l (cdr l)))))) (defun doc-kill() (interactive) (delete-process doc-proc)) (defun doc-send (string) (process-send-string doc-proc (concat string "\n"))) (defun doc-filter (proc string) (set-buffer (get-buffer "*doc*")) (insert string) (set-buffer (get-buffer "*doctor*")) (cond ((string-match "^PING" string) (doc-send (format "PONG :%s" doc-serveur))) ((string-match "^:\\([^!]+\\)![^@]+@[^ ]+ PRIVMSG \\([^ ]+\\) :\\([^ ]*\\)" string) (let ((nick (match-string 1 string)) (arg (match-string 2 string)) (msg (match-string 3 string))) (if (string= nick doc-nick) nil (insert msg) (insert "\n") (let (s (pt (+ 1 (point)))) (doctor-read-print) (goto-char pt) (while (not (eobp)) (end-of-line) (setq s (buffer-substring pt (point))) (if (string= s "") nil (doc-send (format "PRIVMSG %s :%s" (if (string-match "^#" arg) arg nick) s))) (forward-char) (setq pt (point))))))))) ;;; doc-bot.el ends here