3 ;;; zenirc-random-nick.el --- Choose random nicks for ZenIRC
5 ;;; Copyright (C) 1994 Ben A. Mesander
6 ;;; Copyright (C) 1994, 1996, 1997 Per Persson
8 ;;; Author: Ben A. Mesander <ben@gnu.ai.mit.edu>
9 ;;; Per Persson <pp@sno.pp.se>
10 ;;; Maintainer: pp@sno.pp.se
11 ;;; Keywords: extensions
12 ;;; Created: Sun Aug 14 20:20:05 MDT 1994
14 ;;; This program is free software; you can redistribute it and/or modify
15 ;;; it under the terms of the GNU General Public License as published by
16 ;;; the Free Software Foundation; either version 2, or (at your option)
17 ;;; any later version.
19 ;;; This program is distributed in the hope that it will be useful,
20 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;;; GNU General Public License for more details.
24 ;;; You should have received a copy of the GNU General Public License
25 ;;; along with this program; if not, you can either send email to this
26 ;;; program's maintainer or write to: The Free Software Foundation,
27 ;;; Inc.; 675 Massachusetts Avenue; Cambridge, MA 02139, USA.
31 ;;; This is really annoying.
39 ;; note- the rfc lies about valid characters in nicks.
40 ;; it appears the allowed character set is:
41 ;; [0-9][A-^][a-|] and - and _
42 ;; 0-9 and - cannot start a nick
44 (defun zenirc-random-nick-char ()
45 (let ((c (abs (random 69)))) ; mmm, 69
47 ((< c 10) (char-to-string (+ c 47))) ; 0-9
48 ((< c 40) (char-to-string (+ c 55))) ; A-^
49 (t (char-to-string (+ c 57)))))) ; a-|
51 (defun zenirc-random-nick-string (numchars)
52 (let ((i 1) (str (zenirc-random-nick-char)))
55 (while (and (< (string-to-char str) 58) ; can't start with
56 (> (string-to-char str) 47)) ; [0-9]
57 (setq str (zenirc-random-nick-char)))
59 (setq str (concat str (zenirc-random-nick-char)))
63 (defun zenirc-random-nick ()
64 (setq zenirc-nick (zenirc-random-nick-string 9)))
66 ;;; Code to automatically change nickname every now and then, this is
67 ;;; _really_ annoying. mmm, annoying code.
69 ;;; <poxaV> yes, i agree, it's annoying.
71 (defvar zenirc-change-nick-interval '(0 600)
72 "How often to change your random nickname. The default is 600
73 seconds or 10 minutes.")
74 (make-variable-buffer-local 'zenirc-change-nick-interval)
76 (defvar zenirc-last-nick-change '(0 0)
77 "The time the last change was made in a ZenIRC buffer.")
78 (make-variable-buffer-local 'zenirc-last-nick-change)
80 ;; Should this really be optional? B-)
81 (defvar zenirc-change-nick-mode nil
82 "If zenirc-random-nick should change nickname automatically.")
83 (make-variable-buffer-local 'zenirc-change-nick-mode)
85 (defun zenirc-change-random-nick (proc now)
86 "Change nickname in the specified process PROC every
87 zenirc-change-nick-interval seconds."
88 (if zenirc-change-nick-mode
89 (if (zenirc-time< zenirc-change-nick-interval
90 (zenirc-time-diff now zenirc-last-nick-change))
92 (process-send-string proc (concat
94 (zenirc-random-nick-string 9)
96 (setq zenirc-last-nick-change now)))))
98 (zenirc-add-hook 'zenirc-timer-hook 'zenirc-change-random-nick)
99 (zenirc-add-hook 'zenirc-mode-hook 'zenirc-random-nick)
101 (provide 'zenirc-random-nick)
103 ;;; End of zenirc-random-nick.el